Skip to content
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 @@ -67,10 +67,11 @@ public interface CommonItemConfig {
Optional<String> additionalRequestArgs();

/**
* Defines if the methods should return {@link jakarta.ws.rs.core.Response} or a model. Default is {@code false}.
* Defines if the methods should return {@link jakarta.ws.rs.core.Response},
* {@link org.jboss.resteasy.reactive.RestResponse} or a model. Default is {@code false}.
*/
@WithName("return-response")
Optional<Boolean> returnResponse();
Optional<String> returnResponse();

/**
* Defines if security support classes should be generated
Expand All @@ -92,11 +93,11 @@ public interface CommonItemConfig {
Optional<Boolean> supportMutiny();

/**
* Defines with SmallRye Mutiny enabled if methods should return {@link jakarta.ws.rs.core.Response} or a model. Default is
* {@code false}.
* Defines with SmallRye Mutiny enabled if methods should return {@link jakarta.ws.rs.core.Response},
* {@link org.jboss.resteasy.reactive.RestResponse} or a model. Default is {@code false}.
*/
@WithName("mutiny.return-response")
Optional<Boolean> mutinyReturnResponse();
Optional<String> mutinyReturnResponse();

/**
* Handles the return type for each operation, depending on the configuration.
Expand All @@ -107,20 +108,32 @@ public interface CommonItemConfig {
* - If {@code mutiny.return-response} is enabled, the return type will be
* {@link io.smallrye.mutiny.Multi<jakarta.ws.rs.core.Response>}.
* - If the operation has a void return type, it will return {@link io.smallrye.mutiny.Multi<jakarta.ws.rs.core.Response>}.
* - If {@code mutiny.return-response} is set to {@code RestResponse}, the return type will be
* {@link io.smallrye.mutiny.Multi<org.jboss.resteasy.reactive.RestResponse<returnType>>}.
* - If the operation has a void return type, it will return
* {@link io.smallrye.mutiny.Multi<org.jboss.resteasy.reactive.RestResponse<java.lang.Void>>}.
* - Otherwise, it will return {@link io.smallrye.mutiny.Multi<returnType>}.
* <p>
* 2. If {@code mutiny} is enabled and the operation ID is specified to return {@code Uni}:
* - The return type will be wrapped in {@link io.smallrye.mutiny.Uni}.
* - If {@code mutiny.return-response} is enabled, the return type will be
* {@link io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response>}.
* - If the operation has a void return type, it will return {@link io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response>}.
* - If {@code mutiny.return-response} is set to {@code RestResponse}, the return type will be
* {@link io.smallrye.mutiny.Uni<org.jboss.resteasy.reactive.RestResponse<returnType>>}.
* - If the operation has a void return type, it will return
* {@link io.smallrye.mutiny.Uni<org.jboss.resteasy.reactive.RestResponse<java.lang.Void>>}.
* - Otherwise, it will return {@link io.smallrye.mutiny.Uni<returnType>}.
* <p>
* 3. If {@code mutiny} is enabled but no specific operation ID is configured for {@code Multi} or {@code Uni}:
* - The return type defaults to {@code Uni}.
* - If {@code mutiny.return-response} is enabled, the return type will be
* {@link io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response>}.
* - If the operation has a void return type, it will return {@link io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response>}.
* - If {@code mutiny.return-response} is set to {@code RestResponse}, the return type will be
* {@link io.smallrye.mutiny.Uni<org.jboss.resteasy.reactive.RestResponse<returnType>>}.
* - If the operation has a void return type, it will return
* {@link io.smallrye.mutiny.Uni<org.jboss.resteasy.reactive.RestResponse<java.lang.Void>>}.
* - Otherwise, it will return {@link io.smallrye.mutiny.Uni<returnType>}`.
*/
@WithName("mutiny.operation-ids")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,11 @@ protected void generate(OpenApiGeneratorOptions options) {
.ifPresentOrElse(generator::withConfigKey,
() -> generator.withConfigKey(getSanitizedFileName(openApiFilePath)));

generator.withReturnResponse(
getValues(config, openApiFilePath, CodegenConfig.ConfigName.RETURN_RESPONSE, Boolean.class).orElse(false));
getValues(config, openApiFilePath, CodegenConfig.ConfigName.RETURN_RESPONSE, String.class)
.ifPresent(generator::withReturnResponse);

generator.withMutinyReturnResponse(
getValues(config, openApiFilePath, CodegenConfig.ConfigName.MUTINY_RETURN_RESPONSE, Boolean.class)
.orElse(false));
getValues(config, openApiFilePath, CodegenConfig.ConfigName.MUTINY_RETURN_RESPONSE, String.class)
.ifPresent(generator::withMutinyReturnResponse);

generator.withEnabledSecurityGeneration(
getValues(config, openApiFilePath, CodegenConfig.ConfigName.ENABLE_SECURITY_GENERATION, Boolean.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,12 @@ public OpenApiClientGeneratorWrapper withMutiny(final Boolean config) {
return this;
}

public OpenApiClientGeneratorWrapper withMutinyReturnResponse(final Boolean config) {
Optional.ofNullable(config).ifPresent(cfg -> {
this.configurator.addAdditionalProperty("mutiny-return-response", cfg);
});
public OpenApiClientGeneratorWrapper withMutinyReturnResponse(final String config) {
if (config.equalsIgnoreCase(TRUE.toString())) {
this.configurator.addAdditionalProperty("mutiny-return-response", "Response");
} else {
this.configurator.addAdditionalProperty("mutiny-return-response", config);
}
return this;
}

Expand Down Expand Up @@ -174,8 +176,12 @@ public OpenApiClientGeneratorWrapper withTypeMappings(final Map<String, String>
return this;
}

public OpenApiClientGeneratorWrapper withReturnResponse(Boolean returnResponse) {
configurator.addAdditionalProperty("return-response", returnResponse);
public OpenApiClientGeneratorWrapper withReturnResponse(String returnResponse) {
if (returnResponse.equalsIgnoreCase(TRUE.toString())) {
this.configurator.addAdditionalProperty("return-response", "Response");
} else {
this.configurator.addAdditionalProperty("return-response", returnResponse);
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,14 @@ public interface {classname} {
{/if}{/for}
{#if mutiny}
{#if mutiny-operation-ids.get(op.operationIdOriginal) == "Multi"}
{#if mutiny-return-response}
{#if mutiny-return-response == "Response"}
public io.smallrye.mutiny.Multi<jakarta.ws.rs.core.Response> {op.nickname}(
{#else if mutiny-return-response == "RestResponse"}
{#if op.returnType == "void"}
public io.smallrye.mutiny.Multi<org.jboss.resteasy.reactive.RestResponse<Void>> {op.nickname}(
{#else}
public io.smallrye.mutiny.Multi<org.jboss.resteasy.reactive.RestResponse<{#if op.returnType}{op.returnType}{#else}Void{/if}>> {op.nickname}(
{/if}
{#else}
{#if op.returnType == "void"}
public io.smallrye.mutiny.Multi<jakarta.ws.rs.core.Response> {op.nickname}(
Expand All @@ -72,8 +78,14 @@ public interface {classname} {
{/if}
{#else}
{#if mutiny-operation-ids.get(op.operationIdOriginal) == "Uni"}
{#if mutiny-return-response}
{#if mutiny-return-response == "Response"}
public io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response> {op.nickname}(
{#else if mutiny-return-response == "RestResponse"}
{#if op.returnType == "void"}
public io.smallrye.mutiny.Uni<org.jboss.resteasy.reactive.RestResponse<Void>> {op.nickname}(
{#else}
public io.smallrye.mutiny.Uni<org.jboss.resteasy.reactive.RestResponse<{#if op.returnType}{op.returnType}{#else}Void{/if}>> {op.nickname}(
{/if}
{#else}
{#if op.returnType == "void"}
public io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response> {op.nickname}(
Expand All @@ -83,8 +95,14 @@ public interface {classname} {
{/if}
{#else}
{#if !mutiny-operation-ids}
{#if mutiny-return-response}
{#if mutiny-return-response == "Response"}
public io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response> {op.nickname}(
{#else if mutiny-return-response == "RestResponse"}
{#if op.returnType == "void"}
public io.smallrye.mutiny.Uni<org.jboss.resteasy.reactive.RestResponse<Void>> {op.nickname}(
{#else}
public io.smallrye.mutiny.Uni<org.jboss.resteasy.reactive.RestResponse<{#if op.returnType}{op.returnType}{#else}Void{/if}>> {op.nickname}(
{/if}
{#else}
{#if op.returnType == "void"}
public io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response> {op.nickname}(
Expand All @@ -100,8 +118,14 @@ public interface {classname} {
public {#if op.returnType}io.smallrye.mutiny.Uni<{op.returnType}>{#else}io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response>{/if} {op.nickname}(
{/if}
{#else}
{#if return-response}
{#if return-response == "Response"}
public jakarta.ws.rs.core.Response {op.nickname}(
{#else if return-response == "RestResponse"}
{#if op.returnType == "void"}
public org.jboss.resteasy.reactive.RestResponse<Void> {op.nickname}(
{#else}
public org.jboss.resteasy.reactive.RestResponse<{#if op.returnType}{op.returnType}{#else}Void{/if}> {op.nickname}(
{/if}
{#else}
{#if op.returnType == "void"}
public jakarta.ws.rs.core.Response {op.nickname}(
Expand All @@ -114,8 +138,14 @@ public interface {classname} {
{/if}
{/if}
{#else}
{#if return-response}
{#if return-response == "Response"}
public jakarta.ws.rs.core.Response {op.nickname}(
{#else if return-response == "RestResponse"}
{#if op.returnType == "void"}
public org.jboss.resteasy.reactive.RestResponse<Void> {op.nickname}(
{#else}
public org.jboss.resteasy.reactive.RestResponse<{#if op.returnType}{op.returnType}{#else}Void{/if}> {op.nickname}(
{/if}
{#else}
{#if op.returnType == "void"}
public jakarta.ws.rs.core.Response {op.nickname}(
Expand Down Expand Up @@ -164,4 +194,4 @@ public interface {classname} {

{/if} {! check deprecated !}
{/for}
}
}
93 changes: 93 additions & 0 deletions client/integration-tests/mutiny-return-rest-response/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?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-integration-tests</artifactId>
<groupId>io.quarkiverse.openapi.generator</groupId>
<version>3.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-openapi-generator-it-mutiny-return-rest-response</artifactId>
<name>Quarkus - OpenAPI Generator - Integration Tests - Client - Mutiny Return RestResponse</name>
<description>Example project for usage of the mutiny-return-response property</description>

<dependencies>
<dependency>
<groupId>io.quarkiverse.openapi.generator</groupId>
<artifactId>quarkus-openapi-generator</artifactId>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>build</goal>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native-image</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${native.surefire.skip}</skipTests>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<native.image.path>
${project.build.directory}/${project.build.finalName}-runner
</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager
</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>

</project>
Loading