[Java] Fix compilation for Map of InnerEnum (#19401)

This commit is contained in:
Bragolgirith 2024-11-24 17:40:44 +01:00 committed by GitHub
parent cdafa5a0cc
commit 8ce332a540
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 60 additions and 1 deletions

View File

@ -4323,7 +4323,7 @@ public class DefaultCodegen implements CodegenConfig {
if (baseItem != null) {
// set both datatype and datetypeWithEnum as only the inner type is enum
property.datatypeWithEnum = property.datatypeWithEnum.replace(", " + baseItem.baseType, ", " + toEnumName(baseItem));
property.datatypeWithEnum = property.datatypeWithEnum.replace(baseItem.baseType + ">", toEnumName(baseItem) + ">");
// naming the enum with respect to the language enum naming convention
// e.g. remove [], {} from array/map of enum

View File

@ -2317,6 +2317,25 @@ public class JavaClientCodegenTest {
.bodyContainsLines("if (b.value.equals(value)) {");
}
@Test
public void testMapOfInnerEnum_issue19393() {
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_19393_map_of_inner_enum.yaml");
final JavaClientCodegen codegen = new JavaClientCodegen();
codegen.setOpenAPI(openAPI);
codegen.setOutputDir(newTempFolder().toString());
Map<String, File> files = new DefaultGenerator().opts(new ClientOptInput().openAPI(openAPI).config(codegen))
.generate().stream().collect(Collectors.toMap(File::getName, Function.identity()));
JavaFileAssert.assertThat(files.get("EmployeeWithMapOfEnum.java"))
.assertProperty("projectRole")
.withType("Map<String, InnerEnum>");
JavaFileAssert.assertThat(files.get("EmployeeWithMultiMapOfEnum.java"))
.assertProperty("projectRoles")
.withType("Map<String, Set<InnerEnum>>");
}
@Test
public void testWebClientResponseTypeWithUseAbstractionForFiles_issue16589() {
final Path output = newTempFolder();

View File

@ -0,0 +1,40 @@
openapi: 3.0.0
info:
version: 1.0.0
title: OpenAPI Test API
license:
name: Apache-2.0
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
paths:
/status:
get:
responses:
'200':
description: desc
components:
schemas:
EmployeeWithMapOfEnum:
type: object
properties:
projectRole:
type: object
additionalProperties:
type: string
enum:
- DEVELOPER
- TESTER
- OWNER
EmployeeWithMultiMapOfEnum:
type: object
properties:
projectRoles:
type: object
additionalProperties:
uniqueItems: true
type: array
items:
type: string
enum:
- DEVELOPER
- TESTER
- OWNER