Skip to content

Commit 3f88017

Browse files
[kotlin-spring] fix kotlin map nullable add test
1 parent 8cc743b commit 3f88017

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/AbstractKotlinCodegenTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,25 @@ public void handleInheritanceWithObjectTypeShouldNotBeAMap() {
383383
Assert.assertTrue(mapSchemaModel.isMap);
384384
}
385385

386+
@Test(description = "Issue #16501")
387+
public void testNullableMap() {
388+
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/kotlin/issue16501-nullable-map.yaml");
389+
390+
Schema test1 = openAPI.getComponents().getSchemas().get("NullMapNotNullMap");
391+
CodegenModel cm1 = codegen.fromModel("NullMapNotNullMap", test1);
392+
393+
// We need to postProcess the model for enums to be processed
394+
codegen.postProcessModels(createCodegenModelWrapper(cm1));
395+
396+
// Assert the enum default value is properly generated
397+
CodegenProperty nullableMap = cm1.vars.get(0);
398+
CodegenProperty notNullableMap = cm1.vars.get(1);
399+
CodegenProperty defaultMap = cm1.vars.get(2);
400+
Assert.assertEquals(nullableMap.getDataType(), "kotlin.collections.Map<kotlin.String, kotlin.String?>");
401+
Assert.assertEquals(notNullableMap.getDataType(), "kotlin.collections.Map<kotlin.String, kotlin.String>");
402+
Assert.assertEquals(defaultMap.getDataType(), "kotlin.collections.Map<kotlin.String, kotlin.String>");
403+
}
404+
386405
@Test
387406
public void handleUseJakartaEeTrue() {
388407
codegen.additionalProperties().put("useJakartaEe", true);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
openapi: 3.0.0
2+
info:
3+
title: 'Issue 16501 Nullable map'
4+
version: latest
5+
components:
6+
schemas:
7+
NullMapNotNullMap:
8+
properties:
9+
nullableMap:
10+
type: object
11+
additionalProperties:
12+
type: string
13+
nullable: true
14+
notNullableMap:
15+
type: object
16+
additionalProperties:
17+
type: string
18+
nullable: false
19+
defaultMap:
20+
type: object
21+
additionalProperties:
22+
type: string

0 commit comments

Comments
 (0)