Skip to content

Commit 561abbe

Browse files
Andy Barillaandybarilla
authored andcommitted
Add generatemodels and generateapis options
1 parent e230b96 commit 561abbe

File tree

15 files changed

+321
-4
lines changed

15 files changed

+321
-4
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ public enum ConfigName {
6767
USE_FIELD_NAME_IN_PART_FILENAME("use-field-name-in-part-filename"),
6868
ADDITIONAL_PROPERTIES_AS_ATTRIBUTE("additional-properties-as-attribute"),
6969
ADDITIONAL_REQUEST_ARGS("additional-request-args"),
70-
BEAN_VALIDATION("use-bean-validation");
70+
BEAN_VALIDATION("use-bean-validation"),
71+
GENERATE_APIS("generate-apis"),
72+
GENERATE_MODELS("generate-models");
7173

7274
private final String name;
7375

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
@@ -153,4 +153,16 @@ public class CommonItemConfig {
153153
*/
154154
@ConfigItem(name = "use-bean-validation")
155155
public Optional<Boolean> useBeanValidation;
156+
157+
/**
158+
* Enable the generation of APIs. If you set this to {@code false}, APIs will not be generated.
159+
*/
160+
@ConfigItem(name = "generate-apis")
161+
public Optional<Boolean> generateApis;
162+
163+
/**
164+
* Enable the generation of models. If you set this to {@code false}, models will not be generated.
165+
*/
166+
@ConfigItem(name = "generate-models")
167+
public Optional<Boolean> generateModels;
156168
}

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
@@ -288,6 +288,12 @@ protected void generate(OpenApiGeneratorOptions options) {
288288
getValues(config, openApiFilePath, CodegenConfig.ConfigName.BEAN_VALIDATION, Boolean.class)
289289
.ifPresent(generator::withUseBeanValidation);
290290

291+
getValues(config, openApiFilePath, CodegenConfig.ConfigName.GENERATE_APIS, Boolean.class)
292+
.ifPresent(generator::withGenerateApis);
293+
294+
getValues(config, openApiFilePath, CodegenConfig.ConfigName.GENERATE_MODELS, Boolean.class)
295+
.ifPresent(generator::withGenerateModels);
296+
291297
SmallRyeConfig smallRyeConfig = config.unwrap(SmallRyeConfig.class);
292298

293299
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
@@ -270,6 +270,16 @@ public OpenApiClientGeneratorWrapper withUseBeanValidation(Boolean config) {
270270
return this;
271271
}
272272

273+
public OpenApiClientGeneratorWrapper withGenerateApis(Boolean config) {
274+
configurator.addAdditionalProperty("generate-apis", config);
275+
return this;
276+
}
277+
278+
public OpenApiClientGeneratorWrapper withGenerateModels(Boolean config) {
279+
configurator.addAdditionalProperty("generate-models", config);
280+
return this;
281+
}
282+
273283
public OpenApiClientGeneratorWrapper withApiNameSuffix(final String apiNameSuffix) {
274284
this.configurator.setApiNameSuffix(apiNameSuffix);
275285
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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ 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",
22+
"quarkus.openapi-generator.codegen.spec.spec_yaml.generate-apis=false",
23+
"quarkus.openapi-generator.codegen.spec.spec_yaml.generate-models=false",
24+
"quarkus.openapi-generator.codegen.spec.spec_yaml.generate-apis=true",
25+
"quarkus.openapi-generator.codegen.spec.spec_yaml.generate-models=true",
2226
})
2327
void test_known_configs_ok(String validConfiguration) {
2428
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)