Skip to content

Commit 53adf9d

Browse files
committed
Added test definitions for discriminator use with allOf
1 parent abd1f30 commit 53adf9d

File tree

1 file changed

+197
-2
lines changed

1 file changed

+197
-2
lines changed

src/test/resources/openapi3/discriminator.json

Lines changed: 197 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"description": "discriminator with oneOf and explicitly mapped single alternative for Dog and an implicit mapping for Cat",
3+
"description": "discriminator with oneOf",
44
"schema": {
55
"oneOf": [
66
{
@@ -51,7 +51,9 @@
5151
},
5252
{
5353
"type": "object",
54-
"required": ["bark"],
54+
"required": [
55+
"bark"
56+
],
5557
"properties": {
5658
"bark": {
5759
"type": "string"
@@ -95,5 +97,198 @@
9597
"valid": false
9698
}
9799
]
100+
},
101+
{
102+
"description": "discriminator with allOf",
103+
"schema": {
104+
"$ref": "#/components/schemas/Room",
105+
"components": {
106+
"schemas": {
107+
"Room": {
108+
"type": "object",
109+
"properties": {
110+
"@type": {
111+
"type": "string",
112+
"pattern": "^(?!Room$)"
113+
},
114+
"floor": {
115+
"type": "int32"
116+
}
117+
},
118+
"required": [
119+
"@type"
120+
],
121+
"discriminator": {
122+
"propertyName": "@type",
123+
"mapping": {
124+
"bed": "#/components/schemas/BedRoom"
125+
}
126+
}
127+
},
128+
"BedRoom": {
129+
"type": "object",
130+
"allOf": "#/components/schemas/Room",
131+
"properties": {
132+
"numberOfBeds": {
133+
"type": "int32"
134+
}
135+
},
136+
"required": [
137+
"numberOfBeds"
138+
]
139+
},
140+
"KidsBedRoom": {
141+
"type": "object",
142+
"allOf": "#/components/schemas/BedRoom",
143+
"properties": {
144+
"isTidy": {
145+
"type": "boolean"
146+
}
147+
},
148+
"required": [
149+
"isTidy"
150+
]
151+
},
152+
"Kitchen": {
153+
"type": "object",
154+
"allOf": "#/components/schemas/Room",
155+
"properties": {
156+
"hasMicrowaveOven": "boolean"
157+
},
158+
"required": [
159+
"hasMicrowaveOven"
160+
]
161+
}
162+
}
163+
}
164+
},
165+
"tests": [
166+
{
167+
"description": "Forbidden mapping to base type",
168+
"data": {
169+
"@type": "Room"
170+
},
171+
"valid": false
172+
},
173+
{
174+
"description": "mapped to Bedroom",
175+
"data": {
176+
"@type": "bed",
177+
"numberOfBeds": 2
178+
},
179+
"valid": true
180+
},
181+
{
182+
"description": "mapped to Kitchen",
183+
"data": {
184+
"@type": "bed",
185+
"hasMicrowaveOven": true
186+
},
187+
"valid": true
188+
},
189+
{
190+
"description": "mapped to KidsBedRoom",
191+
"data": {
192+
"@type": "KidsBedRoom",
193+
"numberOfBeds": 1,
194+
"isTidy": false
195+
},
196+
"valid": true
197+
},
198+
{
199+
"description": "mapped to Bedroom with missing number of beds",
200+
"data": {
201+
"@type": "bed"
202+
},
203+
"valid": false
204+
},
205+
{
206+
"description": "mapped to KidsBedroom with missing number of beds",
207+
"data": {
208+
"@type": "KidsBedRoom",
209+
"isTidy": true
210+
},
211+
"valid": false
212+
},
213+
{
214+
"description": "mapped to KidsBedroom with missing tidiness",
215+
"data": {
216+
"@type": "KidsBedRoom",
217+
"numberOfBeds": 1
218+
},
219+
"valid": false
220+
},
221+
{
222+
"description": "mapped to invalid Room",
223+
"data": {
224+
"@type": "Bathroom"
225+
},
226+
"valid": false
227+
}
228+
]
229+
},
230+
{
231+
"description": "Conflicting discriminators",
232+
"schema": {
233+
"$ref": "#/components/schemas/Room",
234+
"components": {
235+
"schemas": {
236+
"Room": {
237+
"type": "object",
238+
"properties": {
239+
"@type": {
240+
"type": "string"
241+
},
242+
"floor": {
243+
"type": "int32"
244+
}
245+
},
246+
"required": [
247+
"@type"
248+
],
249+
"discriminator": {
250+
"propertyName": "@type",
251+
"mapping": {
252+
"bed": "#/components/schemas/BedRoom"
253+
}
254+
}
255+
},
256+
"BedRoom": {
257+
"type": "object",
258+
"allOf": "#/components/schemas/Room",
259+
"properties": {
260+
"redefinedDiscriminatorProperty": {
261+
"type": "string"
262+
}
263+
},
264+
"required": [
265+
"redefinedDiscriminatorProperty"
266+
],
267+
"discriminator": {
268+
"propertyName": "redefinedDiscriminatorProperty"
269+
}
270+
},
271+
"KidsBedRoom": {
272+
"type": "object",
273+
"allOf": "#/components/schemas/BedRoom",
274+
"properties": {
275+
"isTidy": {
276+
"type": "boolean"
277+
}
278+
},
279+
"required": [
280+
"isTidy"
281+
]
282+
}
283+
}
284+
}
285+
},
286+
"tests": [
287+
{
288+
"description": "Schema invalid",
289+
"data": "{}",
290+
"valid": false
291+
}
292+
]
98293
}
99294
]

0 commit comments

Comments
 (0)