diff --git a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CodegenConfig.java b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CodegenConfig.java index f163f25ee..aa707bc7e 100644 --- a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CodegenConfig.java +++ b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CodegenConfig.java @@ -73,7 +73,8 @@ public enum ConfigName { REMOVE_OPERATION_ID_PREFIX_COUNT("remove-operation-id-prefix-count"), GENERATE_APIS("generate-apis"), GENERATE_MODELS("generate-models"), - BEAN_VALIDATION("use-bean-validation"); + BEAN_VALIDATION("use-bean-validation"), + SERIALIZABLE_MODEL("serializable-model"); private final String name; diff --git a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/OpenApiGeneratorCodeGenBase.java b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/OpenApiGeneratorCodeGenBase.java index 0431e6777..c4f69013b 100644 --- a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/OpenApiGeneratorCodeGenBase.java +++ b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/OpenApiGeneratorCodeGenBase.java @@ -317,6 +317,9 @@ protected void generate(OpenApiGeneratorOptions options) { getValues(smallRyeConfig, openApiFilePath, CodegenConfig.ConfigName.SCHEMA_MAPPINGS, String.class, String.class) .ifPresent(generator::withSchemaMappings); + getValues(smallRyeConfig, openApiFilePath, CodegenConfig.ConfigName.SERIALIZABLE_MODEL, Boolean.class) + .ifPresent(generator::withSerialiableModel); + getValues(smallRyeConfig, openApiFilePath, CodegenConfig.ConfigName.NORMALIZER, String.class, String.class) .ifPresent(generator::withOpenApiNormalizer); diff --git a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/wrapper/OpenApiClientGeneratorWrapper.java b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/wrapper/OpenApiClientGeneratorWrapper.java index 7d34db5e4..12147ece2 100644 --- a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/wrapper/OpenApiClientGeneratorWrapper.java +++ b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/wrapper/OpenApiClientGeneratorWrapper.java @@ -111,7 +111,6 @@ private void setDefaults() { this.configurator.addAdditionalProperty("use-bean-validation", FALSE); this.configurator.addAdditionalProperty("use-field-name-in-part-filename", FALSE); this.configurator.addAdditionalProperty("verbose", FALSE); - // TODO: expose as properties https://github.com/quarkiverse/quarkus-openapi-generator/issues/869 this.configurator.addAdditionalProperty(CodegenConstants.SERIALIZABLE_MODEL, FALSE); } @@ -198,6 +197,11 @@ public OpenApiClientGeneratorWrapper withOpenApiNormalizer(final Mapconfig-key github without-oidc + serializable-model diff --git a/client/integration-tests/serializable-model/pom.xml b/client/integration-tests/serializable-model/pom.xml new file mode 100644 index 000000000..80df64ac6 --- /dev/null +++ b/client/integration-tests/serializable-model/pom.xml @@ -0,0 +1,94 @@ + + + + quarkus-openapi-generator-integration-tests + io.quarkiverse.openapi.generator + 3.0.0-SNAPSHOT + + 4.0.0 + + quarkus-openapi-generator-it-serializable-model + Quarkus - Openapi Generator - Integration Tests - Client - Serializable model + Example project for general usage + + + + io.quarkiverse.openapi.generator + quarkus-openapi-generator + + + org.assertj + assertj-core + test + + + io.quarkus + quarkus-junit5 + test + + + + + + io.quarkus + quarkus-maven-plugin + true + + + + build + generate-code + generate-code-tests + + + + + + + + + native-image + + + native + + + + + + maven-surefire-plugin + + ${native.surefire.skip} + + + + maven-failsafe-plugin + + + + integration-test + verify + + + + + ${project.build.directory}/${project.build.finalName}-runner + + org.jboss.logmanager.LogManager + + ${maven.home} + + + + + + + + + native + + + + + \ No newline at end of file diff --git a/client/integration-tests/serializable-model/src/main/openapi/quarkus-non-serializable-openapi.yaml b/client/integration-tests/serializable-model/src/main/openapi/quarkus-non-serializable-openapi.yaml new file mode 100644 index 000000000..ec431be5e --- /dev/null +++ b/client/integration-tests/serializable-model/src/main/openapi/quarkus-non-serializable-openapi.yaml @@ -0,0 +1,125 @@ +{ + "openapi": "3.0.2", + "info": { + "title": "Animals - OpenAPI 3.0", + "version": "1.0.5" + }, + "servers": [ + { + "url": "/api/v3" + } + ], + "tags": [ + { + "name": "primate", + "description": "Everything about Primates" + } + ], + "paths": { + "/primate/{id}": { + "get": { + "tags": [ + "primate" + ], + "summary": "Find primate by ID", + "description": "Returns a single primate", + "operationId": "getPrimateById", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "ID of primate to return", + "required": true, + "schema": { + "type": "integer", + "format": "int64" + } + } + ], + "responses": { + "200": { + "description": "successful operation", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Primate" + } + } + } + }, + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Primate not found" + } + } + } + } + }, + "components": { + "schemas": { + "Animal": { + "type": "object", + "properties": { + "born": { + "type": "string", + "description": "Dated Base extension.", + "format": "date-time" + }, + "deceased": { + "type": "string", + "description": "Dated Base extension.", + "format": "date-time" + } + }, + "xml": { + "name": "animal" + } + }, + "Mammal": { + "type": "object", + "allOf": [ { + "$ref": "#/components/schemas/Animal" + } ], + "properties": { + "gender": { + "type": "string", + "enum": [ + "female", + "male" + ] + } + }, + "xml": { + "name": "mammal" + } + }, + "Primate": { + "required": [ + "name" + ], + "type": "object", + "allOf": [ + { + "$ref": "#/components/schemas/Mammal" + } + ], + "properties": { + "id": { + "type": "integer", + "format": "int64", + "example": 10 + }, + "name": { + "type": "string", + "example": "jane doe" + } + }, + "xml": { + "name": "primate" + } + } + } + } +} diff --git a/client/integration-tests/serializable-model/src/main/openapi/quarkus-serializable-openapi.yaml b/client/integration-tests/serializable-model/src/main/openapi/quarkus-serializable-openapi.yaml new file mode 100644 index 000000000..ec431be5e --- /dev/null +++ b/client/integration-tests/serializable-model/src/main/openapi/quarkus-serializable-openapi.yaml @@ -0,0 +1,125 @@ +{ + "openapi": "3.0.2", + "info": { + "title": "Animals - OpenAPI 3.0", + "version": "1.0.5" + }, + "servers": [ + { + "url": "/api/v3" + } + ], + "tags": [ + { + "name": "primate", + "description": "Everything about Primates" + } + ], + "paths": { + "/primate/{id}": { + "get": { + "tags": [ + "primate" + ], + "summary": "Find primate by ID", + "description": "Returns a single primate", + "operationId": "getPrimateById", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "ID of primate to return", + "required": true, + "schema": { + "type": "integer", + "format": "int64" + } + } + ], + "responses": { + "200": { + "description": "successful operation", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Primate" + } + } + } + }, + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Primate not found" + } + } + } + } + }, + "components": { + "schemas": { + "Animal": { + "type": "object", + "properties": { + "born": { + "type": "string", + "description": "Dated Base extension.", + "format": "date-time" + }, + "deceased": { + "type": "string", + "description": "Dated Base extension.", + "format": "date-time" + } + }, + "xml": { + "name": "animal" + } + }, + "Mammal": { + "type": "object", + "allOf": [ { + "$ref": "#/components/schemas/Animal" + } ], + "properties": { + "gender": { + "type": "string", + "enum": [ + "female", + "male" + ] + } + }, + "xml": { + "name": "mammal" + } + }, + "Primate": { + "required": [ + "name" + ], + "type": "object", + "allOf": [ + { + "$ref": "#/components/schemas/Mammal" + } + ], + "properties": { + "id": { + "type": "integer", + "format": "int64", + "example": 10 + }, + "name": { + "type": "string", + "example": "jane doe" + } + }, + "xml": { + "name": "primate" + } + } + } + } +} diff --git a/client/integration-tests/serializable-model/src/main/resources/application.properties b/client/integration-tests/serializable-model/src/main/resources/application.properties new file mode 100644 index 000000000..30fc60530 --- /dev/null +++ b/client/integration-tests/serializable-model/src/main/resources/application.properties @@ -0,0 +1,6 @@ +quarkus.openapi-generator.codegen.spec.quarkus_serializable_openapi_yaml.serializable-model=true +quarkus.openapi-generator.codegen.spec.quarkus_serializable_openapi_yaml.base-package=org.acme.serializable + +quarkus.openapi-generator.codegen.spec.quarkus_non_serializable_openapi_yaml.base-package=org.acme.non.serializable + +quarkus.keycloak.devservices.enabled=false \ No newline at end of file diff --git a/client/integration-tests/serializable-model/src/test/java/io/quarkiverse/openapi/generator/it/SerializableModelTest.java b/client/integration-tests/serializable-model/src/test/java/io/quarkiverse/openapi/generator/it/SerializableModelTest.java new file mode 100644 index 000000000..4f1937c15 --- /dev/null +++ b/client/integration-tests/serializable-model/src/test/java/io/quarkiverse/openapi/generator/it/SerializableModelTest.java @@ -0,0 +1,27 @@ +package io.quarkiverse.openapi.generator.it; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.Serializable; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +class SerializableModelTest { + + @Test + void verifySerializableIsEnabled() { + var interfaces = org.acme.serializable.model.Animal.class.getInterfaces(); + + assertThat(interfaces).contains(Serializable.class); + } + + @Test + void verifySerializableIsNotEnabled() { + var interfaces = org.acme.non.serializable.model.Animal.class.getInterfaces(); + + assertThat(interfaces).doesNotContain(Serializable.class); + } +} diff --git a/docs/modules/ROOT/pages/client.adoc b/docs/modules/ROOT/pages/client.adoc index fa51d0525..7ea4386b0 100644 --- a/docs/modules/ROOT/pages/client.adoc +++ b/docs/modules/ROOT/pages/client.adoc @@ -183,6 +183,17 @@ include::./includes/generate-apis.adoc[leveloffset=+1, opts=optional] include::./includes/generate-models.adoc[leveloffset=+1, opts=optional] +[[generate-serilazble-models]] +== Generate Serilazable Models + +If you need to have the generated models to implement `java.io.Serializable`-interface then set the `serializable-model` +to true: + +[source,properties] +---- +quarkus.openapi-generator.codegen.spec.my_openapi_yaml.serializable-model=true +---- + == Known Limitations === Supported Arguments