Skip to content

Commit bc4fd03

Browse files
committed
Exposed the serializable-model when generating client models.
1 parent 7634262 commit bc4fd03

File tree

11 files changed

+459
-59
lines changed

11 files changed

+459
-59
lines changed

client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CodegenConfig.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package io.quarkiverse.openapi.generator.deployment;
22

3-
import java.nio.file.Path;
4-
import java.util.Arrays;
5-
import java.util.List;
6-
import java.util.Map;
7-
import java.util.stream.Collectors;
8-
93
import io.quarkiverse.openapi.generator.deployment.codegen.OpenApiGeneratorOutputPaths;
104
import io.quarkus.runtime.annotations.ConfigItem;
115
import io.quarkus.runtime.annotations.ConfigPhase;
126
import io.quarkus.runtime.annotations.ConfigRoot;
137
import io.smallrye.config.common.utils.StringUtil;
148

9+
import java.nio.file.Path;
10+
import java.util.Arrays;
11+
import java.util.List;
12+
import java.util.Map;
13+
import java.util.stream.Collectors;
14+
1515
// This configuration is read in codegen phase (before build time), the annotation is for document purposes and avoiding quarkus warns
1616
@ConfigRoot(name = CodegenConfig.CODEGEN_TIME_CONFIG_PREFIX, phase = ConfigPhase.BUILD_TIME)
1717
public class CodegenConfig extends GlobalCodegenConfig {
@@ -73,7 +73,8 @@ public enum ConfigName {
7373
REMOVE_OPERATION_ID_PREFIX_COUNT("remove-operation-id-prefix-count"),
7474
GENERATE_APIS("generate-apis"),
7575
GENERATE_MODELS("generate-models"),
76-
BEAN_VALIDATION("use-bean-validation");
76+
BEAN_VALIDATION("use-bean-validation"),
77+
SERIALIZABLE_MODEL("serializable-model");
7778

7879
private final String name;
7980

client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/codegen/OpenApiGeneratorCodeGenBase.java

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,5 @@
11
package io.quarkiverse.openapi.generator.deployment.codegen;
22

3-
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_NAME_DEFAULT;
4-
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_STRING_VALUE_DEFAULT;
5-
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.getGlobalConfigName;
6-
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.getSanitizedFileName;
7-
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.getSpecConfigName;
8-
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.API_NAME_SUFFIX;
9-
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.BASE_PACKAGE;
10-
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.DEFAULT_SECURITY_SCHEME;
11-
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.EXCLUDE;
12-
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.INCLUDE;
13-
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.INPUT_BASE_DIR;
14-
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.MODEL_NAME_PREFIX;
15-
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.MODEL_NAME_SUFFIX;
16-
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.REMOVE_OPERATION_ID_PREFIX;
17-
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.REMOVE_OPERATION_ID_PREFIX_COUNT;
18-
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.REMOVE_OPERATION_ID_PREFIX_DELIMITER;
19-
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.TEMPLATE_BASE_DIR;
20-
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.VALIDATE_SPEC;
21-
22-
import java.io.IOException;
23-
import java.nio.file.Files;
24-
import java.nio.file.Path;
25-
import java.util.List;
26-
import java.util.Map;
27-
import java.util.Optional;
28-
import java.util.function.Predicate;
29-
import java.util.stream.Collectors;
30-
import java.util.stream.Stream;
31-
import java.util.stream.StreamSupport;
32-
33-
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
34-
import org.eclipse.microprofile.config.Config;
35-
import org.openapitools.codegen.config.GlobalSettings;
36-
373
import io.quarkiverse.openapi.generator.deployment.CodegenConfig;
384
import io.quarkiverse.openapi.generator.deployment.OpenApiGeneratorOptions;
395
import io.quarkiverse.openapi.generator.deployment.circuitbreaker.CircuitBreakerConfigurationParser;
@@ -46,6 +12,23 @@
4612
import io.quarkus.deployment.CodeGenContext;
4713
import io.quarkus.deployment.CodeGenProvider;
4814
import io.smallrye.config.SmallRyeConfig;
15+
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
16+
import org.eclipse.microprofile.config.Config;
17+
import org.openapitools.codegen.config.GlobalSettings;
18+
19+
import java.io.IOException;
20+
import java.nio.file.Files;
21+
import java.nio.file.Path;
22+
import java.util.List;
23+
import java.util.Map;
24+
import java.util.Optional;
25+
import java.util.function.Predicate;
26+
import java.util.stream.Collectors;
27+
import java.util.stream.Stream;
28+
import java.util.stream.StreamSupport;
29+
30+
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.*;
31+
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.*;
4932

5033
/**
5134
* Code generation for OpenApi Client. Generates Java classes from OpenApi spec files located in src/main/openapi or
@@ -317,6 +300,9 @@ protected void generate(OpenApiGeneratorOptions options) {
317300
getValues(smallRyeConfig, openApiFilePath, CodegenConfig.ConfigName.SCHEMA_MAPPINGS, String.class, String.class)
318301
.ifPresent(generator::withSchemaMappings);
319302

303+
getValues(smallRyeConfig, openApiFilePath, CodegenConfig.ConfigName.SERIALIZABLE_MODEL, String.class)
304+
.ifPresent(generator::withSerialiableModel);
305+
320306
getValues(smallRyeConfig, openApiFilePath, CodegenConfig.ConfigName.NORMALIZER, String.class, String.class)
321307
.ifPresent(generator::withOpenApiNormalizer);
322308

client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/wrapper/OpenApiClientGeneratorWrapper.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
package io.quarkiverse.openapi.generator.deployment.wrapper;
22

3-
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.getSanitizedFileName;
4-
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.resolveApiPackage;
5-
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.resolveModelPackage;
3+
import io.smallrye.config.common.utils.StringUtil;
4+
import org.openapitools.codegen.CodegenConstants;
5+
import org.openapitools.codegen.DefaultGenerator;
6+
import org.openapitools.codegen.config.GlobalSettings;
7+
8+
import java.io.File;
9+
import java.nio.file.Path;
10+
import java.util.*;
11+
12+
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.*;
613
import static io.quarkiverse.openapi.generator.deployment.wrapper.QuarkusJavaClientCodegen.QUARKUS_GENERATOR_NAME;
714
import static java.lang.Boolean.FALSE;
815
import static java.lang.Boolean.TRUE;
916
import static java.util.Objects.requireNonNull;
1017
import static org.openapitools.codegen.languages.AbstractJavaCodegen.ADDITIONAL_MODEL_TYPE_ANNOTATIONS;
1118

12-
import java.io.File;
13-
import java.nio.file.Path;
14-
import java.util.Collections;
15-
import java.util.HashMap;
16-
import java.util.List;
17-
import java.util.Map;
18-
import java.util.Optional;
19-
20-
import org.openapitools.codegen.CodegenConstants;
21-
import org.openapitools.codegen.DefaultGenerator;
22-
import org.openapitools.codegen.config.GlobalSettings;
23-
24-
import io.smallrye.config.common.utils.StringUtil;
25-
2619
/**
2720
* Wrapper for the OpenAPIGen tool.
2821
* This is the same as calling the Maven plugin or the CLI.
@@ -111,7 +104,6 @@ private void setDefaults() {
111104
this.configurator.addAdditionalProperty("use-bean-validation", FALSE);
112105
this.configurator.addAdditionalProperty("use-field-name-in-part-filename", FALSE);
113106
this.configurator.addAdditionalProperty("verbose", FALSE);
114-
// TODO: expose as properties https://github.com/quarkiverse/quarkus-openapi-generator/issues/869
115107
this.configurator.addAdditionalProperty(CodegenConstants.SERIALIZABLE_MODEL, FALSE);
116108
}
117109

@@ -198,6 +190,11 @@ public OpenApiClientGeneratorWrapper withOpenApiNormalizer(final Map<String, Str
198190
return this;
199191
}
200192

193+
public OpenApiClientGeneratorWrapper withSerialiableModel(final String serialiableModel) {
194+
this.configurator.addAdditionalProperty(CodegenConstants.SERIALIZABLE_MODEL, serialiableModel);
195+
return this;
196+
}
197+
201198
/**
202199
* Sets the global 'additionalModelTypeAnnotations' setting. If not set this setting will default to empty.
203200
*

client/integration-tests/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<module>config-key</module>
4545
<module>github</module>
4646
<module>without-oidc</module>
47+
<module>serializable-model</module>
4748
</modules>
4849
<dependencyManagement>
4950
<dependencies>
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<parent>
5+
<artifactId>quarkus-openapi-generator-integration-tests</artifactId>
6+
<groupId>io.quarkiverse.openapi.generator</groupId>
7+
<version>3.0.0-SNAPSHOT</version>
8+
</parent>
9+
<modelVersion>4.0.0</modelVersion>
10+
11+
<artifactId>quarkus-openapi-generator-it-serializable-model</artifactId>
12+
<name>Quarkus - Openapi Generator - Integration Tests - Client - Serializable model</name>
13+
<description>Example project for general usage</description>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>io.quarkiverse.openapi.generator</groupId>
18+
<artifactId>quarkus-openapi-generator</artifactId>
19+
</dependency>
20+
<dependency>
21+
<groupId>org.assertj</groupId>
22+
<artifactId>assertj-core</artifactId>
23+
<scope>test</scope>
24+
</dependency>
25+
<dependency>
26+
<groupId>io.quarkus</groupId>
27+
<artifactId>quarkus-junit5</artifactId>
28+
<scope>test</scope>
29+
</dependency>
30+
</dependencies>
31+
<build>
32+
<plugins>
33+
<plugin>
34+
<groupId>io.quarkus</groupId>
35+
<artifactId>quarkus-maven-plugin</artifactId>
36+
<extensions>true</extensions>
37+
<executions>
38+
<execution>
39+
<goals>
40+
<goal>build</goal>
41+
<goal>generate-code</goal>
42+
<goal>generate-code-tests</goal>
43+
</goals>
44+
</execution>
45+
</executions>
46+
</plugin>
47+
</plugins>
48+
</build>
49+
<profiles>
50+
<profile>
51+
<id>native-image</id>
52+
<activation>
53+
<property>
54+
<name>native</name>
55+
</property>
56+
</activation>
57+
<build>
58+
<plugins>
59+
<plugin>
60+
<artifactId>maven-surefire-plugin</artifactId>
61+
<configuration>
62+
<skipTests>${native.surefire.skip}</skipTests>
63+
</configuration>
64+
</plugin>
65+
<plugin>
66+
<artifactId>maven-failsafe-plugin</artifactId>
67+
<executions>
68+
<execution>
69+
<goals>
70+
<goal>integration-test</goal>
71+
<goal>verify</goal>
72+
</goals>
73+
<configuration>
74+
<systemPropertyVariables>
75+
<native.image.path>
76+
${project.build.directory}/${project.build.finalName}-runner
77+
</native.image.path>
78+
<java.util.logging.manager>org.jboss.logmanager.LogManager
79+
</java.util.logging.manager>
80+
<maven.home>${maven.home}</maven.home>
81+
</systemPropertyVariables>
82+
</configuration>
83+
</execution>
84+
</executions>
85+
</plugin>
86+
</plugins>
87+
</build>
88+
<properties>
89+
<quarkus.package.type>native</quarkus.package.type>
90+
</properties>
91+
</profile>
92+
</profiles>
93+
94+
</project>
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
{
2+
"openapi": "3.0.2",
3+
"info": {
4+
"title": "Animals - OpenAPI 3.0",
5+
"version": "1.0.5"
6+
},
7+
"servers": [
8+
{
9+
"url": "/api/v3"
10+
}
11+
],
12+
"tags": [
13+
{
14+
"name": "primate",
15+
"description": "Everything about Primates"
16+
}
17+
],
18+
"paths": {
19+
"/primate/{id}": {
20+
"get": {
21+
"tags": [
22+
"primate"
23+
],
24+
"summary": "Find primate by ID",
25+
"description": "Returns a single primate",
26+
"operationId": "getPrimateById",
27+
"parameters": [
28+
{
29+
"name": "id",
30+
"in": "path",
31+
"description": "ID of primate to return",
32+
"required": true,
33+
"schema": {
34+
"type": "integer",
35+
"format": "int64"
36+
}
37+
}
38+
],
39+
"responses": {
40+
"200": {
41+
"description": "successful operation",
42+
"content": {
43+
"application/json": {
44+
"schema": {
45+
"$ref": "#/components/schemas/Primate"
46+
}
47+
}
48+
}
49+
},
50+
"400": {
51+
"description": "Invalid ID supplied"
52+
},
53+
"404": {
54+
"description": "Primate not found"
55+
}
56+
}
57+
}
58+
}
59+
},
60+
"components": {
61+
"schemas": {
62+
"Animal": {
63+
"type": "object",
64+
"properties": {
65+
"born": {
66+
"type": "string",
67+
"description": "Dated Base extension.",
68+
"format": "date-time"
69+
},
70+
"deceased": {
71+
"type": "string",
72+
"description": "Dated Base extension.",
73+
"format": "date-time"
74+
}
75+
},
76+
"xml": {
77+
"name": "animal"
78+
}
79+
},
80+
"Mammal": {
81+
"type": "object",
82+
"allOf": [ {
83+
"$ref": "#/components/schemas/Animal"
84+
} ],
85+
"properties": {
86+
"gender": {
87+
"type": "string",
88+
"enum": [
89+
"female",
90+
"male"
91+
]
92+
}
93+
},
94+
"xml": {
95+
"name": "mammal"
96+
}
97+
},
98+
"Primate": {
99+
"required": [
100+
"name"
101+
],
102+
"type": "object",
103+
"allOf": [
104+
{
105+
"$ref": "#/components/schemas/Mammal"
106+
}
107+
],
108+
"properties": {
109+
"id": {
110+
"type": "integer",
111+
"format": "int64",
112+
"example": 10
113+
},
114+
"name": {
115+
"type": "string",
116+
"example": "jane doe"
117+
}
118+
},
119+
"xml": {
120+
"name": "primate"
121+
}
122+
}
123+
}
124+
}
125+
}

0 commit comments

Comments
 (0)