Skip to content

Commit 22014a2

Browse files
Exposed the serializable-model when generating client models. (#907) (#910)
Co-authored-by: Richard Alm <[email protected]>
1 parent 789f3bb commit 22014a2

File tree

10 files changed

+399
-2
lines changed

10 files changed

+399
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ protected void generate(OpenApiGeneratorOptions options) {
317317
getValues(smallRyeConfig, openApiFilePath, CodegenConfig.ConfigName.SCHEMA_MAPPINGS, String.class, String.class)
318318
.ifPresent(generator::withSchemaMappings);
319319

320+
getValues(smallRyeConfig, openApiFilePath, CodegenConfig.ConfigName.SERIALIZABLE_MODEL, Boolean.class)
321+
.ifPresent(generator::withSerialiableModel);
322+
320323
getValues(smallRyeConfig, openApiFilePath, CodegenConfig.ConfigName.NORMALIZER, String.class, String.class)
321324
.ifPresent(generator::withOpenApiNormalizer);
322325

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ private void setDefaults() {
111111
this.configurator.addAdditionalProperty("use-bean-validation", FALSE);
112112
this.configurator.addAdditionalProperty("use-field-name-in-part-filename", FALSE);
113113
this.configurator.addAdditionalProperty("verbose", FALSE);
114-
// TODO: expose as properties https://github.com/quarkiverse/quarkus-openapi-generator/issues/869
115114
this.configurator.addAdditionalProperty(CodegenConstants.SERIALIZABLE_MODEL, FALSE);
116115
}
117116

@@ -198,6 +197,11 @@ public OpenApiClientGeneratorWrapper withOpenApiNormalizer(final Map<String, Str
198197
return this;
199198
}
200199

200+
public OpenApiClientGeneratorWrapper withSerialiableModel(final Boolean serialiableModel) {
201+
this.configurator.addAdditionalProperty(CodegenConstants.SERIALIZABLE_MODEL, serialiableModel);
202+
return this;
203+
}
204+
201205
/**
202206
* Sets the global 'additionalModelTypeAnnotations' setting. If not set this setting will default to empty.
203207
*

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+
}
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)