Skip to content

Commit aaa32d0

Browse files
committed
Test Cases for more than two oneOf-Options (both passing, but important to narrow down observed bug)
1 parent 27d3c6f commit aaa32d0

File tree

3 files changed

+106
-2
lines changed

3 files changed

+106
-2
lines changed

modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,9 +766,10 @@ public void testComposedSchemaOneOfWithProperties() {
766766
Set<String> oneOf = new TreeSet<>();
767767
oneOf.add("Apple");
768768
oneOf.add("Banana");
769+
oneOf.add("Orange");
769770
assertEquals(fruit.oneOf, oneOf);
770-
assertEquals(3, fruit.optionalVars.size());
771-
assertEquals(3, fruit.vars.size());
771+
assertEquals(4, fruit.optionalVars.size());
772+
assertEquals(4, fruit.vars.size());
772773
// make sure that fruit has the property color
773774
boolean colorSeen = false;
774775
for (CodegenProperty cp : fruit.vars) {
@@ -788,6 +789,32 @@ public void testComposedSchemaOneOfWithProperties() {
788789
assertTrue(colorSeen);
789790
}
790791

792+
@Test
793+
public void testComposedSchemaOneOfAllOf() {
794+
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/oneOf_inheritance.yaml");
795+
final DefaultCodegen codegen = new DefaultCodegen();
796+
797+
final Schema schema = openAPI.getComponents().getSchemas().get("RandomAnimalsResponse_animals_inner");
798+
codegen.setOpenAPI(openAPI);
799+
CodegenModel randomAnimalsResponseInner = codegen.fromModel("RandomAnimalsResponse_animals_inner", schema);
800+
801+
Set<String> oneOf = new TreeSet<>();
802+
oneOf.add("Mouse");
803+
oneOf.add("Cat");
804+
oneOf.add("Dog");
805+
assertEquals(oneOf, randomAnimalsResponseInner.oneOf);
806+
assertEquals(4, randomAnimalsResponseInner.vars.size());
807+
// make sure that RandomAnimalsResponseInner has the property species
808+
boolean speciesSeen = false;
809+
for (CodegenProperty cp : randomAnimalsResponseInner.vars) {
810+
if ("species".equals(cp.name)) {
811+
speciesSeen = true;
812+
break;
813+
}
814+
}
815+
assertTrue(speciesSeen);
816+
}
817+
791818
@Test
792819
public void testEscapeText() {
793820
final DefaultCodegen codegen = new DefaultCodegen();

modules/openapi-generator/src/test/resources/3_0/oneOf.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ components:
2222
oneOf:
2323
- $ref: '#/components/schemas/apple'
2424
- $ref: '#/components/schemas/banana'
25+
- $ref: '#/components/schemas/orange'
2526
# additionalProperties:
2627
# type: string
2728
# uncomment this when https://github.com/swagger-api/swagger-parser/issues/1252 is resolved
@@ -37,3 +38,9 @@ components:
3738
properties:
3839
count:
3940
type: number
41+
orange:
42+
title: orange
43+
type: object
44+
properties:
45+
sweet:
46+
type: boolean
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
openapi: 3.0.3
3+
info:
4+
title: randimals
5+
version: "1.0"
6+
paths:
7+
/random-animals:
8+
get:
9+
tags:
10+
- Random Animals Resource
11+
responses:
12+
"200":
13+
description: OK
14+
content:
15+
'*/*':
16+
schema:
17+
$ref: '#/components/schemas/RandomAnimalsResponse'
18+
components:
19+
schemas:
20+
RandomAnimalsResponse:
21+
type: object
22+
properties:
23+
animals:
24+
type: array
25+
items:
26+
oneOf:
27+
- $ref: '#/components/schemas/Dog'
28+
- $ref: '#/components/schemas/Cat'
29+
- $ref: '#/components/schemas/Mouse'
30+
required:
31+
- animals
32+
Dog:
33+
allOf:
34+
- $ref: '#/components/schemas/Animal'
35+
- type: object
36+
properties:
37+
dogId:
38+
type: string
39+
required:
40+
- dogId
41+
Animal:
42+
discriminator:
43+
propertyName: species
44+
mapping:
45+
Dog: '#/components/schemas/Dog'
46+
Cat: '#/components/schemas/Cat'
47+
Mouse: '#/components/schemas/Mouse'
48+
properties:
49+
species:
50+
type: string
51+
required:
52+
- species
53+
Cat:
54+
allOf:
55+
- $ref: '#/components/schemas/Animal'
56+
- type: object
57+
properties:
58+
catId:
59+
type: string
60+
required:
61+
- catId
62+
Mouse:
63+
allOf:
64+
- $ref: '#/components/schemas/Mouse'
65+
- type: object
66+
properties:
67+
mouseId:
68+
type: string
69+
required:
70+
- mouseId

0 commit comments

Comments
 (0)