Skip to content

Commit 836d426

Browse files
authored
[Java] Fix generation of POJOs with sets of enums (fixes OpenAPITools#19957) (OpenAPITools#19960)
1 parent 62c0258 commit 836d426

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

modules/openapi-generator/src/main/resources/Java/pojo.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
395395
{{#uniqueItems}}
396396
if ({{getter}}() != null) {
397397
int i = 0;
398-
for ({{{items.dataType}}} _item : {{getter}}()) {
398+
for ({{{items.datatypeWithEnum}}} _item : {{getter}}()) {
399399
try {
400400
joiner.add(String.format("%s{{baseName}}%s%s=%s", prefix, suffix,
401401
"".equals(suffix) ? "" : String.format("%s%d%s", containerPrefix, i, containerSuffix),

modules/openapi-generator/src/test/java/org/openapitools/codegen/java/apachehttpclient/ApacheHttpClientCodegenTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,28 @@ public void testApacheHttpClientExplodedQueryParamWithArrayProperty() throws IOE
9090
"localVarQueryParams.addAll(apiClient.parameterToPairs(\"multi\", \"values\", queryObject.getValues()))"
9191
);
9292
}
93+
94+
@Test
95+
void testApacheHttpClientQueryParamHandlingUniqueItemsStringEnum() throws IOException {
96+
// Arrange
97+
var output = Files.createTempDirectory("test").toFile();
98+
output.deleteOnExit();
99+
100+
var configurator = new CodegenConfigurator()
101+
.setGeneratorName("java")
102+
.setLibrary(JavaClientCodegen.APACHE)
103+
.setInputSpec("src/test/resources/3_0/unique-items-string-enum.yaml")
104+
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
105+
106+
final ClientOptInput clientOptInput = configurator.toClientOptInput();
107+
DefaultGenerator generator = new DefaultGenerator();
108+
109+
// Act
110+
var files = generator.opts(clientOptInput).generate();
111+
112+
// Assert
113+
TestUtils.assertFileContains(Paths.get(output + "/src/main/java/org/openapitools/client/model/GetUsersRequestV1.java"),
114+
"for (RolesEnum _item : getRoles()) {"
115+
);
116+
}
93117
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
openapi: 3.0.1
2+
info:
3+
title: Sample API to test generation of schemas with uniqueItems arrays of enums
4+
description: API description in Markdown.
5+
version: 1.0.0
6+
servers: []
7+
paths: {}
8+
components:
9+
schemas:
10+
GetUsersRequestV1:
11+
type: object
12+
properties:
13+
roles:
14+
uniqueItems: true
15+
type: array
16+
items:
17+
type: string
18+
enum:
19+
- ROLE1
20+
- ROLE2

0 commit comments

Comments
 (0)