Skip to content

Commit ab87bf6

Browse files
committed
issue-205 Added support to enum arrays (#211)
1 parent 074d026 commit ab87bf6

File tree

6 files changed

+178
-12
lines changed

6 files changed

+178
-12
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
{#if e.withXml}
2-
@XmlType(name="{e.datatypeWithEnum}")
3-
@XmlEnum({e.dataType}.class)
2+
@XmlType(name={#if e.isEnum}"{e.items.enumName}"{#else}"{e.enumName}"{/if})
3+
@XmlEnum({#if e.isEnum}{e.items.dataType}{#else}{e.dataType}{/if}.class)
44
{/if}
5-
{#include additionalEnumTypeAnnotations.qute e=e /}public enum {e.datatypeWithEnum} {
5+
{#include additionalEnumTypeAnnotations.qute e=e /}public enum {e.enumName} {
66
{#if e.allowableValues}
77
{#if e.withXml}
8-
{#for v in e.allowableValues.enumVars}@XmlEnumValue({#if v.isInteger || v.isDouble || v.isLong || v.isFloat}"{/if}{v.value}{#if v.isInteger || v.isDouble || v.isLong || v.isFloat}"{/if}) {v.name}({e.dataType}.valueOf({v.value})){#if v_hasNext}, {#else}; {/if}{/for}
8+
{#for v in e.allowableValues.enumVars}@XmlEnumValue({#if v.isInteger || v.isDouble || v.isLong || v.isFloat}"{/if}{v.value}{#if v.isInteger || v.isDouble || v.isLong || v.isFloat}"{/if}) {v.name}({#if e.isEnum}{e.items.dataType}{#else}{e.dataType}{/if}.valueOf({v.value})){#if v_hasNext}, {#else}; {/if}{/for}
99
{#else}
10-
{#for v in e.allowableValues.enumVars}{v.name}({e.dataType}.valueOf({v.value})){#if v_hasNext}, {#else};{/if}{/for}
10+
{#for v in e.allowableValues.enumVars}{v.name}({v.value}){#if v_hasNext}, {#else};{/if}{/for}
1111
{/if}
1212
{/if}
1313

1414
// caching enum access
15-
private static final java.util.EnumSet<{e.datatypeWithEnum}> values = java.util.EnumSet.allOf({e.datatypeWithEnum}.class);
15+
private static final java.util.EnumSet<{e.enumName}> values = java.util.EnumSet.allOf({e.enumName}.class);
1616

17-
{e.dataType} value;
17+
{#if e.isContainer}{e.items.dataType}{#else}{e.dataType}{/if} value;
1818

19-
{e.datatypeWithEnum} ({e.dataType} v) {
19+
{e.enumName} ({#if e.isContainer}{e.items.dataType}{#else}{e.dataType}{/if} v) {
2020
value = v;
2121
}
2222

23-
public {e.dataType} value() {
23+
public {#if e.isContainer}{e.items.dataType}{#else}{e.dataType}{/if} value() {
2424
return value;
2525
}
2626

@@ -30,8 +30,8 @@
3030
}
3131

3232
@com.fasterxml.jackson.annotation.JsonCreator
33-
public static {e.datatypeWithEnum} fromValue(String v) {
34-
for ({#if e.datatypeWithEnum}{e.datatypeWithEnum}{#else}{e.classname}{/if} b : values) {
33+
public static {e.enumName} fromValue(String v) {
34+
for ({#if e.enumName}{e.enumName}{#else}{e.classname}{/if} b : values) {
3535
if (String.valueOf(b.value).equalsIgnoreCase(v)) {
3636
return b;
3737
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ public class {m.classname} {#if m.parent}extends {m.parent}{/if}{#if m.serializa
7979
{ext}
8080
{/for}
8181
{#if v.useBeanValidation}{#include beanValidation.qute p=v/}{/if}
82-
{#if v.isEnum && !v.isArray && !v.isMap}public {v.datatypeWithEnum} {v.getter}() {
82+
{#if v.isEnum && v.isContainer}public {v.datatypeWithEnum} {v.getter}(){
83+
return {v.name};
84+
}{#else if v.isEnum && !v.isArray && !v.isMap}public {v.datatypeWithEnum} {v.getter}() {
8385
return {v.name};
8486
}{#else if !v.isEnum && !v.isArray && !v.isMap}public {v.datatype} {v.getter}() {
8587
return {v.name};
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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>1.0.0-SNAPSHOT</version>
7+
</parent>
8+
<modelVersion>4.0.0</modelVersion>
9+
10+
<artifactId>quarkus-openapi-generator-it-array-enum</artifactId>
11+
<name>Quarkus - Openapi Generator - Integration Tests - Array enum</name>
12+
<description>Example project for OpenAPI with array of enums</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>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
75+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
76+
<maven.home>${maven.home}</maven.home>
77+
</systemPropertyVariables>
78+
</configuration>
79+
</execution>
80+
</executions>
81+
</plugin>
82+
</plugins>
83+
</build>
84+
<properties>
85+
<quarkus.package.type>native</quarkus.package.type>
86+
</properties>
87+
</profile>
88+
</profiles>
89+
90+
</project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
openapi: 3.0.3
3+
info:
4+
title: greeting-flow API
5+
version: "1.0"
6+
paths:
7+
/hello:
8+
get:
9+
tags:
10+
- Array Enum Resource
11+
operationId: create-a-webhook
12+
summary: Add a webhook
13+
description: Add a webhook subscription to the account
14+
parameters:
15+
- name: data
16+
in: query
17+
required: true
18+
schema:
19+
$ref: '#/components/schemas/webhook_create_update_payload'
20+
responses:
21+
"200":
22+
description: OK
23+
/messaging/topics:
24+
get:
25+
tags:
26+
- Quarkus Topics Information Resource
27+
responses:
28+
"200":
29+
description: OK
30+
components:
31+
schemas:
32+
webhook_create_update_payload:
33+
type: object
34+
properties:
35+
url:
36+
type: string
37+
description: The url where the events should be sent
38+
subscriptions:
39+
type: array
40+
items:
41+
type: string
42+
enum:
43+
- conversation_created
44+
- conversation_status_changed
45+
- conversation_updated
46+
- message_created
47+
- message_updated
48+
- webwidget_triggered
49+
description: The events you want to subscribe to.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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.array_enum_yaml.api.ArrayEnumResourceApi;
10+
11+
import io.quarkus.test.junit.QuarkusTest;
12+
13+
@QuarkusTest
14+
class ArrayEnumTest {
15+
16+
@RestClient
17+
@Inject
18+
ArrayEnumResourceApi api;
19+
20+
@Test
21+
void apiIsBeingGenerated() {
22+
assertThat(api).isNotNull();
23+
}
24+
}

integration-tests/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<name>Quarkus - Openapi Generator - Integration Tests</name>
1111
<packaging>pom</packaging>
1212
<modules>
13+
<module>array-enum</module>
1314
<module>simple</module>
1415
<module>skip-validation</module>
1516
<module>generation-tests</module>

0 commit comments

Comments
 (0)