Skip to content

Commit

Permalink
fix inline schema without object type (OpenAPITools#5992)
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 authored and michaelpro1 committed May 7, 2020
1 parent a58a296 commit 3c36f62
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,11 @@ private void flattenResponses(OpenAPI openAPI, String pathname, Operation operat
* Flattens properties of inline object schemas that belong to a composed schema into a
* single flat list of properties. This is useful to generate a single or multiple
* inheritance model.
*
*
* In the example below, codegen may generate a 'Dog' class that extends from the
* generated 'Animal' class. 'Dog' has additional properties 'name', 'age' and 'breed' that
* are flattened as a single list of properties.
*
*
* Dog:
* allOf:
* - $ref: '#/components/schemas/Animal'
Expand All @@ -350,7 +350,7 @@ private void flattenResponses(OpenAPI openAPI, String pathname, Operation operat
* properties:
* breed:
* type: string
*
*
* @param openAPI the OpenAPI document
* @param key a unique name ofr the composed schema.
* @param children the list of nested schemas within a composed schema (allOf, anyOf, oneOf).
Expand All @@ -362,8 +362,10 @@ private void flattenComposedChildren(OpenAPI openAPI, String key, List<Schema> c
ListIterator<Schema> listIterator = children.listIterator();
while (listIterator.hasNext()) {
Schema component = listIterator.next();
if (component instanceof ObjectSchema) {
ObjectSchema op = (ObjectSchema) component;
if (component instanceof ObjectSchema || // for inline schema with type:object
(component != null && component.getProperties() != null &&
!component.getProperties().isEmpty())) { // for inline schema without type:object
Schema op = component;
if (op.get$ref() == null && op.getProperties() != null && op.getProperties().size() > 0) {
// If a `title` attribute is defined in the inline schema, codegen uses it to name the
// inline schema. Otherwise, we'll use the default naming such as InlineObject1, etc.
Expand All @@ -390,6 +392,8 @@ private void flattenComposedChildren(OpenAPI openAPI, String key, List<Schema> c
listIterator.set(schema);
}
}
} else {
// likely a reference to schema (not inline schema)
}
}
}
Expand Down Expand Up @@ -465,7 +469,7 @@ private void fixStringModel(Schema m) {
* with underscores
*
* e.g. io.schema.User_name => io_schema_User_name
*
*
* @param title String title field in the schema if present
* @param key String model name
*
Expand Down Expand Up @@ -607,7 +611,7 @@ private void flattenProperties(Map<String, Schema> properties, String path) {
}
}

private Schema modelFromProperty(ObjectSchema object, String path) {
private Schema modelFromProperty(Schema object, String path) {
String description = object.getDescription();
String example = null;
Object obj = object.getExample();
Expand Down

0 comments on commit 3c36f62

Please sign in to comment.