Skip to content

Commit

Permalink
Exposed the serializable-model when generating client models. (#907)
Browse files Browse the repository at this point in the history
  • Loading branch information
denvitaharen authored Dec 12, 2024
1 parent 1c0a5a4 commit 12825ee
Show file tree
Hide file tree
Showing 10 changed files with 399 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -198,6 +197,11 @@ public OpenApiClientGeneratorWrapper withOpenApiNormalizer(final Map<String, Str
return this;
}

public OpenApiClientGeneratorWrapper withSerialiableModel(final Boolean serialiableModel) {
this.configurator.addAdditionalProperty(CodegenConstants.SERIALIZABLE_MODEL, serialiableModel);
return this;
}

/**
* Sets the global 'additionalModelTypeAnnotations' setting. If not set this setting will default to empty.
*
Expand Down
1 change: 1 addition & 0 deletions client/integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<module>config-key</module>
<module>github</module>
<module>without-oidc</module>
<module>serializable-model</module>
</modules>
<dependencyManagement>
<dependencies>
Expand Down
94 changes: 94 additions & 0 deletions client/integration-tests/serializable-model/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-openapi-generator-integration-tests</artifactId>
<groupId>io.quarkiverse.openapi.generator</groupId>
<version>3.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-openapi-generator-it-serializable-model</artifactId>
<name>Quarkus - Openapi Generator - Integration Tests - Client - Serializable model</name>
<description>Example project for general usage</description>

<dependencies>
<dependency>
<groupId>io.quarkiverse.openapi.generator</groupId>
<artifactId>quarkus-openapi-generator</artifactId>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>build</goal>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native-image</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${native.surefire.skip}</skipTests>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<native.image.path>
${project.build.directory}/${project.build.finalName}-runner
</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager
</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
}
Loading

0 comments on commit 12825ee

Please sign in to comment.