forked from Jonathan-Rosenberg/oasdiff
-
Notifications
You must be signed in to change notification settings - Fork 1
/
check-response-discriminator-updated_test.go
183 lines (165 loc) · 7.42 KB
/
check-response-discriminator-updated_test.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package checker_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/treeverse/oasdiff/checker"
"github.com/treeverse/oasdiff/diff"
)
// CL: adding discriminator to the response body or response property
func TestResponseDiscriminatorUpdatedCheckAdded(t *testing.T) {
s1, err := open("../data/checker/response_property_discriminator_added_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/response_property_discriminator_added_revision.yaml")
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseDiscriminatorUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 2)
require.ElementsMatch(t, []checker.ApiChange{
{
Id: "response-body-discriminator-added",
Text: "added response discriminator for the response status 200",
Comment: "",
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: "../data/checker/response_property_discriminator_added_revision.yaml",
OperationId: "updatePets",
},
{
Id: "response-property-discriminator-added",
Text: "added discriminator to '/oneOf[#/components/schemas/Dog]/breed' response property for the response status 200",
Comment: "",
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: "../data/checker/response_property_discriminator_added_revision.yaml",
OperationId: "updatePets",
}}, errs)
}
// CL: removing discriminator from the response body or response property
func TestResponseDiscriminatorUpdatedCheckRemoved(t *testing.T) {
s1, err := open("../data/checker/response_property_discriminator_added_revision.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/response_property_discriminator_added_base.yaml")
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseDiscriminatorUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 2)
require.ElementsMatch(t, []checker.ApiChange{
{
Id: "response-body-discriminator-removed",
Text: "removed response discriminator for the response status 200",
Comment: "",
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: "../data/checker/response_property_discriminator_added_base.yaml",
OperationId: "updatePets",
},
{
Id: "response-property-discriminator-removed",
Text: "removed discriminator from '/oneOf[#/components/schemas/Dog]/breed' response property for the response status 200",
Comment: "",
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: "../data/checker/response_property_discriminator_added_base.yaml",
OperationId: "updatePets",
}}, errs)
}
// CL: changing discriminator propertyName in the response body or response property
func TestResponseDiscriminatorUpdatedCheckPropertyNameChanging(t *testing.T) {
s1, err := open("../data/checker/response_property_discriminator_added_revision.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/response_property_discriminator_added_property_name_changed.yaml")
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseDiscriminatorUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 2)
require.ElementsMatch(t, []checker.ApiChange{
{
Id: "response-body-discriminator-property-name-changed",
Text: "response discriminator property name changed from 'petType' to 'petType2' for the response status 200",
Comment: "",
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: "../data/checker/response_property_discriminator_added_property_name_changed.yaml",
OperationId: "updatePets",
},
{
Id: "response-property-discriminator-property-name-changed",
Text: "response discriminator property name changed for '/oneOf[#/components/schemas/Dog]/breed' response property from 'name' to 'name2' for the response status 200",
Comment: "",
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: "../data/checker/response_property_discriminator_added_property_name_changed.yaml",
OperationId: "updatePets",
}}, errs)
}
// CL: changing discriminator mapping in the response body or response property
func TestResponseDiscriminatorUpdatedCheckMappingChanging(t *testing.T) {
s1, err := open("../data/checker/response_property_discriminator_added_revision.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/response_property_discriminator_mapping_changed.yaml")
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseDiscriminatorUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 5)
require.ElementsMatch(t, []checker.ApiChange{
{
Id: "response-body-discriminator-mapping-added",
Text: "added '[cats]' mapping keys to the response discriminator for the response status 200",
Comment: "",
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: "../data/checker/response_property_discriminator_mapping_changed.yaml",
OperationId: "updatePets",
},
{
Id: "response-body-discriminator-mapping-deleted",
Text: "removed '[cat]' mapping keys from the response discriminator for the response status 200",
Comment: "",
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: "../data/checker/response_property_discriminator_mapping_changed.yaml",
OperationId: "updatePets",
},
{
Id: "response-property-discriminator-mapping-added",
Text: "added '[breed1Code]' discriminator mapping keys to the '/oneOf[#/components/schemas/Dog]/breed' response property for the response status 200",
Comment: "",
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: "../data/checker/response_property_discriminator_mapping_changed.yaml",
OperationId: "updatePets",
},
{
Id: "response-property-discriminator-mapping-changed",
Text: "mapped value for discriminator key 'breed2' changed from '#/components/schemas/Breed2' to '#/components/schemas/Breed3' for '/oneOf[#/components/schemas/Dog]/breed' response property for the response status 200",
Comment: "",
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: "../data/checker/response_property_discriminator_mapping_changed.yaml",
OperationId: "updatePets",
},
{
Id: "response-property-discriminator-mapping-deleted",
Text: "removed '[breed1]' discriminator mapping keys from the '/oneOf[#/components/schemas/Dog]/breed' response property for the response status 200",
Comment: "",
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: "../data/checker/response_property_discriminator_mapping_changed.yaml",
OperationId: "updatePets",
}}, errs)
}