Skip to content

[Java] Fix compilation error for a Map<String, Set<InnerEnum>> due to incompatible types #19401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading