github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/cmd/swagger/commands/diff/compatibility.go (about) 1 package diff 2 3 // CompatibilityPolicy decides which changes are breaking and which are not 4 type CompatibilityPolicy struct { 5 ForResponse map[SpecChangeCode]Compatibility 6 ForRequest map[SpecChangeCode]Compatibility 7 ForChange map[SpecChangeCode]Compatibility 8 } 9 10 var compatibility CompatibilityPolicy 11 12 func init() { 13 compatibility = CompatibilityPolicy{ 14 ForResponse: map[SpecChangeCode]Compatibility{ 15 AddedRequiredProperty: Breaking, 16 DeletedProperty: Breaking, 17 AddedProperty: NonBreaking, 18 DeletedResponse: Breaking, 19 AddedResponse: NonBreaking, 20 WidenedType: NonBreaking, 21 NarrowedType: NonBreaking, 22 ChangedType: Breaking, 23 ChangedToCompatibleType: NonBreaking, 24 AddedEnumValue: Breaking, 25 DeletedEnumValue: NonBreaking, 26 AddedResponseHeader: NonBreaking, 27 ChangedResponseHeader: Breaking, 28 DeletedResponseHeader: Breaking, 29 ChangedDescripton: NonBreaking, 30 AddedDescripton: NonBreaking, 31 DeletedDescripton: NonBreaking, 32 ChangedTag: NonBreaking, 33 AddedTag: NonBreaking, 34 DeletedTag: NonBreaking, 35 DeletedConstraint: Breaking, 36 AddedConstraint: NonBreaking, 37 DeletedExtension: Warning, 38 AddedExtension: Warning, 39 ChangedExtensionValue: Warning, 40 }, 41 ForRequest: map[SpecChangeCode]Compatibility{ 42 AddedRequiredProperty: Breaking, 43 DeletedProperty: Breaking, 44 AddedProperty: NonBreaking, 45 AddedOptionalParam: NonBreaking, 46 AddedRequiredParam: Breaking, 47 DeletedOptionalParam: NonBreaking, 48 DeletedRequiredParam: NonBreaking, 49 WidenedType: NonBreaking, 50 NarrowedType: Breaking, 51 ChangedType: Breaking, 52 ChangedToCompatibleType: NonBreaking, 53 ChangedOptionalToRequired: Breaking, 54 ChangedRequiredToOptional: NonBreaking, 55 AddedEnumValue: NonBreaking, 56 DeletedEnumValue: Breaking, 57 ChangedDescripton: NonBreaking, 58 AddedDescripton: NonBreaking, 59 DeletedDescripton: NonBreaking, 60 ChangedTag: NonBreaking, 61 AddedTag: NonBreaking, 62 DeletedTag: NonBreaking, 63 DeletedConstraint: NonBreaking, 64 AddedConstraint: Breaking, 65 ChangedDefault: Warning, 66 AddedDefault: Warning, 67 DeletedDefault: Warning, 68 ChangedExample: NonBreaking, 69 AddedExample: NonBreaking, 70 DeletedExample: NonBreaking, 71 ChangedCollectionFormat: Breaking, 72 DeletedExtension: Warning, 73 AddedExtension: Warning, 74 ChangedExtensionValue: Warning, 75 }, 76 ForChange: map[SpecChangeCode]Compatibility{ 77 NoChangeDetected: NonBreaking, 78 AddedEndpoint: NonBreaking, 79 DeletedEndpoint: Breaking, 80 DeletedDeprecatedEndpoint: NonBreaking, 81 AddedConsumesFormat: NonBreaking, 82 DeletedConsumesFormat: Breaking, 83 AddedProducesFormat: NonBreaking, 84 DeletedProducesFormat: Breaking, 85 AddedSchemes: NonBreaking, 86 DeletedSchemes: Breaking, 87 ChangedHostURL: Breaking, 88 ChangedBasePath: Breaking, 89 ChangedDescripton: NonBreaking, 90 AddedDescripton: NonBreaking, 91 DeletedDescripton: NonBreaking, 92 ChangedTag: NonBreaking, 93 AddedTag: NonBreaking, 94 DeletedTag: NonBreaking, 95 RefTargetChanged: Breaking, 96 RefTargetRenamed: NonBreaking, 97 AddedDefinition: NonBreaking, 98 DeletedDefinition: NonBreaking, 99 DeletedExtension: Warning, 100 AddedExtension: Warning, 101 ChangedExtensionValue: Warning, 102 }, 103 } 104 } 105 106 func getCompatibilityForChange(diffCode SpecChangeCode, where DataDirection) Compatibility { 107 if compat, commonChange := compatibility.ForChange[diffCode]; commonChange { 108 return compat 109 } 110 if where == Request { 111 return compatibility.ForRequest[diffCode] 112 } 113 return compatibility.ForResponse[diffCode] 114 }