forked from loafle/openapi-generator-original
[Java/Core] Adds properties to ComposedSchema models when they exist (#4482)
* Adds comment in java test where we need to check the fruit model * Adds oneOf test to DefaultCodegenTest.java, adds code to include properties in composed schema
This commit is contained in:
parent
e774db05b6
commit
c882338ef1
@ -1788,6 +1788,17 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
Map<String, Schema> allProperties = new LinkedHashMap<String, Schema>();
|
||||
List<String> allRequired = new ArrayList<String>();
|
||||
|
||||
// if schema has properties outside of allOf/oneOf/anyOf also add them to m
|
||||
if (schema.getProperties() != null) {
|
||||
addVars(m, unaliasPropertySchema(schema.getProperties()), schema.getRequired(), null, null);
|
||||
}
|
||||
|
||||
// uncomment this when https://github.com/swagger-api/swagger-parser/issues/1252 is resolved
|
||||
// if schema has additionalproperties outside of allOf/oneOf/anyOf also add it to m
|
||||
// if (schema.getAdditionalProperties() != null) {
|
||||
// addAdditionPropertiesToCodeGenModel(m, schema);
|
||||
// }
|
||||
|
||||
// parent model
|
||||
final String parentName = ModelUtils.getParentName(composed, allDefinitions);
|
||||
final List<String> allParents = ModelUtils.getAllParentsName(composed, allDefinitions);
|
||||
|
@ -268,6 +268,41 @@ public class DefaultCodegenTest {
|
||||
Assert.assertEquals(type, "oneOf<ObjA,ObjB>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComposedSchemaOneOfWithProperties() {
|
||||
final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/oneOf.yaml");
|
||||
final DefaultCodegen codegen = new DefaultCodegen();
|
||||
|
||||
final Schema schema = openAPI.getComponents().getSchemas().get("fruit");
|
||||
codegen.setOpenAPI(openAPI);
|
||||
CodegenModel fruit = codegen.fromModel("Fruit", schema);
|
||||
|
||||
Set<String> oneOf = new TreeSet<String>();
|
||||
oneOf.add("Apple");
|
||||
oneOf.add("Banana");
|
||||
Assert.assertEquals(fruit.oneOf, oneOf);
|
||||
Assert.assertEquals(fruit.optionalVars.size(), 3);
|
||||
Assert.assertEquals(fruit.vars.size(), 3);
|
||||
// make sure that fruit has the property color
|
||||
boolean colorSeen = false;
|
||||
for (CodegenProperty cp : fruit.vars) {
|
||||
if (cp.name.equals("color")) {
|
||||
colorSeen = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Assert.assertTrue(colorSeen);
|
||||
colorSeen = false;
|
||||
for (CodegenProperty cp : fruit.optionalVars) {
|
||||
if (cp.name.equals("color")) {
|
||||
colorSeen = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Assert.assertTrue(colorSeen);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEscapeText() {
|
||||
final DefaultCodegen codegen = new DefaultCodegen();
|
||||
|
@ -22,6 +22,9 @@ components:
|
||||
oneOf:
|
||||
- $ref: '#/components/schemas/apple'
|
||||
- $ref: '#/components/schemas/banana'
|
||||
# additionalProperties:
|
||||
# type: string
|
||||
# uncomment this when https://github.com/swagger-api/swagger-parser/issues/1252 is resolved
|
||||
apple:
|
||||
title: apple
|
||||
type: object
|
||||
|
Loading…
x
Reference in New Issue
Block a user