Skip to content

Commit 111931d

Browse files
cmoine-swimcruzdev
authored andcommitted
Hook OpenApi2JaxRs to expose the generateBuilders option
1 parent 756dc51 commit 111931d

File tree

9 files changed

+1415
-5
lines changed

9 files changed

+1415
-5
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public interface CodegenConfig extends ServerCodegenConfig {
1313
String CODEGEN_SPEC = CODEGEN_TIME_CONFIG_PREFIX + ".spec";
1414
String INPUT_BASE_DIR = CODEGEN_TIME_CONFIG_PREFIX + ".input-base-dir";
1515
String CODEGEN_REACTIVE = CODEGEN_TIME_CONFIG_PREFIX + ".reactive";
16+
String GENERATE_BUILDERS = CODEGEN_TIME_CONFIG_PREFIX + ".builders";
1617

1718
static String getBasePackagePropertyName() {
1819
return CODEGEN_BASE_PACKAGE;
@@ -29,4 +30,8 @@ static String getInputBaseDirPropertyName() {
2930
static String getCodegenReactive() {
3031
return CODEGEN_REACTIVE;
3132
}
33+
34+
static String getGenerateBuilders() {
35+
return GENERATE_BUILDERS;
36+
}
3237
}

server/deployment/src/main/java/io/quarkiverse/openapi/server/generator/deployment/ServerCodegenConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public interface ServerCodegenConfig {
2626
@WithDefault("false")
2727
boolean reactive();
2828

29+
/**
30+
* Whether it must generate builders for properties.
31+
*/
32+
@WithDefault("false")
33+
boolean builders();
34+
2935
/**
3036
* The base package to be used to generated sources.
3137
*/

server/deployment/src/main/java/io/quarkiverse/openapi/server/generator/deployment/codegen/ApicurioCodegenWrapper.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class ApicurioCodegenWrapper {
2828

2929
private static final Logger log = LoggerFactory.getLogger(ApicurioCodegenWrapper.class);
3030

31+
private final Config config;
3132
private final File outdir;
3233
private final JaxRsProjectSettings projectSettings;
3334

@@ -36,10 +37,11 @@ public ApicurioCodegenWrapper(Config config, File outdir) {
3637
}
3738

3839
public ApicurioCodegenWrapper(Config config, File outdir, JaxRsProjectSettings projectSettings) {
40+
this.config = config;
3941
this.outdir = outdir;
4042
this.projectSettings = projectSettings;
41-
this.projectSettings.setJavaPackage(getBasePackage(config));
42-
this.projectSettings.setReactive(getReactiveValue(config));
43+
this.projectSettings.setJavaPackage(getBasePackage());
44+
this.projectSettings.setReactive(getReactiveValue());
4345
}
4446

4547
public void generate(Path openApiResource) throws CodeGenException {
@@ -61,7 +63,11 @@ public void generate(Path openApiResource) throws CodeGenException {
6163

6264
try (FileOutputStream fos = new FileOutputStream(zipFile);
6365
FileInputStream openApiStream = new FileInputStream(openApiFile)) {
64-
OpenApi2JaxRs generator = new OpenApi2JaxRs();
66+
OpenApi2JaxRs generator = new OpenApi2JaxRs() {
67+
{
68+
config = new ConfigurableGenerationConfig(ApicurioCodegenWrapper.this.config);
69+
}
70+
};
6571
generator.setSettings(projectSettings);
6672
generator.setUpdateOnly(true);
6773
generator.setOpenApiDocument(openApiStream);
@@ -106,13 +112,13 @@ private void unzip(File fromZipFile, File toOutputDir) throws IOException {
106112
}
107113
}
108114

109-
private String getBasePackage(final Config config) {
115+
private String getBasePackage() {
110116
return config
111117
.getOptionalValue(getBasePackagePropertyName(), String.class)
112118
.orElse(DEFAULT_PACKAGE);
113119
}
114120

115-
private Boolean getReactiveValue(final Config config) {
121+
private Boolean getReactiveValue() {
116122
return config
117123
.getOptionalValue(getCodegenReactive(), Boolean.class)
118124
.orElse(Boolean.FALSE);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.quarkiverse.openapi.server.generator.deployment.codegen;
2+
3+
import org.eclipse.microprofile.config.Config;
4+
import org.jsonschema2pojo.DefaultGenerationConfig;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
8+
import io.quarkiverse.openapi.server.generator.deployment.CodegenConfig;
9+
10+
public class ConfigurableGenerationConfig extends DefaultGenerationConfig {
11+
12+
private static final Logger log = LoggerFactory.getLogger(ConfigurableGenerationConfig.class);
13+
14+
private final boolean generateBuilders;
15+
16+
public ConfigurableGenerationConfig(Config config) {
17+
generateBuilders = config
18+
.getOptionalValue(CodegenConfig.getGenerateBuilders(), Boolean.class)
19+
.orElse(Boolean.FALSE);
20+
log.debug("generateBuilders={}", generateBuilders);
21+
}
22+
23+
@Override
24+
public boolean isGenerateBuilders() {
25+
return generateBuilders;
26+
}
27+
28+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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-server-integration-tests-parent</artifactId>
5+
<groupId>io.quarkiverse.openapi.generator</groupId>
6+
<version>3.0.0-SNAPSHOT</version>
7+
<relativePath>../pom.xml</relativePath>
8+
</parent>
9+
<modelVersion>4.0.0</modelVersion>
10+
11+
<artifactId>quarkus-openapi-generator-server-integration-tests-builders</artifactId>
12+
<name>Quarkus - OpenAPI Generator - Server - Integration Tests - Builders</name>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>io.quarkus</groupId>
17+
<artifactId>quarkus-undertow</artifactId>
18+
</dependency>
19+
<dependency>
20+
<groupId>io.quarkus</groupId>
21+
<artifactId>quarkus-resteasy</artifactId>
22+
</dependency>
23+
<dependency>
24+
<groupId>io.quarkus</groupId>
25+
<artifactId>quarkus-resteasy-jackson</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>io.quarkiverse.openapi.generator</groupId>
29+
<artifactId>quarkus-openapi-generator-server</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>io.quarkus</groupId>
33+
<artifactId>quarkus-junit5</artifactId>
34+
<scope>test</scope>
35+
</dependency>
36+
<dependency>
37+
<groupId>io.quarkus</groupId>
38+
<artifactId>quarkus-test-common</artifactId>
39+
<scope>test</scope>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.junit.jupiter</groupId>
43+
<artifactId>junit-jupiter</artifactId>
44+
<scope>test</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>io.rest-assured</groupId>
48+
<artifactId>rest-assured</artifactId>
49+
<scope>test</scope>
50+
</dependency>
51+
<dependency>
52+
<groupId>io.quarkus</groupId>
53+
<artifactId>quarkus-smallrye-openapi</artifactId>
54+
</dependency>
55+
</dependencies>
56+
57+
<build>
58+
<pluginManagement>
59+
<plugins>
60+
<plugin>
61+
<groupId>io.quarkus</groupId>
62+
<artifactId>quarkus-maven-plugin</artifactId>
63+
<version>${quarkus.version}</version>
64+
</plugin>
65+
<plugin>
66+
<artifactId>maven-surefire-plugin</artifactId>
67+
<version>${version.surefire.plugin}</version>
68+
<configuration>
69+
<systemPropertyVariables>
70+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
71+
<maven.home>${maven.home}</maven.home>
72+
<maven.repo>${settings.localRepository}</maven.repo>
73+
</systemPropertyVariables>
74+
</configuration>
75+
</plugin>
76+
<plugin>
77+
<artifactId>maven-failsafe-plugin</artifactId>
78+
<version>${failsafe-plugin.version}</version>
79+
<configuration>
80+
<systemPropertyVariables>
81+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
82+
<maven.home>${maven.home}</maven.home>
83+
<maven.repo>${settings.localRepository}</maven.repo>
84+
</systemPropertyVariables>
85+
</configuration>
86+
</plugin>
87+
<plugin>
88+
<artifactId>maven-compiler-plugin</artifactId>
89+
<version>${compiler-plugin.version}</version>
90+
<configuration>
91+
<compilerArgs>
92+
<arg>-parameters</arg>
93+
</compilerArgs>
94+
</configuration>
95+
</plugin>
96+
</plugins>
97+
</pluginManagement>
98+
<plugins>
99+
<plugin>
100+
<groupId>io.quarkus</groupId>
101+
<artifactId>quarkus-maven-plugin</artifactId>
102+
<executions>
103+
<execution>
104+
<goals>
105+
<goal>build</goal>
106+
<goal>generate-code</goal>
107+
</goals>
108+
</execution>
109+
</executions>
110+
</plugin>
111+
</plugins>
112+
</build>
113+
</project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Codegen properties
2+
quarkus.openapi.generator.spec=petstore-openapi.json
3+
quarkus.openapi.generator.base-package=io.petstore
4+
quarkus.openapi.generator.reactive=false
5+
quarkus.openapi.generator.builders=true

0 commit comments

Comments
 (0)