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 30ac18c43e35..40ab769081de 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 @@ -472,14 +472,22 @@ private void flattenComponents(OpenAPI openAPI) { * @param m Schema implementation */ private void fixStringModel(Schema m) { - if (m.getType() != null && m.getType().equals("string") && m.getExample() != null) { + if (schemaIsOfType(m, "string") && schemaContainsExample(m)) { String example = m.getExample().toString(); - if (example.substring(0, 1).equals("\"") && example.substring(example.length() - 1).equals("\"")) { + if (example.startsWith("\"") && example.endsWith("\"")) { m.setExample(example.substring(1, example.length() - 1)); } } } + private boolean schemaIsOfType(Schema m, String type) { + return m.getType() != null && m.getType().equals(type); + } + + private boolean schemaContainsExample(Schema m) { + return m.getExample() != null && m.getExample() != ""; + } + /** * Generates a unique model name. Non-alphanumeric characters will be replaced * with underscores 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 e612f985de3c..2ebc0d52143d 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 @@ -28,6 +28,7 @@ import io.swagger.v3.oas.models.responses.ApiResponses; import io.swagger.v3.parser.core.models.ParseOptions; import org.openapitools.codegen.utils.ModelUtils; +import org.testng.Assert; import org.testng.annotations.Test; import java.util.HashMap; @@ -927,7 +928,7 @@ public void emptyExampleOnStringTypeModels() { assertEquals("#/components/schemas/EmptyExampleOnStringTypeModels", schema.getItems().get$ref()); assertTrue(ModelUtils.getReferencedSchema(openAPI, schema.getItems()) instanceof StringSchema); - assertNull(ModelUtils.getReferencedSchema(openAPI, schema.getItems()).getExample()); + Assert.assertSame(ModelUtils.getReferencedSchema(openAPI, schema.getItems()).getExample(), ""); } @Test diff --git a/pom.xml b/pom.xml index 79ff6da7d47b..2359a785cf57 100644 --- a/pom.xml +++ b/pom.xml @@ -1516,7 +1516,7 @@ 1.8 2.1.2 io.swagger.parser.v3 - 2.0.20 + 2.0.22 3.3.1 2.4 1.2 diff --git a/samples/client/petstore/go/go-petstore/api/openapi.yaml b/samples/client/petstore/go/go-petstore/api/openapi.yaml index 2fe0565e0a54..4c7dda7a3b82 100644 --- a/samples/client/petstore/go/go-petstore/api/openapi.yaml +++ b/samples/client/petstore/go/go-petstore/api/openapi.yaml @@ -2126,3 +2126,4 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" diff --git a/samples/client/petstore/haskell-http-client/openapi.yaml b/samples/client/petstore/haskell-http-client/openapi.yaml index 2fe0565e0a54..4c7dda7a3b82 100644 --- a/samples/client/petstore/haskell-http-client/openapi.yaml +++ b/samples/client/petstore/haskell-http-client/openapi.yaml @@ -2126,3 +2126,4 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" diff --git a/samples/client/petstore/java/feign-no-nullable/api/openapi.yaml b/samples/client/petstore/java/feign-no-nullable/api/openapi.yaml index 00cc0f2f4c26..0b3ef3a11c93 100644 --- a/samples/client/petstore/java/feign-no-nullable/api/openapi.yaml +++ b/samples/client/petstore/java/feign-no-nullable/api/openapi.yaml @@ -2187,4 +2187,5 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" diff --git a/samples/client/petstore/java/feign/api/openapi.yaml b/samples/client/petstore/java/feign/api/openapi.yaml index 00cc0f2f4c26..0b3ef3a11c93 100644 --- a/samples/client/petstore/java/feign/api/openapi.yaml +++ b/samples/client/petstore/java/feign/api/openapi.yaml @@ -2187,4 +2187,5 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" 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 00cc0f2f4c26..0b3ef3a11c93 100644 --- a/samples/client/petstore/java/google-api-client/api/openapi.yaml +++ b/samples/client/petstore/java/google-api-client/api/openapi.yaml @@ -2187,4 +2187,5 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" diff --git a/samples/client/petstore/java/jersey1/api/openapi.yaml b/samples/client/petstore/java/jersey1/api/openapi.yaml index 00cc0f2f4c26..0b3ef3a11c93 100644 --- a/samples/client/petstore/java/jersey1/api/openapi.yaml +++ b/samples/client/petstore/java/jersey1/api/openapi.yaml @@ -2187,4 +2187,5 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" diff --git a/samples/client/petstore/java/jersey2-java8/api/openapi.yaml b/samples/client/petstore/java/jersey2-java8/api/openapi.yaml index 00cc0f2f4c26..0b3ef3a11c93 100644 --- a/samples/client/petstore/java/jersey2-java8/api/openapi.yaml +++ b/samples/client/petstore/java/jersey2-java8/api/openapi.yaml @@ -2187,4 +2187,5 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" diff --git a/samples/client/petstore/java/native-async/api/openapi.yaml b/samples/client/petstore/java/native-async/api/openapi.yaml index 00cc0f2f4c26..0b3ef3a11c93 100644 --- a/samples/client/petstore/java/native-async/api/openapi.yaml +++ b/samples/client/petstore/java/native-async/api/openapi.yaml @@ -2187,4 +2187,5 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" diff --git a/samples/client/petstore/java/native/api/openapi.yaml b/samples/client/petstore/java/native/api/openapi.yaml index 00cc0f2f4c26..0b3ef3a11c93 100644 --- a/samples/client/petstore/java/native/api/openapi.yaml +++ b/samples/client/petstore/java/native/api/openapi.yaml @@ -2187,4 +2187,5 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" 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 00cc0f2f4c26..0b3ef3a11c93 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/api/openapi.yaml +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/api/openapi.yaml @@ -2187,4 +2187,5 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" diff --git a/samples/client/petstore/java/okhttp-gson/api/openapi.yaml b/samples/client/petstore/java/okhttp-gson/api/openapi.yaml index 00cc0f2f4c26..0b3ef3a11c93 100644 --- a/samples/client/petstore/java/okhttp-gson/api/openapi.yaml +++ b/samples/client/petstore/java/okhttp-gson/api/openapi.yaml @@ -2187,4 +2187,5 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" 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 00cc0f2f4c26..0b3ef3a11c93 100644 --- a/samples/client/petstore/java/rest-assured-jackson/api/openapi.yaml +++ b/samples/client/petstore/java/rest-assured-jackson/api/openapi.yaml @@ -2187,4 +2187,5 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" diff --git a/samples/client/petstore/java/rest-assured/api/openapi.yaml b/samples/client/petstore/java/rest-assured/api/openapi.yaml index 00cc0f2f4c26..0b3ef3a11c93 100644 --- a/samples/client/petstore/java/rest-assured/api/openapi.yaml +++ b/samples/client/petstore/java/rest-assured/api/openapi.yaml @@ -2187,4 +2187,5 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" diff --git a/samples/client/petstore/java/resteasy/api/openapi.yaml b/samples/client/petstore/java/resteasy/api/openapi.yaml index 00cc0f2f4c26..0b3ef3a11c93 100644 --- a/samples/client/petstore/java/resteasy/api/openapi.yaml +++ b/samples/client/petstore/java/resteasy/api/openapi.yaml @@ -2187,4 +2187,5 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" diff --git a/samples/client/petstore/java/resttemplate-withXml/api/openapi.yaml b/samples/client/petstore/java/resttemplate-withXml/api/openapi.yaml index 00cc0f2f4c26..0b3ef3a11c93 100644 --- a/samples/client/petstore/java/resttemplate-withXml/api/openapi.yaml +++ b/samples/client/petstore/java/resttemplate-withXml/api/openapi.yaml @@ -2187,4 +2187,5 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" diff --git a/samples/client/petstore/java/resttemplate/api/openapi.yaml b/samples/client/petstore/java/resttemplate/api/openapi.yaml index 00cc0f2f4c26..0b3ef3a11c93 100644 --- a/samples/client/petstore/java/resttemplate/api/openapi.yaml +++ b/samples/client/petstore/java/resttemplate/api/openapi.yaml @@ -2187,4 +2187,5 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" diff --git a/samples/client/petstore/java/retrofit2-play26/api/openapi.yaml b/samples/client/petstore/java/retrofit2-play26/api/openapi.yaml index 00cc0f2f4c26..0b3ef3a11c93 100644 --- a/samples/client/petstore/java/retrofit2-play26/api/openapi.yaml +++ b/samples/client/petstore/java/retrofit2-play26/api/openapi.yaml @@ -2187,4 +2187,5 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" diff --git a/samples/client/petstore/java/retrofit2/api/openapi.yaml b/samples/client/petstore/java/retrofit2/api/openapi.yaml index 00cc0f2f4c26..0b3ef3a11c93 100644 --- a/samples/client/petstore/java/retrofit2/api/openapi.yaml +++ b/samples/client/petstore/java/retrofit2/api/openapi.yaml @@ -2187,4 +2187,5 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" diff --git a/samples/client/petstore/java/retrofit2rx2/api/openapi.yaml b/samples/client/petstore/java/retrofit2rx2/api/openapi.yaml index 00cc0f2f4c26..0b3ef3a11c93 100644 --- a/samples/client/petstore/java/retrofit2rx2/api/openapi.yaml +++ b/samples/client/petstore/java/retrofit2rx2/api/openapi.yaml @@ -2187,4 +2187,5 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" diff --git a/samples/client/petstore/java/retrofit2rx3/api/openapi.yaml b/samples/client/petstore/java/retrofit2rx3/api/openapi.yaml index 00cc0f2f4c26..0b3ef3a11c93 100644 --- a/samples/client/petstore/java/retrofit2rx3/api/openapi.yaml +++ b/samples/client/petstore/java/retrofit2rx3/api/openapi.yaml @@ -2187,4 +2187,5 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" diff --git a/samples/client/petstore/java/vertx-no-nullable/api/openapi.yaml b/samples/client/petstore/java/vertx-no-nullable/api/openapi.yaml index 00cc0f2f4c26..0b3ef3a11c93 100644 --- a/samples/client/petstore/java/vertx-no-nullable/api/openapi.yaml +++ b/samples/client/petstore/java/vertx-no-nullable/api/openapi.yaml @@ -2187,4 +2187,5 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" diff --git a/samples/client/petstore/java/vertx/api/openapi.yaml b/samples/client/petstore/java/vertx/api/openapi.yaml index 00cc0f2f4c26..0b3ef3a11c93 100644 --- a/samples/client/petstore/java/vertx/api/openapi.yaml +++ b/samples/client/petstore/java/vertx/api/openapi.yaml @@ -2187,4 +2187,5 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" diff --git a/samples/client/petstore/java/webclient/api/openapi.yaml b/samples/client/petstore/java/webclient/api/openapi.yaml index 00cc0f2f4c26..0b3ef3a11c93 100644 --- a/samples/client/petstore/java/webclient/api/openapi.yaml +++ b/samples/client/petstore/java/webclient/api/openapi.yaml @@ -2187,4 +2187,5 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" diff --git a/samples/server/petstore/java-play-framework-api-package-override/public/openapi.json b/samples/server/petstore/java-play-framework-api-package-override/public/openapi.json index 1a863721712a..e1554af7b8ff 100644 --- a/samples/server/petstore/java-play-framework-api-package-override/public/openapi.json +++ b/samples/server/petstore/java-play-framework-api-package-override/public/openapi.json @@ -1037,5 +1037,6 @@ "type" : "apiKey" } } - } + }, + "x-original-swagger-version" : "2.0" } \ No newline at end of file diff --git a/samples/server/petstore/java-play-framework-async/public/openapi.json b/samples/server/petstore/java-play-framework-async/public/openapi.json index 1a863721712a..e1554af7b8ff 100644 --- a/samples/server/petstore/java-play-framework-async/public/openapi.json +++ b/samples/server/petstore/java-play-framework-async/public/openapi.json @@ -1037,5 +1037,6 @@ "type" : "apiKey" } } - } + }, + "x-original-swagger-version" : "2.0" } \ No newline at end of file diff --git a/samples/server/petstore/java-play-framework-controller-only/public/openapi.json b/samples/server/petstore/java-play-framework-controller-only/public/openapi.json index 1a863721712a..e1554af7b8ff 100644 --- a/samples/server/petstore/java-play-framework-controller-only/public/openapi.json +++ b/samples/server/petstore/java-play-framework-controller-only/public/openapi.json @@ -1037,5 +1037,6 @@ "type" : "apiKey" } } - } + }, + "x-original-swagger-version" : "2.0" } \ No newline at end of file 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 f5f2da4a9437..25825c7a17da 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 @@ -2880,5 +2880,6 @@ "type" : "http" } } - } + }, + "x-original-swagger-version" : "2.0" } \ No newline at end of file diff --git a/samples/server/petstore/java-play-framework-no-bean-validation/public/openapi.json b/samples/server/petstore/java-play-framework-no-bean-validation/public/openapi.json index 1a863721712a..e1554af7b8ff 100644 --- a/samples/server/petstore/java-play-framework-no-bean-validation/public/openapi.json +++ b/samples/server/petstore/java-play-framework-no-bean-validation/public/openapi.json @@ -1037,5 +1037,6 @@ "type" : "apiKey" } } - } + }, + "x-original-swagger-version" : "2.0" } \ No newline at end of file diff --git a/samples/server/petstore/java-play-framework-no-exception-handling/public/openapi.json b/samples/server/petstore/java-play-framework-no-exception-handling/public/openapi.json index 1a863721712a..e1554af7b8ff 100644 --- a/samples/server/petstore/java-play-framework-no-exception-handling/public/openapi.json +++ b/samples/server/petstore/java-play-framework-no-exception-handling/public/openapi.json @@ -1037,5 +1037,6 @@ "type" : "apiKey" } } - } + }, + "x-original-swagger-version" : "2.0" } \ No newline at end of file diff --git a/samples/server/petstore/java-play-framework-no-interface/public/openapi.json b/samples/server/petstore/java-play-framework-no-interface/public/openapi.json index 1a863721712a..e1554af7b8ff 100644 --- a/samples/server/petstore/java-play-framework-no-interface/public/openapi.json +++ b/samples/server/petstore/java-play-framework-no-interface/public/openapi.json @@ -1037,5 +1037,6 @@ "type" : "apiKey" } } - } + }, + "x-original-swagger-version" : "2.0" } \ No newline at end of file diff --git a/samples/server/petstore/java-play-framework-no-nullable/public/openapi.json b/samples/server/petstore/java-play-framework-no-nullable/public/openapi.json index 1a863721712a..e1554af7b8ff 100644 --- a/samples/server/petstore/java-play-framework-no-nullable/public/openapi.json +++ b/samples/server/petstore/java-play-framework-no-nullable/public/openapi.json @@ -1037,5 +1037,6 @@ "type" : "apiKey" } } - } + }, + "x-original-swagger-version" : "2.0" } \ No newline at end of file diff --git a/samples/server/petstore/java-play-framework-no-wrap-calls/public/openapi.json b/samples/server/petstore/java-play-framework-no-wrap-calls/public/openapi.json index 1a863721712a..e1554af7b8ff 100644 --- a/samples/server/petstore/java-play-framework-no-wrap-calls/public/openapi.json +++ b/samples/server/petstore/java-play-framework-no-wrap-calls/public/openapi.json @@ -1037,5 +1037,6 @@ "type" : "apiKey" } } - } + }, + "x-original-swagger-version" : "2.0" } \ No newline at end of file diff --git a/samples/server/petstore/java-play-framework/public/openapi.json b/samples/server/petstore/java-play-framework/public/openapi.json index 1a863721712a..e1554af7b8ff 100644 --- a/samples/server/petstore/java-play-framework/public/openapi.json +++ b/samples/server/petstore/java-play-framework/public/openapi.json @@ -1037,5 +1037,6 @@ "type" : "apiKey" } } - } + }, + "x-original-swagger-version" : "2.0" } \ No newline at end of file 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 7d1bd12ec826..7d2de524fc6e 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 @@ -2261,3 +2261,4 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" 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 7d1bd12ec826..7d2de524fc6e 100644 --- a/samples/server/petstore/jaxrs-spec/src/main/openapi/openapi.yaml +++ b/samples/server/petstore/jaxrs-spec/src/main/openapi/openapi.yaml @@ -2261,3 +2261,4 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" diff --git a/samples/server/petstore/python-aiohttp-srclayout/src/openapi_server/openapi/openapi.yaml b/samples/server/petstore/python-aiohttp-srclayout/src/openapi_server/openapi/openapi.yaml index 030b84f7402c..1e68be278ed1 100644 --- a/samples/server/petstore/python-aiohttp-srclayout/src/openapi_server/openapi/openapi.yaml +++ b/samples/server/petstore/python-aiohttp-srclayout/src/openapi_server/openapi/openapi.yaml @@ -794,3 +794,4 @@ components: name: api_key type: apiKey x-apikeyInfoFunc: openapi_server.controllers.security_controller_.info_from_api_key +x-original-swagger-version: "2.0" diff --git a/samples/server/petstore/python-aiohttp/openapi_server/openapi/openapi.yaml b/samples/server/petstore/python-aiohttp/openapi_server/openapi/openapi.yaml index 030b84f7402c..1e68be278ed1 100644 --- a/samples/server/petstore/python-aiohttp/openapi_server/openapi/openapi.yaml +++ b/samples/server/petstore/python-aiohttp/openapi_server/openapi/openapi.yaml @@ -794,3 +794,4 @@ components: name: api_key type: apiKey x-apikeyInfoFunc: openapi_server.controllers.security_controller_.info_from_api_key +x-original-swagger-version: "2.0" diff --git a/samples/server/petstore/python-flask/openapi_server/openapi/openapi.yaml b/samples/server/petstore/python-flask/openapi_server/openapi/openapi.yaml index 69c15a8f11a3..0edb89eac95b 100644 --- a/samples/server/petstore/python-flask/openapi_server/openapi/openapi.yaml +++ b/samples/server/petstore/python-flask/openapi_server/openapi/openapi.yaml @@ -783,3 +783,4 @@ components: name: api_key type: apiKey x-apikeyInfoFunc: openapi_server.controllers.security_controller_.info_from_api_key +x-original-swagger-version: "2.0" 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 02f3dc603a4b..0885080f5fdc 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 @@ -1591,4 +1591,5 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0" 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 59a9a76b8877..e7cef9a3cf2a 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 @@ -212,4 +212,5 @@ components: required: - required_thing type: object +x-original-swagger-version: "2.0" 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 7d1bd12ec826..7d2de524fc6e 100644 --- a/samples/server/petstore/springboot-reactive/src/main/resources/openapi.yaml +++ b/samples/server/petstore/springboot-reactive/src/main/resources/openapi.yaml @@ -2261,3 +2261,4 @@ components: http_basic_test: scheme: basic type: http +x-original-swagger-version: "2.0"