Skip to content

Commit 24d4977

Browse files
authored
Replaced @queryParams with @BeanParams (#313) (#317)
* Replaced @queryParams with @BeanParams (#313) Signed-off-by: Helber Belmiro <[email protected]> (cherry picked from commit 913ee37) * Replaced jakarta with javax Signed-off-by: Helber Belmiro <[email protected]> --------- Signed-off-by: Helber Belmiro <[email protected]>
1 parent 68c05c2 commit 24d4977

File tree

7 files changed

+290
-1
lines changed

7 files changed

+290
-1
lines changed

deployment/src/main/resources/templates/pojo.qute

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public class {m.classname} {#if m.parent}extends {m.parent}{/if}{#if m.serializa
4848
* {m.description}
4949
**/
5050
{/if}
51+
{#if !v.isEnum}
52+
@javax.ws.rs.QueryParam("{v.name}")
53+
{/if}
5154
{#if v.isContainer}
5255
private {v.datatypeWithEnum} {v.name}{#if v.required} = {v.defaultValue}{#else} = null{/if};
5356
{#else}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{#if param.isQueryParam}@GeneratedParam("{param.baseName}") @QueryParam("{param.baseName}"){#if param.useBeanValidation}{#include beanValidationCore.qute p=param/}{/if} {#if param.isContainer}{#if param.defaultValue}@DefaultValue("\{{param.defaultValue}\}"){/if}{/if}{param.dataType} {param.paramName}{/if}
1+
{#if param.isQueryParam}@GeneratedParam("{param.baseName}") {#if param.isModel}@BeanParam{#else}@QueryParam("{param.baseName}"){/if}{#if param.useBeanValidation}{#include beanValidationCore.qute p=param/}{/if} {#if param.isContainer}{#if param.defaultValue}@DefaultValue("\{{param.defaultValue}\}"){/if}{/if}{param.dataType} {param.paramName}{#else}{/if}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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>2.0.0-SNAPSHOT</version>
7+
</parent>
8+
<modelVersion>4.0.0</modelVersion>
9+
10+
<artifactId>quarkus-openapi-generator-it-beanparam</artifactId>
11+
<name>Quarkus - Openapi Generator - Integration Tests - BeanParam</name>
12+
<description>Example project for @BeanParam usage</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+
<dependency>
30+
<groupId>com.github.tomakehurst</groupId>
31+
<artifactId>wiremock-jre8</artifactId>
32+
<scope>test</scope>
33+
</dependency>
34+
</dependencies>
35+
<build>
36+
<plugins>
37+
<plugin>
38+
<groupId>io.quarkus</groupId>
39+
<artifactId>quarkus-maven-plugin</artifactId>
40+
<extensions>true</extensions>
41+
<executions>
42+
<execution>
43+
<goals>
44+
<goal>build</goal>
45+
<goal>generate-code</goal>
46+
<goal>generate-code-tests</goal>
47+
</goals>
48+
</execution>
49+
</executions>
50+
</plugin>
51+
</plugins>
52+
</build>
53+
<profiles>
54+
<profile>
55+
<id>native-image</id>
56+
<activation>
57+
<property>
58+
<name>native</name>
59+
</property>
60+
</activation>
61+
<build>
62+
<plugins>
63+
<plugin>
64+
<artifactId>maven-surefire-plugin</artifactId>
65+
<configuration>
66+
<skipTests>${native.surefire.skip}</skipTests>
67+
</configuration>
68+
</plugin>
69+
<plugin>
70+
<artifactId>maven-failsafe-plugin</artifactId>
71+
<executions>
72+
<execution>
73+
<goals>
74+
<goal>integration-test</goal>
75+
<goal>verify</goal>
76+
</goals>
77+
<configuration>
78+
<systemPropertyVariables>
79+
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
80+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
81+
<maven.home>${maven.home}</maven.home>
82+
</systemPropertyVariables>
83+
</configuration>
84+
</execution>
85+
</executions>
86+
</plugin>
87+
</plugins>
88+
</build>
89+
<properties>
90+
<quarkus.package.type>native</quarkus.package.type>
91+
</properties>
92+
</profile>
93+
</profiles>
94+
95+
</project>
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
openapi: 3.0.1
2+
info:
3+
title: Api Documentation
4+
description: Api Documentation
5+
contact: {}
6+
license:
7+
name: Apache 2.0
8+
url: http://www.apache.org/licenses/LICENSE-2.0
9+
version: "4.0.0"
10+
tags:
11+
- name: GetTest
12+
description: GetTest Controller
13+
paths:
14+
/get:
15+
get:
16+
tags:
17+
- GetTest
18+
summary: getTest
19+
operationId: getTest
20+
parameters:
21+
- name: testObj
22+
in: query
23+
schema:
24+
$ref: "#/components/schemas/TestObj"
25+
- name: unpaged
26+
in: query
27+
schema:
28+
type: boolean
29+
responses:
30+
200:
31+
description: OK
32+
content:
33+
application/json:
34+
schema:
35+
$ref: "#/components/schemas/ResponseDto"
36+
400:
37+
$ref: "#/components/responses/ErrorResponse"
38+
403:
39+
$ref: "#/components/responses/ForbiddenResponse"
40+
deprecated: false
41+
components:
42+
schemas:
43+
TestObj:
44+
title: Pageable
45+
type: object
46+
properties:
47+
size:
48+
type: integer
49+
format: int32
50+
page:
51+
type: integer
52+
format: int32
53+
sort:
54+
$ref: "#/components/schemas/Sort"
55+
Sort:
56+
title: Sort
57+
type: array
58+
items:
59+
type: string
60+
ResponseDto:
61+
title: ResponseDto
62+
type: object
63+
discriminator:
64+
propertyName: response_type
65+
required:
66+
- message
67+
properties:
68+
error:
69+
type: string
70+
message:
71+
type: string
72+
optionals:
73+
type: array
74+
items:
75+
type: string
76+
ErrorResponseObject:
77+
type: object
78+
required:
79+
- error
80+
- message
81+
properties:
82+
error:
83+
type: string
84+
message:
85+
type: string
86+
responses:
87+
ErrorResponse:
88+
description: Common error
89+
content:
90+
application/json:
91+
schema:
92+
$ref: "#/components/schemas/ErrorResponseObject"
93+
UnauthorizedResponse:
94+
description: The user have typed the wrong credentials or don't have an account. This error only shows on login.
95+
content:
96+
application/json:
97+
schema:
98+
$ref: "#/components/schemas/ErrorResponseObject"
99+
ForbiddenResponse:
100+
description: The user doesn't have permission to make the operation.
101+
content:
102+
application/json:
103+
schema:
104+
$ref: "#/components/schemas/ErrorResponseObject"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package io.quarkiverse.openapi.generator.it;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import javax.inject.Inject;
6+
7+
import org.eclipse.microprofile.rest.client.inject.RestClient;
8+
import org.junit.jupiter.api.Test;
9+
import org.openapi.quarkus.openapi_yaml.api.GetTestApi;
10+
import org.openapi.quarkus.openapi_yaml.model.ResponseDto;
11+
import org.openapi.quarkus.openapi_yaml.model.TestObj;
12+
13+
import com.github.tomakehurst.wiremock.WireMockServer;
14+
import com.github.tomakehurst.wiremock.client.WireMock;
15+
16+
import io.quarkus.test.common.QuarkusTestResource;
17+
import io.quarkus.test.junit.QuarkusTest;
18+
19+
@QuarkusTestResource(WiremockBeanParam.class)
20+
@QuarkusTest
21+
class BeanParamOpenApiTest {
22+
23+
@RestClient
24+
@Inject
25+
GetTestApi api;
26+
27+
WireMockServer wireMockServer;
28+
29+
@Test
30+
void apiIsBeingGenerated() {
31+
TestObj model = new TestObj();
32+
model.size(42);
33+
34+
ResponseDto responseDto = api.getTest(model, true);
35+
assertThat(responseDto.getMessage()).isEqualTo("Hello");
36+
37+
wireMockServer.verify(WireMock.getRequestedFor(
38+
WireMock.urlEqualTo("/get?size=42&unpaged=true")));
39+
}
40+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package io.quarkiverse.openapi.generator.it;
2+
3+
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
4+
import static com.github.tomakehurst.wiremock.client.WireMock.get;
5+
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
6+
7+
import java.util.Map;
8+
9+
import com.github.tomakehurst.wiremock.WireMockServer;
10+
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
11+
12+
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
13+
14+
public class WiremockBeanParam implements QuarkusTestResourceLifecycleManager {
15+
16+
public static final String URL_KEY = "quarkus.rest-client.openapi_yaml.url";
17+
18+
private WireMockServer wireMockServer;
19+
20+
@Override
21+
public Map<String, String> start() {
22+
wireMockServer = new WireMockServer(WireMockConfiguration.wireMockConfig().dynamicPort());
23+
wireMockServer.start();
24+
25+
wireMockServer.stubFor(get(urlPathEqualTo("/get"))
26+
.willReturn(aResponse()
27+
.withStatus(200)
28+
.withHeader("Content-Type", "application/json")
29+
.withBody(
30+
"{\"message\": \"Hello\"}")));
31+
32+
return Map.of(URL_KEY, wireMockServer.baseUrl());
33+
}
34+
35+
@Override
36+
public void inject(TestInjector testInjector) {
37+
testInjector.injectIntoFields(wireMockServer, f -> f.getName().equals("wireMockServer"));
38+
}
39+
40+
@Override
41+
public void stop() {
42+
if (null != wireMockServer) {
43+
wireMockServer.stop();
44+
}
45+
}
46+
}

integration-tests/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<module>exclude</module>
2626
<module>change-directory</module>
2727
<module>return-response</module>
28+
<module>beanparam</module>
2829
</modules>
2930
<dependencyManagement>
3031
<dependencies>

0 commit comments

Comments
 (0)