Skip to content

Commit 671d2f4

Browse files
wizwozdjankows
authored andcommitted
fix issue with inner enums
1 parent 50363e4 commit 671d2f4

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1948,7 +1948,7 @@ protected void updateDataTypeWithEnumForMap(CodegenProperty property) {
19481948

19491949
if (baseItem != null) {
19501950
// set both datatype and datetypeWithEnum as only the inner type is enum
1951-
property.datatypeWithEnum = property.datatypeWithEnum.replace(", " + baseItem.baseType, ", " + toEnumName(baseItem));
1951+
property.datatypeWithEnum = property.datatypeWithEnum.replace(baseItem.baseType + ">", toEnumName(baseItem) + ">");
19521952

19531953
// naming the enum with respect to the language enum naming convention
19541954
// e.g. remove [], {} from array/map of enum

src/test/java/io/swagger/codegen/v3/generators/java/JavaClientCodegenTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,4 +343,20 @@ public void checkOneOfModelCreation() {
343343

344344
Assert.assertTrue(hasComposedModel);
345345
}
346+
347+
@Test
348+
public void testMapOfInnerEnum() {
349+
final OpenAPI openAPI = getOpenAPI("3_0_0/map_of_inner_enum.yaml");
350+
final JavaClientCodegen config = new JavaClientCodegen();
351+
final CodegenWrapper codegenWrapper = processSchemas(config, openAPI);
352+
353+
final Map<String, CodegenModel> codegenModels = codegenWrapper.getAllModels();
354+
355+
final CodegenModel employeeWithMapOfEnum = codegenModels.get("EmployeeWithMapOfEnum");
356+
Assert.assertEquals(employeeWithMapOfEnum.vars.get(0).datatypeWithEnum, "Map<String, InnerEnum>");
357+
358+
final CodegenModel employeeWithMultiMapOfEnum = codegenModels.get("EmployeeWithMultiMapOfEnum");
359+
Assert.assertEquals(employeeWithMultiMapOfEnum.vars.get(0).datatypeWithEnum, "Map<String, List<InnerEnum>>");
360+
361+
}
346362
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
openapi: 3.0.0
2+
info:
3+
version: 1.0.0
4+
title: OpenAPI Test API
5+
license:
6+
name: Apache-2.0
7+
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
8+
paths:
9+
/status:
10+
get:
11+
responses:
12+
'200':
13+
description: desc
14+
components:
15+
schemas:
16+
EmployeeWithMapOfEnum:
17+
type: object
18+
properties:
19+
projectRole:
20+
type: object
21+
additionalProperties:
22+
type: string
23+
enum:
24+
- DEVELOPER
25+
- TESTER
26+
- OWNER
27+
EmployeeWithMultiMapOfEnum:
28+
type: object
29+
properties:
30+
projectRoles:
31+
type: object
32+
additionalProperties:
33+
uniqueItems: true
34+
type: array
35+
items:
36+
type: string
37+
enum:
38+
- DEVELOPER
39+
- TESTER
40+
- OWNER

0 commit comments

Comments
 (0)