From fa69a7f4af5ff3de68310281f8ccfb653c8c8332 Mon Sep 17 00:00:00 2001 From: Jim Schubert <james.schubert@gmail.com> Date: Sat, 1 Aug 2020 19:05:12 -0400 Subject: [PATCH 1/5] [bug] Copy all validations on composed schemas when flattening models --- .../codegen/InlineModelResolver.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java index 9d632888f20..f9cb430e05f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java @@ -627,6 +627,30 @@ public class InlineModelResolver { model.setXml(xml); model.setRequired(object.getRequired()); model.setNullable(object.getNullable()); + model.setDiscriminator(object.getDiscriminator()); + model.setWriteOnly(object.getWriteOnly()); + model.setUniqueItems(object.getUniqueItems()); + model.setType(object.getType()); + model.setTitle(object.getTitle()); + model.setReadOnly(object.getReadOnly()); + model.setPattern(object.getPattern()); + model.setNot(object.getNot()); + model.setMinProperties(object.getMinProperties()); + model.setMinLength(object.getMinLength()); + model.setMinItems(object.getMinItems()); + model.setMinimum(object.getMinimum()); + model.setMaxProperties(object.getMaxProperties()); + model.setMaxLength(object.getMaxLength()); + model.setMaxItems(object.getMaxItems()); + model.setMaximum(object.getMaximum()); + model.setFormat(object.getFormat()); + model.setExternalDocs(object.getExternalDocs()); + model.setExtensions(object.getExtensions()); + model.setExclusiveMinimum(object.getExclusiveMinimum()); + model.setExclusiveMaximum(object.getExclusiveMaximum()); + model.setExample(object.getExample()); + model.setDeprecated(object.getDeprecated()); + if (properties != null) { flattenProperties(openAPI, properties, path); model.setProperties(properties); -- GitLab From f7f578851d9853ae9503d5325825d240a25cfe13 Mon Sep 17 00:00:00 2001 From: Jim Schubert <james.schubert@gmail.com> Date: Sat, 1 Aug 2020 19:08:52 -0400 Subject: [PATCH 2/5] Regenerate samples --- .../go-experimental/go-petstore/api/openapi.yaml | 3 +++ .../petstore/go/go-petstore-withXml/api/openapi.yaml | 3 +++ samples/client/petstore/go/go-petstore/api/openapi.yaml | 3 +++ samples/client/petstore/haskell-http-client/openapi.yaml | 3 +++ samples/client/petstore/java/feign/api/openapi.yaml | 3 +++ .../petstore/java/google-api-client/api/openapi.yaml | 3 +++ samples/client/petstore/java/jersey1/api/openapi.yaml | 3 +++ .../client/petstore/java/jersey2-java8/api/openapi.yaml | 3 +++ .../client/petstore/java/native-async/api/openapi.yaml | 3 +++ samples/client/petstore/java/native/api/openapi.yaml | 3 +++ .../java/okhttp-gson-parcelableModel/api/openapi.yaml | 3 +++ .../client/petstore/java/okhttp-gson/api/openapi.yaml | 3 +++ .../petstore/java/rest-assured-jackson/api/openapi.yaml | 3 +++ .../client/petstore/java/rest-assured/api/openapi.yaml | 3 +++ samples/client/petstore/java/resteasy/api/openapi.yaml | 3 +++ .../petstore/java/resttemplate-withXml/api/openapi.yaml | 3 +++ .../client/petstore/java/resttemplate/api/openapi.yaml | 3 +++ .../petstore/java/retrofit2-play26/api/openapi.yaml | 3 +++ samples/client/petstore/java/retrofit2/api/openapi.yaml | 3 +++ .../client/petstore/java/retrofit2rx2/api/openapi.yaml | 3 +++ .../client/petstore/java/retrofit2rx3/api/openapi.yaml | 3 +++ samples/client/petstore/java/vertx/api/openapi.yaml | 3 +++ samples/client/petstore/java/webclient/api/openapi.yaml | 3 +++ .../go-experimental/go-petstore/api/openapi.yaml | 3 +++ .../client/petstore/go/go-petstore/api/openapi.yaml | 3 +++ .../jersey2-java8-special-characters/api/openapi.yaml | 2 ++ .../client/petstore/java/jersey2-java8/api/openapi.yaml | 4 ++++ .../public/openapi.json | 9 ++++++--- .../jaxrs-spec-interface/src/main/openapi/openapi.yaml | 3 +++ .../petstore/jaxrs-spec/src/main/openapi/openapi.yaml | 3 +++ .../rust-server/output/multipart-v3/api/openapi.yaml | 1 + .../rust-server/output/openapi-v3/api/openapi.yaml | 1 + .../api/openapi.yaml | 2 ++ .../rust-server/output/rust-server-test/api/openapi.yaml | 1 + .../springboot-reactive/src/main/resources/openapi.yaml | 3 +++ 35 files changed, 101 insertions(+), 3 deletions(-) diff --git a/samples/client/petstore/go-experimental/go-petstore/api/openapi.yaml b/samples/client/petstore/go-experimental/go-petstore/api/openapi.yaml index 7a47b6f9bee..2fe0565e0a5 100644 --- a/samples/client/petstore/go-experimental/go-petstore/api/openapi.yaml +++ b/samples/client/petstore/go-experimental/go-petstore/api/openapi.yaml @@ -2090,10 +2090,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2103,6 +2105,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/go/go-petstore-withXml/api/openapi.yaml b/samples/client/petstore/go/go-petstore-withXml/api/openapi.yaml index 7a47b6f9bee..2fe0565e0a5 100644 --- a/samples/client/petstore/go/go-petstore-withXml/api/openapi.yaml +++ b/samples/client/petstore/go/go-petstore-withXml/api/openapi.yaml @@ -2090,10 +2090,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2103,6 +2105,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/go/go-petstore/api/openapi.yaml b/samples/client/petstore/go/go-petstore/api/openapi.yaml index 7a47b6f9bee..2fe0565e0a5 100644 --- a/samples/client/petstore/go/go-petstore/api/openapi.yaml +++ b/samples/client/petstore/go/go-petstore/api/openapi.yaml @@ -2090,10 +2090,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2103,6 +2105,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/haskell-http-client/openapi.yaml b/samples/client/petstore/haskell-http-client/openapi.yaml index 7a47b6f9bee..2fe0565e0a5 100644 --- a/samples/client/petstore/haskell-http-client/openapi.yaml +++ b/samples/client/petstore/haskell-http-client/openapi.yaml @@ -2090,10 +2090,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2103,6 +2105,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/java/feign/api/openapi.yaml b/samples/client/petstore/java/feign/api/openapi.yaml index a49359fd348..00cc0f2f4c2 100644 --- a/samples/client/petstore/java/feign/api/openapi.yaml +++ b/samples/client/petstore/java/feign/api/openapi.yaml @@ -2151,10 +2151,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2164,6 +2166,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/java/google-api-client/api/openapi.yaml b/samples/client/petstore/java/google-api-client/api/openapi.yaml index a49359fd348..00cc0f2f4c2 100644 --- a/samples/client/petstore/java/google-api-client/api/openapi.yaml +++ b/samples/client/petstore/java/google-api-client/api/openapi.yaml @@ -2151,10 +2151,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2164,6 +2166,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/java/jersey1/api/openapi.yaml b/samples/client/petstore/java/jersey1/api/openapi.yaml index a49359fd348..00cc0f2f4c2 100644 --- a/samples/client/petstore/java/jersey1/api/openapi.yaml +++ b/samples/client/petstore/java/jersey1/api/openapi.yaml @@ -2151,10 +2151,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2164,6 +2166,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/java/jersey2-java8/api/openapi.yaml b/samples/client/petstore/java/jersey2-java8/api/openapi.yaml index a49359fd348..00cc0f2f4c2 100644 --- a/samples/client/petstore/java/jersey2-java8/api/openapi.yaml +++ b/samples/client/petstore/java/jersey2-java8/api/openapi.yaml @@ -2151,10 +2151,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2164,6 +2166,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/java/native-async/api/openapi.yaml b/samples/client/petstore/java/native-async/api/openapi.yaml index a49359fd348..00cc0f2f4c2 100644 --- a/samples/client/petstore/java/native-async/api/openapi.yaml +++ b/samples/client/petstore/java/native-async/api/openapi.yaml @@ -2151,10 +2151,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2164,6 +2166,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/java/native/api/openapi.yaml b/samples/client/petstore/java/native/api/openapi.yaml index a49359fd348..00cc0f2f4c2 100644 --- a/samples/client/petstore/java/native/api/openapi.yaml +++ b/samples/client/petstore/java/native/api/openapi.yaml @@ -2151,10 +2151,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2164,6 +2166,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/api/openapi.yaml b/samples/client/petstore/java/okhttp-gson-parcelableModel/api/openapi.yaml index a49359fd348..00cc0f2f4c2 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/api/openapi.yaml +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/api/openapi.yaml @@ -2151,10 +2151,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2164,6 +2166,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/java/okhttp-gson/api/openapi.yaml b/samples/client/petstore/java/okhttp-gson/api/openapi.yaml index a49359fd348..00cc0f2f4c2 100644 --- a/samples/client/petstore/java/okhttp-gson/api/openapi.yaml +++ b/samples/client/petstore/java/okhttp-gson/api/openapi.yaml @@ -2151,10 +2151,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2164,6 +2166,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/java/rest-assured-jackson/api/openapi.yaml b/samples/client/petstore/java/rest-assured-jackson/api/openapi.yaml index a49359fd348..00cc0f2f4c2 100644 --- a/samples/client/petstore/java/rest-assured-jackson/api/openapi.yaml +++ b/samples/client/petstore/java/rest-assured-jackson/api/openapi.yaml @@ -2151,10 +2151,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2164,6 +2166,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/java/rest-assured/api/openapi.yaml b/samples/client/petstore/java/rest-assured/api/openapi.yaml index a49359fd348..00cc0f2f4c2 100644 --- a/samples/client/petstore/java/rest-assured/api/openapi.yaml +++ b/samples/client/petstore/java/rest-assured/api/openapi.yaml @@ -2151,10 +2151,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2164,6 +2166,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/java/resteasy/api/openapi.yaml b/samples/client/petstore/java/resteasy/api/openapi.yaml index a49359fd348..00cc0f2f4c2 100644 --- a/samples/client/petstore/java/resteasy/api/openapi.yaml +++ b/samples/client/petstore/java/resteasy/api/openapi.yaml @@ -2151,10 +2151,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2164,6 +2166,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/java/resttemplate-withXml/api/openapi.yaml b/samples/client/petstore/java/resttemplate-withXml/api/openapi.yaml index a49359fd348..00cc0f2f4c2 100644 --- a/samples/client/petstore/java/resttemplate-withXml/api/openapi.yaml +++ b/samples/client/petstore/java/resttemplate-withXml/api/openapi.yaml @@ -2151,10 +2151,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2164,6 +2166,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/java/resttemplate/api/openapi.yaml b/samples/client/petstore/java/resttemplate/api/openapi.yaml index a49359fd348..00cc0f2f4c2 100644 --- a/samples/client/petstore/java/resttemplate/api/openapi.yaml +++ b/samples/client/petstore/java/resttemplate/api/openapi.yaml @@ -2151,10 +2151,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2164,6 +2166,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/java/retrofit2-play26/api/openapi.yaml b/samples/client/petstore/java/retrofit2-play26/api/openapi.yaml index a49359fd348..00cc0f2f4c2 100644 --- a/samples/client/petstore/java/retrofit2-play26/api/openapi.yaml +++ b/samples/client/petstore/java/retrofit2-play26/api/openapi.yaml @@ -2151,10 +2151,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2164,6 +2166,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/java/retrofit2/api/openapi.yaml b/samples/client/petstore/java/retrofit2/api/openapi.yaml index a49359fd348..00cc0f2f4c2 100644 --- a/samples/client/petstore/java/retrofit2/api/openapi.yaml +++ b/samples/client/petstore/java/retrofit2/api/openapi.yaml @@ -2151,10 +2151,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2164,6 +2166,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/java/retrofit2rx2/api/openapi.yaml b/samples/client/petstore/java/retrofit2rx2/api/openapi.yaml index a49359fd348..00cc0f2f4c2 100644 --- a/samples/client/petstore/java/retrofit2rx2/api/openapi.yaml +++ b/samples/client/petstore/java/retrofit2rx2/api/openapi.yaml @@ -2151,10 +2151,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2164,6 +2166,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/java/retrofit2rx3/api/openapi.yaml b/samples/client/petstore/java/retrofit2rx3/api/openapi.yaml index a49359fd348..00cc0f2f4c2 100644 --- a/samples/client/petstore/java/retrofit2rx3/api/openapi.yaml +++ b/samples/client/petstore/java/retrofit2rx3/api/openapi.yaml @@ -2151,10 +2151,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2164,6 +2166,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/java/vertx/api/openapi.yaml b/samples/client/petstore/java/vertx/api/openapi.yaml index a49359fd348..00cc0f2f4c2 100644 --- a/samples/client/petstore/java/vertx/api/openapi.yaml +++ b/samples/client/petstore/java/vertx/api/openapi.yaml @@ -2151,10 +2151,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2164,6 +2166,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/client/petstore/java/webclient/api/openapi.yaml b/samples/client/petstore/java/webclient/api/openapi.yaml index a49359fd348..00cc0f2f4c2 100644 --- a/samples/client/petstore/java/webclient/api/openapi.yaml +++ b/samples/client/petstore/java/webclient/api/openapi.yaml @@ -2151,10 +2151,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2164,6 +2166,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml b/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml index 7e77947b7a7..4bb7abdc392 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml @@ -1999,6 +1999,7 @@ components: properties: string: $ref: '#/components/schemas/Foo' + type: object inline_object: properties: name: @@ -2138,10 +2139,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/openapi3/client/petstore/go/go-petstore/api/openapi.yaml b/samples/openapi3/client/petstore/go/go-petstore/api/openapi.yaml index af7148414b9..51e7c243284 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/api/openapi.yaml +++ b/samples/openapi3/client/petstore/go/go-petstore/api/openapi.yaml @@ -1920,6 +1920,7 @@ components: properties: string: $ref: '#/components/schemas/Foo' + type: object inline_object: properties: name: @@ -2059,10 +2060,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/openapi3/client/petstore/java/jersey2-java8-special-characters/api/openapi.yaml b/samples/openapi3/client/petstore/java/jersey2-java8-special-characters/api/openapi.yaml index 44c6a2aa3c4..748bc1b78ed 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8-special-characters/api/openapi.yaml +++ b/samples/openapi3/client/petstore/java/jersey2-java8-special-characters/api/openapi.yaml @@ -46,8 +46,10 @@ components: properties: prop1: type: string + type: object MySchemaName___Characters_allOf: properties: prop2: type: string + type: object diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/api/openapi.yaml b/samples/openapi3/client/petstore/java/jersey2-java8/api/openapi.yaml index 373650648fe..e09549a0c3d 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/api/openapi.yaml +++ b/samples/openapi3/client/petstore/java/jersey2-java8/api/openapi.yaml @@ -2249,6 +2249,7 @@ components: properties: string: $ref: '#/components/schemas/Foo' + type: object inline_object: properties: name: @@ -2390,14 +2391,17 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object ChildCat_allOf: properties: name: type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/server/petstore/java-play-framework-fake-endpoints/public/openapi.json b/samples/server/petstore/java-play-framework-fake-endpoints/public/openapi.json index ebe044bed92..f5f2da4a943 100644 --- a/samples/server/petstore/java-play-framework-fake-endpoints/public/openapi.json +++ b/samples/server/petstore/java-play-framework-fake-endpoints/public/openapi.json @@ -2831,14 +2831,16 @@ "breed" : { "type" : "string" } - } + }, + "type" : "object" }, "Cat_allOf" : { "properties" : { "declawed" : { "type" : "boolean" } - } + }, + "type" : "object" }, "BigCat_allOf" : { "properties" : { @@ -2846,7 +2848,8 @@ "enum" : [ "lions", "tigers", "leopards", "jaguars" ], "type" : "string" } - } + }, + "type" : "object" } }, "securitySchemes" : { diff --git a/samples/server/petstore/jaxrs-spec-interface/src/main/openapi/openapi.yaml b/samples/server/petstore/jaxrs-spec-interface/src/main/openapi/openapi.yaml index da95378bbc8..7d1bd12ec82 100644 --- a/samples/server/petstore/jaxrs-spec-interface/src/main/openapi/openapi.yaml +++ b/samples/server/petstore/jaxrs-spec-interface/src/main/openapi/openapi.yaml @@ -2225,10 +2225,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2238,6 +2240,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/server/petstore/jaxrs-spec/src/main/openapi/openapi.yaml b/samples/server/petstore/jaxrs-spec/src/main/openapi/openapi.yaml index da95378bbc8..7d1bd12ec82 100644 --- a/samples/server/petstore/jaxrs-spec/src/main/openapi/openapi.yaml +++ b/samples/server/petstore/jaxrs-spec/src/main/openapi/openapi.yaml @@ -2225,10 +2225,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2238,6 +2240,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/server/petstore/rust-server/output/multipart-v3/api/openapi.yaml b/samples/server/petstore/rust-server/output/multipart-v3/api/openapi.yaml index cc003383b96..a1a58c5e69c 100644 --- a/samples/server/petstore/rust-server/output/multipart-v3/api/openapi.yaml +++ b/samples/server/petstore/rust-server/output/multipart-v3/api/openapi.yaml @@ -132,4 +132,5 @@ components: type: array required: - field_a + type: object diff --git a/samples/server/petstore/rust-server/output/openapi-v3/api/openapi.yaml b/samples/server/petstore/rust-server/output/openapi-v3/api/openapi.yaml index 907d126e3da..984374b520a 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/api/openapi.yaml +++ b/samples/server/petstore/rust-server/output/openapi-v3/api/openapi.yaml @@ -606,6 +606,7 @@ components: properties: foo: type: string + type: object securitySchemes: authScheme: flows: diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/api/openapi.yaml b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/api/openapi.yaml index 27f96b0bef1..02f3dc603a4 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/api/openapi.yaml +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/api/openapi.yaml @@ -1565,10 +1565,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object securitySchemes: petstore_auth: flows: diff --git a/samples/server/petstore/rust-server/output/rust-server-test/api/openapi.yaml b/samples/server/petstore/rust-server/output/rust-server-test/api/openapi.yaml index 276349f7a0e..59a9a76b887 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/api/openapi.yaml +++ b/samples/server/petstore/rust-server/output/rust-server-test/api/openapi.yaml @@ -211,4 +211,5 @@ components: type: integer required: - required_thing + type: object diff --git a/samples/server/petstore/springboot-reactive/src/main/resources/openapi.yaml b/samples/server/petstore/springboot-reactive/src/main/resources/openapi.yaml index da95378bbc8..7d1bd12ec82 100644 --- a/samples/server/petstore/springboot-reactive/src/main/resources/openapi.yaml +++ b/samples/server/petstore/springboot-reactive/src/main/resources/openapi.yaml @@ -2225,10 +2225,12 @@ components: properties: breed: type: string + type: object Cat_allOf: properties: declawed: type: boolean + type: object BigCat_allOf: properties: kind: @@ -2238,6 +2240,7 @@ components: - leopards - jaguars type: string + type: object securitySchemes: petstore_auth: flows: -- GitLab From eb85d809ec486d0beed60ef903a1a59be204d244 Mon Sep 17 00:00:00 2001 From: Jim Schubert <james.schubert@gmail.com> Date: Sat, 1 Aug 2020 22:04:15 -0400 Subject: [PATCH 3/5] Add regression test for attribute copy of flattened composed schemas --- .../codegen/InlineModelResolverTest.java | 108 +++++++++++ .../test/resources/2_0/regression_6905.yaml | 172 ++++++++++++++++++ 2 files changed, 280 insertions(+) create mode 100644 modules/openapi-generator/src/test/resources/2_0/regression_6905.yaml diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/InlineModelResolverTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/InlineModelResolverTest.java index e32a45252ed..c1e9784b94e 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/InlineModelResolverTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/InlineModelResolverTest.java @@ -768,6 +768,109 @@ public class InlineModelResolverTest { checkComposedChildren(openAPI, schema.getOneOf(), "oneOf"); } + + @Test + public void inheritanceWithInlineDiscriminator() { + OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/regression_6905.yaml"); + new InlineModelResolver().flatten(openAPI); + + assertTrue(openAPI.getComponents().getSchemas().get("PartyType") instanceof StringSchema); + assertTrue(openAPI.getComponents().getSchemas().get("CustomerType") instanceof StringSchema); + assertTrue(openAPI.getComponents().getSchemas().get("Entity") instanceof ObjectSchema); + + assertTrue(openAPI.getComponents().getSchemas().get("Party") instanceof ComposedSchema); + assertTrue(openAPI.getComponents().getSchemas().get("Contact") instanceof ComposedSchema); + assertTrue(openAPI.getComponents().getSchemas().get("Customer") instanceof ComposedSchema); + assertTrue(openAPI.getComponents().getSchemas().get("Person") instanceof ComposedSchema); + assertTrue(openAPI.getComponents().getSchemas().get("Organization") instanceof ComposedSchema); + + assertTrue(openAPI.getComponents().getSchemas().get("ApiError") instanceof ObjectSchema); + + assertFalse(openAPI.getComponents().getSchemas().get("Party_allOf") instanceof ComposedSchema); + assertFalse(openAPI.getComponents().getSchemas().get("Contact_allOf") instanceof ComposedSchema); + assertFalse(openAPI.getComponents().getSchemas().get("Customer_allOf") instanceof ComposedSchema); + assertFalse(openAPI.getComponents().getSchemas().get("Person_allOf") instanceof ComposedSchema); + assertFalse(openAPI.getComponents().getSchemas().get("Organization_allOf") instanceof ComposedSchema); + + // Party + ComposedSchema party = (ComposedSchema) openAPI.getComponents().getSchemas().get("Party"); + List<Schema> partySchemas = party.getAllOf(); + Schema entity = ModelUtils.getReferencedSchema(openAPI, partySchemas.get(0)); + Schema partyAllOf = ModelUtils.getReferencedSchema(openAPI, partySchemas.get(1)); + + assertEquals(partySchemas.get(0).get$ref(), "#/components/schemas/Entity"); + assertEquals(partySchemas.get(1).get$ref(), "#/components/schemas/Party_allOf"); + + assertNull(party.getDiscriminator()); + assertNull(entity.getDiscriminator()); + assertNotNull(partyAllOf.getDiscriminator()); + assertEquals(partyAllOf.getDiscriminator().getPropertyName(), "party_type"); + assertEquals(partyAllOf.getRequired().get(0), "party_type"); + + + // Contact + ComposedSchema contact = (ComposedSchema) openAPI.getComponents().getSchemas().get("Contact"); + Schema contactAllOf = ModelUtils.getReferencedSchema(openAPI, contact.getAllOf().get(1)); + + assertEquals(contact.getExtensions().get("x-discriminator-value"), "contact"); + assertEquals(contact.getAllOf().get(0).get$ref(), "#/components/schemas/Party"); + assertEquals(contact.getAllOf().get(1).get$ref(), "#/components/schemas/Contact_allOf"); + assertNull(contactAllOf.getDiscriminator()); + + + // Customer + ComposedSchema customer = (ComposedSchema) openAPI.getComponents().getSchemas().get("Customer"); + List<Schema> customerSchemas = customer.getAllOf(); + Schema customerAllOf = ModelUtils.getReferencedSchema(openAPI, customerSchemas.get(1)); + + assertEquals(customerSchemas.get(0).get$ref(), "#/components/schemas/Party"); + assertNull(customer.getDiscriminator()); + assertEquals(customer.getExtensions().get("x-discriminator-value"), "customer"); + + // Discriminators are not defined at this level in the schema doc + assertNull(customerSchemas.get(0).getDiscriminator()); + assertEquals(customerSchemas.get(1).get$ref(), "#/components/schemas/Customer_allOf"); + assertNull(customerSchemas.get(1).getDiscriminator()); + + // Customer -> Party where Customer defines it's own discriminator + assertNotNull(customerAllOf.getDiscriminator()); + assertEquals(customerAllOf.getDiscriminator().getPropertyName(), "customer_type"); + assertEquals(customerAllOf.getRequired().get(0), "customer_type"); + + + // Person + ComposedSchema person = (ComposedSchema) openAPI.getComponents().getSchemas().get("Person"); + List<Schema> personSchemas = person.getAllOf(); + Schema personAllOf = ModelUtils.getReferencedSchema(openAPI, personSchemas.get(1)); + + // Discriminators are not defined at this level in the schema doc + assertEquals(personSchemas.get(0).get$ref(), "#/components/schemas/Customer"); + assertNull(personSchemas.get(0).getDiscriminator()); + assertEquals(personSchemas.get(1).get$ref(), "#/components/schemas/Person_allOf"); + assertNull(personSchemas.get(1).getDiscriminator()); + + // Person -> Customer -> Party, so discriminator is not at this level + assertNull(person.getDiscriminator()); + assertEquals(person.getExtensions().get("x-discriminator-value"), "person"); + assertNull(personAllOf.getDiscriminator()); + + + // Organization + ComposedSchema organization = (ComposedSchema) openAPI.getComponents().getSchemas().get("Organization"); + List<Schema> organizationSchemas = organization.getAllOf(); + Schema organizationAllOf = ModelUtils.getReferencedSchema(openAPI, organizationSchemas.get(1)); + + // Discriminators are not defined at this level in the schema doc + assertEquals(organizationSchemas.get(0).get$ref(), "#/components/schemas/Customer"); + assertNull(organizationSchemas.get(0).getDiscriminator()); + assertEquals(organizationSchemas.get(1).get$ref(), "#/components/schemas/Organization_allOf"); + assertNull(organizationSchemas.get(1).getDiscriminator()); + + // Organization -> Customer -> Party, so discriminator is not at this level + assertNull(organizationAllOf.getDiscriminator()); + assertEquals(organization.getExtensions().get("x-discriminator-value"), "organization"); + } + @Test public void arbitraryObjectModelWithArrayInlineWithTitle() { OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml"); @@ -871,4 +974,9 @@ public class InlineModelResolverTest { assertTrue(properties.get("action") instanceof StringSchema); assertTrue(properties.get("data") instanceof StringSchema); } + + @Test + public void regresssion_6905() { + + } } \ No newline at end of file diff --git a/modules/openapi-generator/src/test/resources/2_0/regression_6905.yaml b/modules/openapi-generator/src/test/resources/2_0/regression_6905.yaml new file mode 100644 index 00000000000..5a750ae1dd3 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/2_0/regression_6905.yaml @@ -0,0 +1,172 @@ +swagger: '2.0' + +info: + title: Test Command model generation + description: Test Command model generation + version: 1.0.0 +definitions: + PartyType: + description: type + type: string + enum: + - customer + - contact + + CustomerType: + description: type + type: string + enum: + - person + - organization + + Entity: + type: object + properties: + id: + type: string + readOnly: true + + Party: + allOf: + - $ref: '#/definitions/Entity' + - type: object + discriminator: party_type + required: + - party_type + properties: + party_type: + readOnly: true + $ref: '#/definitions/PartyType' + tax_id_number: + type: string + + Contact: + x-discriminator-value: contact + allOf: + - $ref: '#/definitions/Party' + - type: object + properties: + first_name: + type: string + last_name: + type: string + suffix: + type: string + dob: + type: string + format: date + + Customer: + x-discriminator-value: customer + allOf: + - $ref: '#/definitions/Party' + - type: object + discriminator: customer_type + required: + - customer_type + properties: + customer_type: + readOnly: true + $ref: '#/definitions/CustomerType' + customer_num: + type: string + external_customer_num: + type: string + Person: + x-discriminator-value: person + allOf: + - $ref: '#/definitions/Customer' + - type: object + properties: + first_name: + type: string + last_name: + type: string + + Organization: + x-discriminator-value: organization + allOf: + - $ref: '#/definitions/Customer' + - type: object + required: + - organization_name + properties: + organization_name: + type: string + + ApiError: + type: object + required: + - code + - message + properties: + code: + type: string + readOnly: true + message: + type: string + readOnly: true + +paths: + /customers: + get: + consumes: [] + operationId: queryCustomers + tags: + - Customer + summary: Get customers + responses: + 200: + description: Success + schema: + type: array + items: + $ref: '#/definitions/Customer' + 400: + description: Bad request. + schema: + $ref: '#/definitions/ApiError' + default: + description: Unknown error. + schema: + $ref: '#/definitions/ApiError' + /contacts: + get: + consumes: [] + operationId: queryContacts + tags: + - Contact + summary: Get contact + responses: + 200: + description: Success + schema: + type: array + items: + $ref: '#/definitions/Contact' + 400: + description: Bad request. + schema: + $ref: '#/definitions/ApiError' + default: + description: Unknown error. + schema: + $ref: '#/definitions/ApiError' + /parties: + get: + consumes: [] + responses: + 200: + description: Success + schema: + type: array + items: + $ref: '#/definitions/Party' + 400: + description: Bad request. + schema: + $ref: '#/definitions/ApiError' + default: + description: Unknown error. + schema: + $ref: '#/definitions/ApiError' -- GitLab From 3770a2b7b4d05ab454f82bb8112a4eea70697f37 Mon Sep 17 00:00:00 2001 From: Jim Schubert <james.schubert@gmail.com> Date: Sat, 1 Aug 2020 22:04:47 -0400 Subject: [PATCH 4/5] Ensure consistent model structure keying with sorted properties in Jackson JSON writer --- .../codegen/InlineModelResolver.java | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java index f9cb430e05f..660f6cfaa31 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java @@ -17,6 +17,10 @@ package org.openapitools.codegen; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import io.swagger.v3.core.util.Json; import io.swagger.v3.oas.models.*; import io.swagger.v3.oas.models.callbacks.Callback; @@ -25,6 +29,7 @@ import io.swagger.v3.oas.models.parameters.Parameter; import io.swagger.v3.oas.models.parameters.RequestBody; import io.swagger.v3.oas.models.responses.ApiResponse; import io.swagger.v3.oas.models.responses.ApiResponses; +import org.apache.commons.lang3.StringUtils; import org.openapitools.codegen.utils.ModelUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,6 +41,17 @@ public class InlineModelResolver { private OpenAPI openapi; private Map<String, Schema> addedModels = new HashMap<String, Schema>(); private Map<String, String> generatedSignature = new HashMap<String, String>(); + + // structure mapper sorts properties alphabetically on write to ensure models are + // serialized consistently for lookup of existing models + private static ObjectMapper structureMapper; + + static { + structureMapper = Json.mapper().copy(); + structureMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); + structureMapper.writer(new DefaultPrettyPrinter()); + } + static Logger LOGGER = LoggerFactory.getLogger(InlineModelResolver.class); void flatten(OpenAPI openapi) { @@ -488,15 +504,25 @@ public class InlineModelResolver { } private String matchGenerated(Schema model) { - String json = Json.pretty(model); - if (generatedSignature.containsKey(json)) { - return generatedSignature.get(json); + try { + String json = structureMapper.writeValueAsString(model); + if (generatedSignature.containsKey(json)) { + return generatedSignature.get(json); + } + } catch (JsonProcessingException e) { + e.printStackTrace(); } + return null; } private void addGenerated(String name, Schema model) { - generatedSignature.put(Json.pretty(model), name); + try { + String json = structureMapper.writeValueAsString(model); + generatedSignature.put(json, name); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } } /** -- GitLab From a034b52fedf0db0562a0c03665ea58f251662d16 Mon Sep 17 00:00:00 2001 From: Jim Schubert <james.schubert@gmail.com> Date: Mon, 3 Aug 2020 21:12:54 -0400 Subject: [PATCH 5/5] Remove unnecessary null checks and duplicate setters in InlineModelResolver --- .../codegen/InlineModelResolver.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java index a8a78222d84..4a9a163f8c3 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java @@ -646,16 +646,17 @@ public class InlineModelResolver { } XML xml = object.getXml(); Map<String, Schema> properties = object.getProperties(); + + // NOTE: + // No need to null check setters below. All defaults in the new'd Schema are null, so setting to null would just be a noop. Schema model = new Schema(); - if (object.getType() != null) { - model.setType(object.getType()); - } - if (object.getFormat() != null) { - // Even though the `format` keyword typically applies to primitive types only, - // the JSON schema specification states `format` can be used for any model type instance - // including object types. - model.setFormat(object.getFormat()); - } + model.setType(object.getType()); + + // Even though the `format` keyword typically applies to primitive types only, + // the JSON schema specification states `format` can be used for any model type instance + // including object types. + model.setFormat(object.getFormat()); + model.setDescription(description); model.setExample(example); model.setName(object.getName()); @@ -665,7 +666,6 @@ public class InlineModelResolver { model.setDiscriminator(object.getDiscriminator()); model.setWriteOnly(object.getWriteOnly()); model.setUniqueItems(object.getUniqueItems()); - model.setType(object.getType()); model.setTitle(object.getTitle()); model.setReadOnly(object.getReadOnly()); model.setPattern(object.getPattern()); @@ -678,7 +678,6 @@ public class InlineModelResolver { model.setMaxLength(object.getMaxLength()); model.setMaxItems(object.getMaxItems()); model.setMaximum(object.getMaximum()); - model.setFormat(object.getFormat()); model.setExternalDocs(object.getExternalDocs()); model.setExtensions(object.getExtensions()); model.setExclusiveMinimum(object.getExclusiveMinimum()); -- GitLab