Skip to content

Commit

Permalink
[Java] Fix compilation for a map of enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Bragolgirith committed Aug 24, 2024
1 parent c2472b0 commit 940cab5
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4275,7 +4275,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 @@ -2203,6 +2203,23 @@ public void shouldNotAddAdditionalModelAnnotationsToAbstractOpenApiSchema_issue1
.bodyContainsLines("if (b.value.equals(value)) {");
}

@Test public void testMapOfEnum_issue19393() {
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_19393_map_of_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("Employee.java"))
.assertProperty("projectRole")
.withType("Map<String, InnerEnum>")
.toType()
.assertProperty("projectRoles")
.withType("Map<String, Set<InnerEnum>>");
}

@Test public void testWebClientResponseTypeWithUseAbstractionForFiles_issue16589() {
final Path output = newTempFolder();
final CodegenConfigurator configurator = new CodegenConfigurator()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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:
/employees/{employeeId}:
put:
operationId: updateEmployee
parameters:
- name: employeeId
in: path
required: true
schema:
type: string
format: uuid
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Employee'
required: true
responses:
'200':
description: OK
components:
schemas:
Employee:
type: object
properties:
projectRole:
type: object
additionalProperties:
type: string
enum:
- DEVELOPER
- TESTER
- OWNER
projectRoles:
type: object
additionalProperties:
uniqueItems: true
type: array
items:
type: string
enum:
- DEVELOPER
- TESTER
- OWNER

0 comments on commit 940cab5

Please sign in to comment.