forked from oasdiff/oasdiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_request_discriminator_updated_test.go
172 lines (154 loc) · 6.7 KB
/
check_request_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
package checker_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/tufin/oasdiff/checker"
"github.com/tufin/oasdiff/diff"
"github.com/tufin/oasdiff/load"
"github.com/tufin/oasdiff/utils"
)
// CL: adding discriminator to the request body or request body property
func TestRequestDiscriminatorUpdatedCheckAdded(t *testing.T) {
s1, err := open("../data/checker/request_property_discriminator_added_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_property_discriminator_added_revision.yaml")
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestDiscriminatorUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 2)
require.ElementsMatch(t, []checker.ApiChange{
{
Id: checker.RequestBodyDiscriminatorAddedId,
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: load.NewSource("../data/checker/request_property_discriminator_added_revision.yaml"),
OperationId: "updatePets",
},
{
Id: checker.RequestPropertyDiscriminatorAddedId,
Args: []any{"/oneOf[#/components/schemas/Dog]/breed"},
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: load.NewSource("../data/checker/request_property_discriminator_added_revision.yaml"),
OperationId: "updatePets",
}}, errs)
}
// CL: removing discriminator from the request body or request body property
func TestRequestDiscriminatorUpdatedCheckRemoved(t *testing.T) {
s1, err := open("../data/checker/request_property_discriminator_added_revision.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_property_discriminator_added_base.yaml")
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestDiscriminatorUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 2)
require.ElementsMatch(t, []checker.ApiChange{
{
Id: checker.RequestBodyDiscriminatorRemovedId,
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: load.NewSource("../data/checker/request_property_discriminator_added_base.yaml"),
OperationId: "updatePets",
},
{
Id: checker.RequestPropertyDiscriminatorRemovedId,
Args: []any{"/oneOf[#/components/schemas/Dog]/breed"},
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: load.NewSource("../data/checker/request_property_discriminator_added_base.yaml"),
OperationId: "updatePets",
}}, errs)
}
// CL: changing discriminator propertyName in the request body or request body property
func TestRequestDiscriminatorUpdatedCheckPropertyNameChanging(t *testing.T) {
s1, err := open("../data/checker/request_property_discriminator_added_revision.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_property_discriminator_added_property_name_changed.yaml")
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestDiscriminatorUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 2)
require.ElementsMatch(t, []checker.ApiChange{
{
Id: checker.RequestBodyDiscriminatorPropertyNameChangedId,
Args: []any{"petType", "petType2"},
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: load.NewSource("../data/checker/request_property_discriminator_added_property_name_changed.yaml"),
OperationId: "updatePets",
},
{
Id: checker.RequestPropertyDiscriminatorPropertyNameChangedId,
Args: []any{"/oneOf[#/components/schemas/Dog]/breed", "name", "name2"},
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: load.NewSource("../data/checker/request_property_discriminator_added_property_name_changed.yaml"),
OperationId: "updatePets",
}}, errs)
}
// CL: changing discriminator mapping in the request body or request body property
func TestRequestDiscriminatorUpdatedCheckMappingChanging(t *testing.T) {
s1, err := open("../data/checker/request_property_discriminator_added_revision.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_property_discriminator_mapping_changed.yaml")
require.NoError(t, err)
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestDiscriminatorUpdatedCheck), d, osm, checker.INFO)
require.Len(t, errs, 5)
require.ElementsMatch(t, []checker.ApiChange{
{
Id: checker.RequestBodyDiscriminatorMappingAddedId,
Args: []any{utils.StringList{"cats"}},
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: load.NewSource("../data/checker/request_property_discriminator_mapping_changed.yaml"),
OperationId: "updatePets",
},
{
Id: checker.RequestBodyDiscriminatorMappingDeletedId,
Args: []any{utils.StringList{"cat"}},
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: load.NewSource("../data/checker/request_property_discriminator_mapping_changed.yaml"),
OperationId: "updatePets",
},
{
Id: checker.RequestPropertyDiscriminatorMappingAddedId,
Args: []any{utils.StringList{"breed1Code"}, "/oneOf[#/components/schemas/Dog]/breed"},
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: load.NewSource("../data/checker/request_property_discriminator_mapping_changed.yaml"),
OperationId: "updatePets",
},
{
Id: checker.RequestPropertyDiscriminatorMappingChangedId,
Args: []any{"breed2", "#/components/schemas/Breed2", "#/components/schemas/Breed3", "/oneOf[#/components/schemas/Dog]/breed"},
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: load.NewSource("../data/checker/request_property_discriminator_mapping_changed.yaml"),
OperationId: "updatePets",
},
{
Id: checker.RequestPropertyDiscriminatorMappingDeletedId,
Args: []any{utils.StringList{"breed1"}, "/oneOf[#/components/schemas/Dog]/breed"},
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Source: load.NewSource("../data/checker/request_property_discriminator_mapping_changed.yaml"),
OperationId: "updatePets",
}}, errs)
}