mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-06-29 04:00:51 +00:00
This commit is contained in:
parent
62c0258e04
commit
836d426d21
@ -395,7 +395,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens
|
||||
{{#uniqueItems}}
|
||||
if ({{getter}}() != null) {
|
||||
int i = 0;
|
||||
for ({{{items.dataType}}} _item : {{getter}}()) {
|
||||
for ({{{items.datatypeWithEnum}}} _item : {{getter}}()) {
|
||||
try {
|
||||
joiner.add(String.format("%s{{baseName}}%s%s=%s", prefix, suffix,
|
||||
"".equals(suffix) ? "" : String.format("%s%d%s", containerPrefix, i, containerSuffix),
|
||||
|
@ -90,4 +90,28 @@ public class ApacheHttpClientCodegenTest {
|
||||
"localVarQueryParams.addAll(apiClient.parameterToPairs(\"multi\", \"values\", queryObject.getValues()))"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testApacheHttpClientQueryParamHandlingUniqueItemsStringEnum() throws IOException {
|
||||
// Arrange
|
||||
var output = Files.createTempDirectory("test").toFile();
|
||||
output.deleteOnExit();
|
||||
|
||||
var configurator = new CodegenConfigurator()
|
||||
.setGeneratorName("java")
|
||||
.setLibrary(JavaClientCodegen.APACHE)
|
||||
.setInputSpec("src/test/resources/3_0/unique-items-string-enum.yaml")
|
||||
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
|
||||
|
||||
final ClientOptInput clientOptInput = configurator.toClientOptInput();
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
|
||||
// Act
|
||||
var files = generator.opts(clientOptInput).generate();
|
||||
|
||||
// Assert
|
||||
TestUtils.assertFileContains(Paths.get(output + "/src/main/java/org/openapitools/client/model/GetUsersRequestV1.java"),
|
||||
"for (RolesEnum _item : getRoles()) {"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
openapi: 3.0.1
|
||||
info:
|
||||
title: Sample API to test generation of schemas with uniqueItems arrays of enums
|
||||
description: API description in Markdown.
|
||||
version: 1.0.0
|
||||
servers: []
|
||||
paths: {}
|
||||
components:
|
||||
schemas:
|
||||
GetUsersRequestV1:
|
||||
type: object
|
||||
properties:
|
||||
roles:
|
||||
uniqueItems: true
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
enum:
|
||||
- ROLE1
|
||||
- ROLE2
|
Loading…
x
Reference in New Issue
Block a user