Skip to content

Commit 7126f84

Browse files
authored
feat: support RestResponse (#1381)
* feat: support RestResponse * chore: clarify default response type
1 parent e639d5b commit 7126f84

File tree

19 files changed

+2020
-38
lines changed

19 files changed

+2020
-38
lines changed

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ public interface CommonItemConfig {
6767
Optional<String> additionalRequestArgs();
6868

6969
/**
70-
* Defines if the methods should return {@link jakarta.ws.rs.core.Response} or a model. Default is {@code false}.
70+
* Defines if the methods should return {@link jakarta.ws.rs.core.Response},
71+
* {@link org.jboss.resteasy.reactive.RestResponse} or a model. By default, it returns the model in the specification.
7172
*/
7273
@WithName("return-response")
73-
Optional<Boolean> returnResponse();
74+
Optional<String> returnResponse();
7475

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

9495
/**
95-
* Defines with SmallRye Mutiny enabled if methods should return {@link jakarta.ws.rs.core.Response} or a model. Default is
96-
* {@code false}.
96+
* Defines with SmallRye Mutiny enabled if methods should return {@link jakarta.ws.rs.core.Response},
97+
* {@link org.jboss.resteasy.reactive.RestResponse} or a model. By default, it returns the model in the specification.
9798
*/
9899
@WithName("mutiny.return-response")
99-
Optional<Boolean> mutinyReturnResponse();
100+
Optional<String> mutinyReturnResponse();
100101

101102
/**
102103
* Handles the return type for each operation, depending on the configuration.
@@ -107,20 +108,32 @@ public interface CommonItemConfig {
107108
* - If {@code mutiny.return-response} is enabled, the return type will be
108109
* {@link io.smallrye.mutiny.Multi<jakarta.ws.rs.core.Response>}.
109110
* - If the operation has a void return type, it will return {@link io.smallrye.mutiny.Multi<jakarta.ws.rs.core.Response>}.
111+
* - If {@code mutiny.return-response} is set to {@code RestResponse}, the return type will be
112+
* {@link io.smallrye.mutiny.Multi<org.jboss.resteasy.reactive.RestResponse<returnType>>}.
113+
* - If the operation has a void return type, it will return
114+
* {@link io.smallrye.mutiny.Multi<org.jboss.resteasy.reactive.RestResponse<java.lang.Void>>}.
110115
* - Otherwise, it will return {@link io.smallrye.mutiny.Multi<returnType>}.
111116
* <p>
112117
* 2. If {@code mutiny} is enabled and the operation ID is specified to return {@code Uni}:
113118
* - The return type will be wrapped in {@link io.smallrye.mutiny.Uni}.
114119
* - If {@code mutiny.return-response} is enabled, the return type will be
115120
* {@link io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response>}.
116121
* - If the operation has a void return type, it will return {@link io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response>}.
122+
* - If {@code mutiny.return-response} is set to {@code RestResponse}, the return type will be
123+
* {@link io.smallrye.mutiny.Uni<org.jboss.resteasy.reactive.RestResponse<returnType>>}.
124+
* - If the operation has a void return type, it will return
125+
* {@link io.smallrye.mutiny.Uni<org.jboss.resteasy.reactive.RestResponse<java.lang.Void>>}.
117126
* - Otherwise, it will return {@link io.smallrye.mutiny.Uni<returnType>}.
118127
* <p>
119128
* 3. If {@code mutiny} is enabled but no specific operation ID is configured for {@code Multi} or {@code Uni}:
120129
* - The return type defaults to {@code Uni}.
121130
* - If {@code mutiny.return-response} is enabled, the return type will be
122131
* {@link io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response>}.
123132
* - If the operation has a void return type, it will return {@link io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response>}.
133+
* - If {@code mutiny.return-response} is set to {@code RestResponse}, the return type will be
134+
* {@link io.smallrye.mutiny.Uni<org.jboss.resteasy.reactive.RestResponse<returnType>>}.
135+
* - If the operation has a void return type, it will return
136+
* {@link io.smallrye.mutiny.Uni<org.jboss.resteasy.reactive.RestResponse<java.lang.Void>>}.
124137
* - Otherwise, it will return {@link io.smallrye.mutiny.Uni<returnType>}`.
125138
*/
126139
@WithName("mutiny.operation-ids")

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,11 @@ protected void generate(OpenApiGeneratorOptions options) {
279279
.ifPresentOrElse(generator::withConfigKey,
280280
() -> generator.withConfigKey(getSanitizedFileName(openApiFilePath)));
281281

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

285-
generator.withMutinyReturnResponse(
286-
getValues(config, openApiFilePath, CodegenConfig.ConfigName.MUTINY_RETURN_RESPONSE, Boolean.class)
287-
.orElse(false));
285+
getValues(config, openApiFilePath, CodegenConfig.ConfigName.MUTINY_RETURN_RESPONSE, String.class)
286+
.ifPresent(generator::withMutinyReturnResponse);
288287

289288
generator.withEnabledSecurityGeneration(
290289
getValues(config, openApiFilePath, CodegenConfig.ConfigName.ENABLE_SECURITY_GENERATION, Boolean.class)

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,12 @@ public OpenApiClientGeneratorWrapper withMutiny(final Boolean config) {
143143
return this;
144144
}
145145

146-
public OpenApiClientGeneratorWrapper withMutinyReturnResponse(final Boolean config) {
147-
Optional.ofNullable(config).ifPresent(cfg -> {
148-
this.configurator.addAdditionalProperty("mutiny-return-response", cfg);
149-
});
146+
public OpenApiClientGeneratorWrapper withMutinyReturnResponse(final String config) {
147+
if (config.equalsIgnoreCase(TRUE.toString())) {
148+
this.configurator.addAdditionalProperty("mutiny-return-response", "Response");
149+
} else {
150+
this.configurator.addAdditionalProperty("mutiny-return-response", config);
151+
}
150152
return this;
151153
}
152154

@@ -174,8 +176,12 @@ public OpenApiClientGeneratorWrapper withTypeMappings(final Map<String, String>
174176
return this;
175177
}
176178

177-
public OpenApiClientGeneratorWrapper withReturnResponse(Boolean returnResponse) {
178-
configurator.addAdditionalProperty("return-response", returnResponse);
179+
public OpenApiClientGeneratorWrapper withReturnResponse(String returnResponse) {
180+
if (returnResponse.equalsIgnoreCase(TRUE.toString())) {
181+
this.configurator.addAdditionalProperty("return-response", "Response");
182+
} else {
183+
this.configurator.addAdditionalProperty("return-response", returnResponse);
184+
}
179185
return this;
180186
}
181187

client/deployment/src/main/resources/templates/libraries/microprofile/api.qute

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,14 @@ public interface {classname} {
6161
{/if}{/for}
6262
{#if mutiny}
6363
{#if mutiny-operation-ids.get(op.operationIdOriginal) == "Multi"}
64-
{#if mutiny-return-response}
64+
{#if mutiny-return-response == "Response"}
6565
public io.smallrye.mutiny.Multi<jakarta.ws.rs.core.Response> {op.nickname}(
66+
{#else if mutiny-return-response == "RestResponse"}
67+
{#if op.returnType == "void"}
68+
public io.smallrye.mutiny.Multi<org.jboss.resteasy.reactive.RestResponse<Void>> {op.nickname}(
69+
{#else}
70+
public io.smallrye.mutiny.Multi<org.jboss.resteasy.reactive.RestResponse<{#if op.returnType}{op.returnType}{#else}Void{/if}>> {op.nickname}(
71+
{/if}
6672
{#else}
6773
{#if op.returnType == "void"}
6874
public io.smallrye.mutiny.Multi<jakarta.ws.rs.core.Response> {op.nickname}(
@@ -72,8 +78,14 @@ public interface {classname} {
7278
{/if}
7379
{#else}
7480
{#if mutiny-operation-ids.get(op.operationIdOriginal) == "Uni"}
75-
{#if mutiny-return-response}
81+
{#if mutiny-return-response == "Response"}
7682
public io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response> {op.nickname}(
83+
{#else if mutiny-return-response == "RestResponse"}
84+
{#if op.returnType == "void"}
85+
public io.smallrye.mutiny.Uni<org.jboss.resteasy.reactive.RestResponse<Void>> {op.nickname}(
86+
{#else}
87+
public io.smallrye.mutiny.Uni<org.jboss.resteasy.reactive.RestResponse<{#if op.returnType}{op.returnType}{#else}Void{/if}>> {op.nickname}(
88+
{/if}
7789
{#else}
7890
{#if op.returnType == "void"}
7991
public io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response> {op.nickname}(
@@ -83,8 +95,14 @@ public interface {classname} {
8395
{/if}
8496
{#else}
8597
{#if !mutiny-operation-ids}
86-
{#if mutiny-return-response}
98+
{#if mutiny-return-response == "Response"}
8799
public io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response> {op.nickname}(
100+
{#else if mutiny-return-response == "RestResponse"}
101+
{#if op.returnType == "void"}
102+
public io.smallrye.mutiny.Uni<org.jboss.resteasy.reactive.RestResponse<Void>> {op.nickname}(
103+
{#else}
104+
public io.smallrye.mutiny.Uni<org.jboss.resteasy.reactive.RestResponse<{#if op.returnType}{op.returnType}{#else}Void{/if}>> {op.nickname}(
105+
{/if}
88106
{#else}
89107
{#if op.returnType == "void"}
90108
public io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response> {op.nickname}(
@@ -100,8 +118,14 @@ public interface {classname} {
100118
public {#if op.returnType}io.smallrye.mutiny.Uni<{op.returnType}>{#else}io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response>{/if} {op.nickname}(
101119
{/if}
102120
{#else}
103-
{#if return-response}
121+
{#if return-response == "Response"}
104122
public jakarta.ws.rs.core.Response {op.nickname}(
123+
{#else if return-response == "RestResponse"}
124+
{#if op.returnType == "void"}
125+
public org.jboss.resteasy.reactive.RestResponse<Void> {op.nickname}(
126+
{#else}
127+
public org.jboss.resteasy.reactive.RestResponse<{#if op.returnType}{op.returnType}{#else}Void{/if}> {op.nickname}(
128+
{/if}
105129
{#else}
106130
{#if op.returnType == "void"}
107131
public jakarta.ws.rs.core.Response {op.nickname}(
@@ -114,8 +138,14 @@ public interface {classname} {
114138
{/if}
115139
{/if}
116140
{#else}
117-
{#if return-response}
141+
{#if return-response == "Response"}
118142
public jakarta.ws.rs.core.Response {op.nickname}(
143+
{#else if return-response == "RestResponse"}
144+
{#if op.returnType == "void"}
145+
public org.jboss.resteasy.reactive.RestResponse<Void> {op.nickname}(
146+
{#else}
147+
public org.jboss.resteasy.reactive.RestResponse<{#if op.returnType}{op.returnType}{#else}Void{/if}> {op.nickname}(
148+
{/if}
119149
{#else}
120150
{#if op.returnType == "void"}
121151
public jakarta.ws.rs.core.Response {op.nickname}(
@@ -164,4 +194,4 @@ public interface {classname} {
164194

165195
{/if} {! check deprecated !}
166196
{/for}
167-
}
197+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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-mutiny-return-rest-response</artifactId>
11+
<name>Quarkus - OpenAPI Generator - Integration Tests - Client - Mutiny Return RestResponse</name>
12+
<description>Example project for usage of the mutiny-return-response property</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+
</dependencies>
30+
<build>
31+
<plugins>
32+
<plugin>
33+
<groupId>io.quarkus</groupId>
34+
<artifactId>quarkus-maven-plugin</artifactId>
35+
<extensions>true</extensions>
36+
<executions>
37+
<execution>
38+
<goals>
39+
<goal>build</goal>
40+
<goal>generate-code</goal>
41+
<goal>generate-code-tests</goal>
42+
</goals>
43+
</execution>
44+
</executions>
45+
</plugin>
46+
</plugins>
47+
</build>
48+
<profiles>
49+
<profile>
50+
<id>native-image</id>
51+
<activation>
52+
<property>
53+
<name>native</name>
54+
</property>
55+
</activation>
56+
<build>
57+
<plugins>
58+
<plugin>
59+
<artifactId>maven-surefire-plugin</artifactId>
60+
<configuration>
61+
<skipTests>${native.surefire.skip}</skipTests>
62+
</configuration>
63+
</plugin>
64+
<plugin>
65+
<artifactId>maven-failsafe-plugin</artifactId>
66+
<executions>
67+
<execution>
68+
<goals>
69+
<goal>integration-test</goal>
70+
<goal>verify</goal>
71+
</goals>
72+
<configuration>
73+
<systemPropertyVariables>
74+
<native.image.path>
75+
${project.build.directory}/${project.build.finalName}-runner
76+
</native.image.path>
77+
<java.util.logging.manager>org.jboss.logmanager.LogManager
78+
</java.util.logging.manager>
79+
<maven.home>${maven.home}</maven.home>
80+
</systemPropertyVariables>
81+
</configuration>
82+
</execution>
83+
</executions>
84+
</plugin>
85+
</plugins>
86+
</build>
87+
<properties>
88+
<quarkus.package.type>native</quarkus.package.type>
89+
</properties>
90+
</profile>
91+
</profiles>
92+
93+
</project>

0 commit comments

Comments
 (0)