Skip to content

Commit cdbc976

Browse files
authored
Add generatemodels and generateapis options (#897)
1 parent 3b91228 commit cdbc976

File tree

15 files changed

+316
-3
lines changed

15 files changed

+316
-3
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public enum ConfigName {
7171
REMOVE_OPERATION_ID_PREFIX("remove-operation-id-prefix"),
7272
REMOVE_OPERATION_ID_PREFIX_DELIMITER("remove-operation-id-prefix-delimiter"),
7373
REMOVE_OPERATION_ID_PREFIX_COUNT("remove-operation-id-prefix-count"),
74+
GENERATE_APIS("generate-apis"),
75+
GENERATE_MODELS("generate-models"),
7476
BEAN_VALIDATION("use-bean-validation");
7577

7678
private final String name;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,16 @@ public class CommonItemConfig {
160160
*/
161161
@ConfigItem(name = "use-bean-validation")
162162
public Optional<Boolean> useBeanValidation;
163+
164+
/**
165+
* Enable the generation of APIs. If you set this to {@code false}, APIs will not be generated.
166+
*/
167+
@ConfigItem(name = "generate-apis")
168+
public Optional<Boolean> generateApis;
169+
170+
/**
171+
* Enable the generation of models. If you set this to {@code false}, models will not be generated.
172+
*/
173+
@ConfigItem(name = "generate-models")
174+
public Optional<Boolean> generateModels;
163175
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,12 @@ protected void generate(OpenApiGeneratorOptions options) {
300300
getValues(config, openApiFilePath, CodegenConfig.ConfigName.BEAN_VALIDATION, Boolean.class)
301301
.ifPresent(generator::withUseBeanValidation);
302302

303+
getValues(config, openApiFilePath, CodegenConfig.ConfigName.GENERATE_APIS, Boolean.class)
304+
.ifPresent(generator::withGenerateApis);
305+
306+
getValues(config, openApiFilePath, CodegenConfig.ConfigName.GENERATE_MODELS, Boolean.class)
307+
.ifPresent(generator::withGenerateModels);
308+
303309
SmallRyeConfig smallRyeConfig = config.unwrap(SmallRyeConfig.class);
304310

305311
getValues(smallRyeConfig, openApiFilePath, CodegenConfig.ConfigName.TYPE_MAPPINGS, String.class, String.class)

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,16 @@ public OpenApiClientGeneratorWrapper withUseBeanValidation(Boolean config) {
275275
return this;
276276
}
277277

278+
public OpenApiClientGeneratorWrapper withGenerateApis(Boolean config) {
279+
configurator.addAdditionalProperty("generate-apis", config);
280+
return this;
281+
}
282+
283+
public OpenApiClientGeneratorWrapper withGenerateModels(Boolean config) {
284+
configurator.addAdditionalProperty("generate-models", config);
285+
return this;
286+
}
287+
278288
public OpenApiClientGeneratorWrapper withApiNameSuffix(final String apiNameSuffix) {
279289
this.configurator.setApiNameSuffix(apiNameSuffix);
280290
return this;

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ private void replaceWithQuarkusTemplateFiles() {
7070
supportingFiles.clear();
7171

7272
Boolean enableSecurityGeneration = (Boolean) this.additionalProperties.get("enable-security-generation");
73+
Boolean generateApis = (Boolean) this.additionalProperties.getOrDefault("generate-apis", Boolean.TRUE);
74+
Boolean generateModels = (Boolean) this.additionalProperties.getOrDefault("generate-models", Boolean.TRUE);
7375

7476
if (enableSecurityGeneration == null || enableSecurityGeneration) {
7577
if (ProcessUtils.hasHttpBasicMethods(this.openAPI) ||
@@ -92,10 +94,14 @@ private void replaceWithQuarkusTemplateFiles() {
9294
}
9395

9496
apiTemplateFiles.clear();
95-
apiTemplateFiles.put("api.qute", ".java");
97+
if (generateApis) {
98+
apiTemplateFiles.put("api.qute", ".java");
99+
}
96100

97101
modelTemplateFiles.clear();
98-
modelTemplateFiles.put("model.qute", ".java");
102+
if (generateModels) {
103+
modelTemplateFiles.put("model.qute", ".java");
104+
}
99105
}
100106

101107
public String authFileFolder() {

client/deployment/src/test/java/io/quarkiverse/openapi/generator/deployment/OpenApiConfigValidatorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class OpenApiConfigValidatorTest {
1818
"quarkus.openapi-generator.codegen.additional-api-type-annotations",
1919
"quarkus.openapi-generator.codegen.spec.spec_yaml.enable-security-generation",
2020
"quarkus.openapi-generator.codegen.type-mappings.UUID=String",
21-
"quarkus.openapi-generator.codegen.spec.spec_yaml.type-mappings.UUID=String"
21+
"quarkus.openapi-generator.codegen.spec.spec_yaml.type-mappings.UUID=String",
2222
})
2323
void test_known_configs_ok(String validConfiguration) {
2424
assertThatCode(() -> OpenApiConfigValidator.validateInputConfiguration(List.of(validConfiguration)))
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<parent>
4+
<artifactId>quarkus-openapi-generator-integration-tests</artifactId>
5+
<groupId>io.quarkiverse.openapi.generator</groupId>
6+
<version>3.0.0-SNAPSHOT</version>
7+
</parent>
8+
<modelVersion>4.0.0</modelVersion>
9+
10+
<artifactId>quarkus-openapi-generator-it-generate-flags</artifactId>
11+
<name>Quarkus - Openapi Generator - Integration Tests - Client - Generate Flags</name>
12+
<description>Example project for usage of the generate-models and generate-apis properties</description>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>io.quarkiverse.openapi.generator</groupId>
17+
<artifactId>quarkus-openapi-generator</artifactId>
18+
</dependency>
19+
<dependency>
20+
<groupId>org.assertj</groupId>
21+
<artifactId>assertj-core</artifactId>
22+
<scope>test</scope>
23+
</dependency>
24+
<dependency>
25+
<groupId>io.quarkus</groupId>
26+
<artifactId>quarkus-junit5</artifactId>
27+
<scope>test</scope>
28+
</dependency>
29+
<dependency>
30+
<groupId>io.quarkus</groupId>
31+
<artifactId>quarkus-hibernate-validator</artifactId>
32+
</dependency>
33+
</dependencies>
34+
<build>
35+
<plugins>
36+
<plugin>
37+
<groupId>io.quarkus</groupId>
38+
<artifactId>quarkus-maven-plugin</artifactId>
39+
<extensions>true</extensions>
40+
<executions>
41+
<execution>
42+
<goals>
43+
<goal>build</goal>
44+
<goal>generate-code</goal>
45+
<goal>generate-code-tests</goal>
46+
</goals>
47+
</execution>
48+
</executions>
49+
</plugin>
50+
</plugins>
51+
</build>
52+
<profiles>
53+
<profile>
54+
<id>native-image</id>
55+
<activation>
56+
<property>
57+
<name>native</name>
58+
</property>
59+
</activation>
60+
<build>
61+
<plugins>
62+
<plugin>
63+
<artifactId>maven-surefire-plugin</artifactId>
64+
<configuration>
65+
<skipTests>${native.surefire.skip}</skipTests>
66+
</configuration>
67+
</plugin>
68+
<plugin>
69+
<artifactId>maven-failsafe-plugin</artifactId>
70+
<executions>
71+
<execution>
72+
<goals>
73+
<goal>integration-test</goal>
74+
<goal>verify</goal>
75+
</goals>
76+
<configuration>
77+
<systemPropertyVariables>
78+
<native.image.path>
79+
${project.build.directory}/${project.build.finalName}-runner
80+
</native.image.path>
81+
<java.util.logging.manager>org.jboss.logmanager.LogManager
82+
</java.util.logging.manager>
83+
<maven.home>${maven.home}</maven.home>
84+
</systemPropertyVariables>
85+
</configuration>
86+
</execution>
87+
</executions>
88+
</plugin>
89+
</plugins>
90+
</build>
91+
<properties>
92+
<quarkus.package.type>native</quarkus.package.type>
93+
</properties>
94+
</profile>
95+
</profiles>
96+
97+
</project>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
openapi: 3.0.3
3+
info:
4+
title: Test API
5+
version: "1.0"
6+
paths:
7+
/{pathParam}:
8+
get:
9+
tags:
10+
- NonExistentEndpoint
11+
operationId: test
12+
parameters:
13+
- name: pathParam
14+
in: path
15+
required: true
16+
schema:
17+
type: string
18+
minimum: 5
19+
- name: headerParam
20+
in: header
21+
required: false
22+
schema:
23+
type: integer
24+
maximum: 5
25+
- name: cookieParam
26+
in: cookie
27+
required: true
28+
schema:
29+
type: string
30+
minLength: 10
31+
responses:
32+
"200":
33+
description: OK
34+
content:
35+
text/plain:
36+
schema:
37+
type: string
38+
components:
39+
schemas:
40+
ExistentObject:
41+
type: object
42+
description: Some object not to be validated
43+
required:
44+
- id
45+
- name
46+
- size
47+
properties:
48+
id:
49+
type: integer
50+
minimum: 1
51+
maximum: 100
52+
name:
53+
type: string
54+
pattern: "[a-zA-Z]*"
55+
minLength: 1
56+
maxLength: 10
57+
size:
58+
type: number
59+
minimum: 1.0
60+
maximum: 10.0
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
openapi: 3.0.3
3+
info:
4+
title: Test API
5+
version: "1.0"
6+
paths:
7+
/{pathParam}:
8+
get:
9+
tags:
10+
- ExistentEndpoint
11+
operationId: test
12+
parameters:
13+
- name: pathParam
14+
in: path
15+
required: true
16+
schema:
17+
type: string
18+
minimum: 5
19+
- name: headerParam
20+
in: header
21+
required: false
22+
schema:
23+
type: integer
24+
maximum: 5
25+
- name: cookieParam
26+
in: cookie
27+
required: true
28+
schema:
29+
type: string
30+
minLength: 10
31+
responses:
32+
"200":
33+
description: OK
34+
content:
35+
text/plain:
36+
schema:
37+
type: string
38+
components:
39+
schemas:
40+
NonExistentObject:
41+
type: object
42+
description: Some object not to be validated
43+
required:
44+
- id
45+
- name
46+
- size
47+
properties:
48+
id:
49+
type: integer
50+
minimum: 1
51+
maximum: 100
52+
name:
53+
type: string
54+
pattern: "[a-zA-Z]*"
55+
minLength: 1
56+
maxLength: 10
57+
size:
58+
type: number
59+
minimum: 1.0
60+
maximum: 10.0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
quarkus.openapi-generator.codegen.spec.generate_models_false_yaml.generate-models = false
2+
quarkus.openapi-generator.codegen.spec.generate_apis_false_yaml.generate-apis = false

0 commit comments

Comments
 (0)