Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for parents, allParents #5984

Merged
merged 3 commits into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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