Skip to content

Commit

Permalink
[Java] Fix compilation for Map of InnerEnum (#19401)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bragolgirith authored Nov 24, 2024
1 parent cdafa5a commit 8ce332a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4323,7 +4323,7 @@ protected void updateDataTypeWithEnumForMap(CodegenProperty property) {

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2317,6 +2317,25 @@ public void testEnumCaseSensitive_issue8084() {
.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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8ce332a

Please sign in to comment.