Skip to content

Commit 7898483

Browse files
kfebertFerdinand Ebert
andauthored
feature(Mutiny): new flag to generate response for Uni/Multi (#805)
* feature(Mutiny): new flag to generate response for Uni/Multi * test(Mutiny): add integration test - move existing tests from return-response to own module --------- Co-authored-by: Ferdinand Ebert <[email protected]>
1 parent fd06d31 commit 7898483

20 files changed

+239
-102
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public enum ConfigName {
4848
//global & spec configs
4949
SKIP_FORM_MODEL("skip-form-model"),
5050
MUTINY("mutiny"),
51+
MUTINY_RETURN_RESPONSE("mutiny.return-response"),
5152
MUTINY_OPERATION_IDS("mutiny.operation-ids"),
5253
ADDITIONAL_MODEL_TYPE_ANNOTATIONS("additional-model-type-annotations"),
5354
ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER("additional-enum-type-unexpected-member"),

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,27 +86,34 @@ public class CommonItemConfig {
8686
@ConfigItem(name = "mutiny")
8787
public Optional<Boolean> supportMutiny;
8888

89+
/**
90+
* Defines with SmallRye Mutiny enabled if methods should return {@link jakarta.ws.rs.core.Response} or a model. Default is
91+
* {@code false}.
92+
*/
93+
@ConfigItem(name = "mutiny.return-response")
94+
public Optional<Boolean> mutinyReturnResponse;
95+
8996
/**
9097
* Handles the return type for each operation, depending on the configuration.
9198
* The following cases are supported:
9299
* <p>
93100
* 1. If {@code mutiny} is enabled and the operation ID is specified to return {@code Multi}:
94101
* - The return type will be wrapped in {@link io.smallrye.mutiny.Multi}.
95-
* - If {@code return-response} is enabled, the return type will be
102+
* - If {@code mutiny.return-response} is enabled, the return type will be
96103
* {@link io.smallrye.mutiny.Multi<jakarta.ws.rs.core.Response>}.
97104
* - If the operation has a void return type, it will return {@link io.smallrye.mutiny.Multi<jakarta.ws.rs.core.Response>}.
98105
* - Otherwise, it will return {@link io.smallrye.mutiny.Multi<returnType>}.
99106
* <p>
100107
* 2. If {@code mutiny} is enabled and the operation ID is specified to return {@code Uni}:
101108
* - The return type will be wrapped in {@link io.smallrye.mutiny.Uni}.
102-
* - If {@code return-response} is enabled, the return type will be
109+
* - If {@code mutiny.return-response} is enabled, the return type will be
103110
* {@link io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response>}.
104111
* - If the operation has a void return type, it will return {@link io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response>}.
105112
* - Otherwise, it will return {@link io.smallrye.mutiny.Uni<returnType>}.
106113
* <p>
107114
* 3. If {@code mutiny} is enabled but no specific operation ID is configured for {@code Multi} or {@code Uni}:
108115
* - The return type defaults to {@code Uni}.
109-
* - If {@code return-response} is enabled, the return type will be
116+
* - If {@code mutiny.return-response} is enabled, the return type will be
110117
* {@link io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response>}.
111118
* - If the operation has a void return type, it will return {@link io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response>}.
112119
* - Otherwise, it will return {@link io.smallrye.mutiny.Uni<returnType>}`.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ protected void generate(final Config config, final Path openApiFilePath, final P
232232
generator.withReturnResponse(
233233
getValues(config, openApiFilePath, CodegenConfig.ConfigName.RETURN_RESPONSE, Boolean.class).orElse(false));
234234

235+
generator.withMutinyReturnResponse(
236+
getValues(config, openApiFilePath, CodegenConfig.ConfigName.MUTINY_RETURN_RESPONSE, Boolean.class)
237+
.orElse(false));
238+
235239
generator.withEnabledSecurityGeneration(
236240
getValues(config, openApiFilePath, CodegenConfig.ConfigName.ENABLE_SECURITY_GENERATION, Boolean.class)
237241
.orElse(true));

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ public OpenApiClientGeneratorWrapper withMutiny(final Boolean config) {
118118
return this;
119119
}
120120

121+
public OpenApiClientGeneratorWrapper withMutinyReturnResponse(final Boolean config) {
122+
if (config != null) {
123+
configurator.addAdditionalProperty("mutiny-return-response", config);
124+
}
125+
return this;
126+
}
127+
121128
public OpenApiClientGeneratorWrapper withMutinyReturnTypes(final Map<String, String> returnTypeMappings) {
122129
if (returnTypeMappings != null && !returnTypeMappings.isEmpty()) {
123130
Map<String, Object> mutinyOperationIdsMap = new HashMap<>(returnTypeMappings);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public interface {classname} {
5151
{/if}{/for}
5252
{#if mutiny}
5353
{#if mutiny-operation-ids.get(op.operationIdOriginal) == "Multi"}
54-
{#if return-response}
54+
{#if mutiny-return-response}
5555
public io.smallrye.mutiny.Multi<jakarta.ws.rs.core.Response> {op.nickname}(
5656
{#else}
5757
{#if op.returnType == "void"}
@@ -62,7 +62,7 @@ public interface {classname} {
6262
{/if}
6363
{#else}
6464
{#if mutiny-operation-ids.get(op.operationIdOriginal) == "Uni"}
65-
{#if return-response}
65+
{#if mutiny-return-response}
6666
public io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response> {op.nickname}(
6767
{#else}
6868
{#if op.returnType == "void"}
@@ -73,7 +73,7 @@ public interface {classname} {
7373
{/if}
7474
{#else}
7575
{#if !mutiny-operation-ids}
76-
{#if return-response}
76+
{#if mutiny-return-response}
7777
public io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response> {op.nickname}(
7878
{#else}
7979
{#if op.returnType == "void"}
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-response</artifactId>
11+
<name>Quarkus - Openapi Generator - Integration Tests - Client - Mutiny Return Response</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)