Skip to content

Commit a3912b7

Browse files
authored
[Java][Microprofile] Fix #17526: enumOuterClass missing JSON-B (de)serializer (#18951)
* GH-17526/microprofile: Fix enumOuterClass missing JSON-B (de)serializer * Add microprofile-rest-client-outer-enum to jdk17 samples workflow * Regenerate samples
1 parent 0820ede commit a3912b7

23 files changed

Lines changed: 1181 additions & 1 deletion

File tree

.github/workflows/samples-jdk17.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
- samples/client/petstore/spring-http-interface-reactive/**
1010
- samples/client/petstore/spring-http-interface/**
1111
- samples/client/petstore/java/webclient-jakarta/**
12+
- samples/client/petstore/java/microprofile-rest-client-outer-enum/**
1213
# servers
1314
- samples/openapi3/server/petstore/springboot-3/**
1415
- samples/server/petstore/java-camel/**
@@ -23,6 +24,7 @@ on:
2324
- samples/client/petstore/spring-http-interface-reactive/**
2425
- samples/client/petstore/spring-http-interface/**
2526
- samples/client/petstore/java/webclient-jakarta/**
27+
- samples/client/petstore/java/microprofile-rest-client-outer-enum/**
2628
# servers
2729
- samples/openapi3/server/petstore/springboot-3/**
2830
- samples/server/petstore/java-camel/**
@@ -43,6 +45,7 @@ jobs:
4345
- samples/client/petstore/spring-http-interface-reactive
4446
- samples/client/petstore/spring-http-interface
4547
- samples/client/petstore/java/webclient-jakarta
48+
- samples/client/petstore/java/microprofile-rest-client-outer-enum
4649
# servers
4750
- samples/openapi3/server/petstore/springboot-3
4851
- samples/server/petstore/java-camel/
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
generatorName: java
2+
outputDir: samples/client/petstore/java/microprofile-rest-client-outer-enum
3+
library: microprofile
4+
inputSpec: modules/openapi-generator/src/test/resources/3_0/outerEnum.yaml
5+
templateDir: modules/openapi-generator/src/main/resources/Java
6+
additionalProperties:
7+
artifactId: microprofile-rest-client
8+
configKeyFromClassName: true

modules/openapi-generator/src/main/resources/Java/libraries/microprofile/enumOuterClass.mustache

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import java.net.URI;
99
/**
1010
* {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}
1111
*/
12+
{{#jsonb}}
13+
@JsonbTypeSerializer({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.Serializer.class)
14+
@JsonbTypeDeserializer({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.Deserializer.class)
15+
{{/jsonb}}
1216
{{>additionalEnumTypeAnnotations}}public enum {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} {
1317
{{#gson}}
1418
{{#allowableValues}}{{#enumVars}}
@@ -36,6 +40,22 @@ import java.net.URI;
3640
return String.valueOf(value);
3741
}
3842

43+
{{#jsonb}}
44+
public static final class Deserializer implements JsonbDeserializer<{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}> {
45+
@Override
46+
public {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
47+
return fromValue(parser.getString());
48+
}
49+
}
50+
51+
public static final class Serializer implements JsonbSerializer<{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}> {
52+
@Override
53+
public void serialize({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} obj, JsonGenerator generator, SerializationContext ctx) {
54+
generator.write(obj.value{{#isUri}}.toASCIIString(){{/isUri}});
55+
}
56+
}
57+
58+
{{/jsonb}}
3959
{{#jackson}}
4060
@JsonCreator
4161
{{/jackson}}
@@ -47,5 +67,4 @@ import java.net.URI;
4767
}
4868
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + text + "'");{{/useNullForUnknownEnumValue}}
4969
}
50-
5170
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
openapi: 3.0.0
2+
info:
3+
title: Petstore API
4+
description: API for managing pets in a pet store
5+
version: 1.0.0
6+
paths:
7+
/dogs:
8+
get:
9+
summary: List all dogs
10+
operationId: listDogs
11+
responses:
12+
'200':
13+
description: A list of dogs
14+
content:
15+
application/json:
16+
schema:
17+
type: array
18+
items:
19+
$ref: '#/components/schemas/Dog'
20+
/cats:
21+
get:
22+
summary: List all cats
23+
operationId: listCats
24+
responses:
25+
'200':
26+
description: A list of cats
27+
content:
28+
application/json:
29+
schema:
30+
type: array
31+
items:
32+
$ref: '#/components/schemas/Cat'
33+
components:
34+
schemas:
35+
Dog:
36+
type: object
37+
properties:
38+
id:
39+
type: integer
40+
format: int64
41+
name:
42+
type: string
43+
status:
44+
$ref: '#/components/schemas/Status'
45+
required:
46+
- id
47+
- name
48+
- status
49+
Cat:
50+
type: object
51+
properties:
52+
id:
53+
type: integer
54+
format: int64
55+
name:
56+
type: string
57+
status:
58+
$ref: '#/components/schemas/Status'
59+
required:
60+
- id
61+
- name
62+
- status
63+
Status:
64+
type: string
65+
enum:
66+
- available
67+
- pending
68+
- sold
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
README.md
2+
docs/Cat.md
3+
docs/DefaultApi.md
4+
docs/Dog.md
5+
docs/Status.md
6+
pom.xml
7+
src/main/java/org/openapitools/client/api/ApiException.java
8+
src/main/java/org/openapitools/client/api/ApiExceptionMapper.java
9+
src/main/java/org/openapitools/client/api/DefaultApi.java
10+
src/main/java/org/openapitools/client/model/Cat.java
11+
src/main/java/org/openapitools/client/model/Dog.java
12+
src/main/java/org/openapitools/client/model/Status.java
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.8.0-SNAPSHOT
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Petstore API - MicroProfile Rest Client & MicroProfile Server
2+
3+
API for managing pets in a pet store
4+
5+
## Overview
6+
This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
7+
[MicroProfile Rest Client](https://github.com/eclipse/microprofile-rest-client) is a type-safe way of calling
8+
REST services. The generated client contains an interface which acts as the client, you can inject it into dependent classes.
9+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
3+
# Cat
4+
5+
6+
## Properties
7+
8+
| Name | Type | Description | Notes |
9+
|------------ | ------------- | ------------- | -------------|
10+
|**id** | **Long** | | |
11+
|**name** | **String** | | |
12+
|**status** | **Status** | | |
13+
14+
15+
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# DefaultApi
2+
3+
All URIs are relative to *http://localhost*
4+
5+
| Method | HTTP request | Description |
6+
|------------- | ------------- | -------------|
7+
| [**listCats**](DefaultApi.md#listCats) | **GET** /cats | List all cats |
8+
| [**listDogs**](DefaultApi.md#listDogs) | **GET** /dogs | List all dogs |
9+
10+
11+
12+
## listCats
13+
14+
> List&lt;Cat&gt; listCats()
15+
16+
List all cats
17+
18+
### Example
19+
20+
```java
21+
// Import classes:
22+
import org.openapitools.client.ApiClient;
23+
import org.openapitools.client.ApiException;
24+
import org.openapitools.client.Configuration;
25+
import org.openapitools.client.models.*;
26+
import org.openapitools.client.api.DefaultApi;
27+
28+
public class Example {
29+
public static void main(String[] args) {
30+
ApiClient defaultClient = Configuration.getDefaultApiClient();
31+
defaultClient.setBasePath("http://localhost");
32+
33+
DefaultApi apiInstance = new DefaultApi(defaultClient);
34+
try {
35+
List<Cat> result = apiInstance.listCats();
36+
System.out.println(result);
37+
} catch (ApiException e) {
38+
System.err.println("Exception when calling DefaultApi#listCats");
39+
System.err.println("Status code: " + e.getCode());
40+
System.err.println("Reason: " + e.getResponseBody());
41+
System.err.println("Response headers: " + e.getResponseHeaders());
42+
e.printStackTrace();
43+
}
44+
}
45+
}
46+
```
47+
48+
### Parameters
49+
50+
This endpoint does not need any parameter.
51+
52+
### Return type
53+
54+
[**List&lt;Cat&gt;**](Cat.md)
55+
56+
### Authorization
57+
58+
No authorization required
59+
60+
### HTTP request headers
61+
62+
- **Content-Type**: Not defined
63+
- **Accept**: application/json
64+
65+
66+
### HTTP response details
67+
| Status code | Description | Response headers |
68+
|-------------|-------------|------------------|
69+
| **200** | A list of cats | - |
70+
71+
72+
## listDogs
73+
74+
> List&lt;Dog&gt; listDogs()
75+
76+
List all dogs
77+
78+
### Example
79+
80+
```java
81+
// Import classes:
82+
import org.openapitools.client.ApiClient;
83+
import org.openapitools.client.ApiException;
84+
import org.openapitools.client.Configuration;
85+
import org.openapitools.client.models.*;
86+
import org.openapitools.client.api.DefaultApi;
87+
88+
public class Example {
89+
public static void main(String[] args) {
90+
ApiClient defaultClient = Configuration.getDefaultApiClient();
91+
defaultClient.setBasePath("http://localhost");
92+
93+
DefaultApi apiInstance = new DefaultApi(defaultClient);
94+
try {
95+
List<Dog> result = apiInstance.listDogs();
96+
System.out.println(result);
97+
} catch (ApiException e) {
98+
System.err.println("Exception when calling DefaultApi#listDogs");
99+
System.err.println("Status code: " + e.getCode());
100+
System.err.println("Reason: " + e.getResponseBody());
101+
System.err.println("Response headers: " + e.getResponseHeaders());
102+
e.printStackTrace();
103+
}
104+
}
105+
}
106+
```
107+
108+
### Parameters
109+
110+
This endpoint does not need any parameter.
111+
112+
### Return type
113+
114+
[**List&lt;Dog&gt;**](Dog.md)
115+
116+
### Authorization
117+
118+
No authorization required
119+
120+
### HTTP request headers
121+
122+
- **Content-Type**: Not defined
123+
- **Accept**: application/json
124+
125+
126+
### HTTP response details
127+
| Status code | Description | Response headers |
128+
|-------------|-------------|------------------|
129+
| **200** | A list of dogs | - |
130+

0 commit comments

Comments
 (0)