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