Skip to content

Commit a994804

Browse files
authored
issue-214 Fixed enum serialization (#215)
Signed-off-by: Helber Belmiro <[email protected]> Signed-off-by: Helber Belmiro <[email protected]>
1 parent d817cd4 commit a994804

File tree

5 files changed

+213
-0
lines changed

5 files changed

+213
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
value = v;
2121
}
2222

23+
@com.fasterxml.jackson.annotation.JsonValue
2324
public {#if e.isContainer}{e.items.dataType}{#else}{e.dataType}{/if} value() {
2425
return value;
2526
}
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-enum-property</artifactId>
11+
<name>Quarkus - Openapi Generator - Integration Tests - Enum Property</name>
12+
<description>Example project for OpenAPI with enum 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+
<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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
openapi: 3.0.3
2+
info:
3+
title: echo
4+
version: '1.0.0'
5+
description: ""
6+
paths:
7+
/echo:
8+
post:
9+
summary: Echo
10+
operationId: echo
11+
requestBody:
12+
content:
13+
application/json:
14+
schema:
15+
$ref: "#/components/schemas/Message"
16+
responses:
17+
"200":
18+
description: OK
19+
content:
20+
application/json:
21+
schema:
22+
$ref: '#/components/schemas/Echo'
23+
components:
24+
schemas:
25+
Echo:
26+
type: object
27+
properties:
28+
echoedMsgType:
29+
type: string
30+
Message:
31+
type: object
32+
required:
33+
- msgType
34+
properties:
35+
msgType:
36+
type: string
37+
enum:
38+
- 'text'
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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.post;
5+
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
6+
import static org.assertj.core.api.Assertions.assertThat;
7+
8+
import java.util.Collections;
9+
import java.util.Map;
10+
11+
import jakarta.inject.Inject;
12+
13+
import org.eclipse.microprofile.rest.client.inject.RestClient;
14+
import org.junit.jupiter.api.Test;
15+
import org.openapi.quarkus.enum_property_yaml.api.DefaultApi;
16+
import org.openapi.quarkus.enum_property_yaml.model.Echo;
17+
import org.openapi.quarkus.enum_property_yaml.model.Message;
18+
19+
import com.github.tomakehurst.wiremock.WireMockServer;
20+
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
21+
import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer;
22+
23+
import io.quarkus.test.common.QuarkusTestResource;
24+
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
25+
import io.quarkus.test.junit.QuarkusTest;
26+
27+
@QuarkusTest
28+
@QuarkusTestResource(EnumPropertyTest.EchoMockServer.class)
29+
class EnumPropertyTest {
30+
31+
@RestClient
32+
@Inject
33+
DefaultApi api;
34+
35+
@Test
36+
void apiIsBeingGenerated() {
37+
var message = new Message();
38+
message.setMsgType(Message.MsgTypeEnum.TEXT);
39+
40+
Echo echo = api.echo(message);
41+
42+
assertThat(echo.getEchoedMsgType())
43+
.isEqualTo("text");
44+
}
45+
46+
public static class EchoMockServer implements QuarkusTestResourceLifecycleManager {
47+
48+
private WireMockServer wireMockServer;
49+
50+
@Override
51+
public Map<String, String> start() {
52+
configureWiremockServer();
53+
return Collections.singletonMap("org.openapi.quarkus.enum_property_yaml.api.DefaultApi/mp-rest/url",
54+
wireMockServer.baseUrl());
55+
}
56+
57+
private void configureWiremockServer() {
58+
var wireMockConfiguration = WireMockConfiguration.wireMockConfig()
59+
.extensions(new ResponseTemplateTransformer(false)).dynamicPort();
60+
wireMockServer = new WireMockServer(wireMockConfiguration);
61+
wireMockServer.start();
62+
63+
wireMockServer.stubFor(post(urlEqualTo("/echo"))
64+
.willReturn(aResponse()
65+
.withStatus(200)
66+
.withHeader("Content-Type", "application/json")
67+
.withBody("{ \"echoedMsgType\": \"{{jsonPath request.body '$.msgType'}}\"}")
68+
.withTransformers("response-template")));
69+
}
70+
71+
@Override
72+
public void stop() {
73+
if (wireMockServer != null) {
74+
wireMockServer.stop();
75+
}
76+
}
77+
}
78+
}

integration-tests/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<packaging>pom</packaging>
1212
<modules>
1313
<module>array-enum</module>
14+
<module>enum-property</module>
1415
<module>simple</module>
1516
<module>skip-validation</module>
1617
<module>generation-tests</module>

0 commit comments

Comments
 (0)