Skip to content

Commit

Permalink
Add tests for parents, allParents (#5984)
Browse files Browse the repository at this point in the history
* add test for regression with a single ref in allof

* fix tests

* add a test for allParents
  • Loading branch information
wing328 authored Apr 20, 2020
1 parent 1766279 commit c35f32b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -605,15 +605,34 @@ public void testAllOfRequired() {
}

@Test
public void testAllOfSingleRefWithOwnPropsNoDiscriminator() {
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/composed-allof.yaml");
public void testAllOfSingleAndDoubleRefWithOwnPropsNoDiscriminator() {
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/allOf_composition.yaml");
final DefaultCodegen codegen = new CodegenWithMultipleInheritance();

codegen.setOpenAPI(openAPI);

Schema supermanSchema = openAPI.getComponents().getSchemas().get("SuperMan");
CodegenModel supermanModel = codegen.fromModel("SuperMan", supermanSchema);
Assert.assertEquals(supermanModel.parent, null);
Assert.assertEquals(supermanModel.allParents, null);

Schema superboySchema = openAPI.getComponents().getSchemas().get("SuperBoy");
CodegenModel superboyModel = codegen.fromModel("SuperBoy", superboySchema);
Assert.assertEquals(superboyModel.parent, null);
Assert.assertEquals(superboyModel.allParents, null);
}

@Test
public void testAllParents() {
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/allOfMappingDuplicatedProperties.yaml");
final DefaultCodegen codegen = new CodegenWithMultipleInheritance();

Schema schema = openAPI.getComponents().getSchemas().get("MessageEventCoreWithTimeListEntries");
codegen.setOpenAPI(openAPI);
CodegenModel model = codegen.fromModel("MessageEventCoreWithTimeListEntries", schema);
Assert.assertEquals(model.parent, null);
Assert.assertEquals(model.allParents, null);

Schema adultSchema = openAPI.getComponents().getSchemas().get("Adult");
CodegenModel adultModel = codegen.fromModel("Adult", adultSchema);
Assert.assertEquals(adultModel.parent, "Person");
Assert.assertEquals(adultModel.allParents, Collections.singletonList("Person"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ paths:
$ref: "#/components/schemas/SuperMan"
components:
schemas:
SuperBoy: # to test single ref (Human) only
allOf:
- $ref: '#/components/schemas/Human'
- type: object
required:
- level
properties:
category:
type: string
level:
type: integer
SuperMan:
allOf:
- $ref: '#/components/schemas/Human'
Expand Down

0 comments on commit c35f32b

Please sign in to comment.