Skip to content

[main-lts] Generate Builder methods on Beans #1230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 24, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public interface CodegenConfig extends ServerCodegenConfig {
String CODEGEN_SPEC = CODEGEN_TIME_CONFIG_PREFIX + ".spec";
String INPUT_BASE_DIR = CODEGEN_TIME_CONFIG_PREFIX + ".input-base-dir";
String CODEGEN_REACTIVE = CODEGEN_TIME_CONFIG_PREFIX + ".reactive";
String GENERATE_BUILDERS = CODEGEN_TIME_CONFIG_PREFIX + ".builders";

static String getBasePackagePropertyName() {
return CODEGEN_BASE_PACKAGE;
Expand All @@ -29,4 +30,8 @@ static String getInputBaseDirPropertyName() {
static String getCodegenReactive() {
return CODEGEN_REACTIVE;
}

static String getGenerateBuilders() {
return GENERATE_BUILDERS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public interface ServerCodegenConfig {
@WithDefault("false")
boolean reactive();

/**
* Whether it must generate builders for properties.
*/
@WithDefault("false")
boolean builders();

/**
* The base package to be used to generated sources.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class ApicurioCodegenWrapper {

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

private final Config config;
private final File outdir;
private final JaxRsProjectSettings projectSettings;

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

public ApicurioCodegenWrapper(Config config, File outdir, JaxRsProjectSettings projectSettings) {
this.config = config;
this.outdir = outdir;
this.projectSettings = projectSettings;
this.projectSettings.setJavaPackage(getBasePackage(config));
this.projectSettings.setReactive(getReactiveValue(config));
this.projectSettings.setJavaPackage(getBasePackage());
this.projectSettings.setReactive(getReactiveValue());
}

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

try (FileOutputStream fos = new FileOutputStream(zipFile);
FileInputStream openApiStream = new FileInputStream(openApiFile)) {
OpenApi2JaxRs generator = new OpenApi2JaxRs();
OpenApi2JaxRs generator = new OpenApi2JaxRs() {
{
config = new ConfigurableGenerationConfig(ApicurioCodegenWrapper.this.config);
}
};
generator.setSettings(projectSettings);
generator.setUpdateOnly(true);
generator.setOpenApiDocument(openApiStream);
Expand Down Expand Up @@ -106,13 +112,13 @@ private void unzip(File fromZipFile, File toOutputDir) throws IOException {
}
}

private String getBasePackage(final Config config) {
private String getBasePackage() {
return config
.getOptionalValue(getBasePackagePropertyName(), String.class)
.orElse(DEFAULT_PACKAGE);
}

private Boolean getReactiveValue(final Config config) {
private Boolean getReactiveValue() {
return config
.getOptionalValue(getCodegenReactive(), Boolean.class)
.orElse(Boolean.FALSE);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.quarkiverse.openapi.server.generator.deployment.codegen;

import org.eclipse.microprofile.config.Config;
import org.jsonschema2pojo.DefaultGenerationConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.quarkiverse.openapi.server.generator.deployment.CodegenConfig;

public class ConfigurableGenerationConfig extends DefaultGenerationConfig {

private static final Logger log = LoggerFactory.getLogger(ConfigurableGenerationConfig.class);

private final boolean generateBuilders;

public ConfigurableGenerationConfig(Config config) {
generateBuilders = config
.getOptionalValue(CodegenConfig.getGenerateBuilders(), Boolean.class)
.orElse(Boolean.FALSE);
log.debug("generateBuilders={}", generateBuilders);
}

@Override
public boolean isGenerateBuilders() {
return generateBuilders;
}

}
113 changes: 113 additions & 0 deletions server/integration-tests/builders/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>quarkus-openapi-generator-server-integration-tests-parent</artifactId>
<groupId>io.quarkiverse.openapi.generator</groupId>
<version>3.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-openapi-generator-server-integration-tests-builders</artifactId>
<name>Quarkus - OpenAPI Generator - Server - Integration Tests - Builders</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-undertow</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.openapi.generator</groupId>
<artifactId>quarkus-openapi-generator-server</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-test-common</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.version}</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${version.surefire.plugin}</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
<maven.repo>${settings.localRepository}</maven.repo>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${failsafe-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
<maven.repo>${settings.localRepository}</maven.repo>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build</goal>
<goal>generate-code</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Codegen properties
quarkus.openapi.generator.spec=petstore-openapi.json
quarkus.openapi.generator.base-package=io.petstore
quarkus.openapi.generator.reactive=false
quarkus.openapi.generator.builders=true
Loading
Loading