Skip to content
Open
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 @@ -394,7 +394,7 @@ public String getTypeDeclaration(Schema p) {
inner = new StringSchema().description("TODO default missing map inner type to string");
p.setAdditionalProperties(inner);
}
return getSchemaType(target) + "<kotlin.String, " + getTypeDeclaration(inner) + ">";
return getSchemaType(target) + "<kotlin.String, " + getItemsTypeDeclaration(inner) + ">";
}
return super.getTypeDeclaration(target);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,24 @@ public void handleInheritanceWithObjectTypeShouldNotBeAMap() {
Assert.assertTrue(mapSchemaModel.isMap);
}

@Test(description = "Issue #16501")
public void testNullableMap() {
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/kotlin/issue16501-nullable-map.yaml");

Schema test1 = openAPI.getComponents().getSchemas().get("NullMapNotNullMap");
CodegenModel cm1 = codegen.fromModel("NullMapNotNullMap", test1);

codegen.postProcessModels(createCodegenModelWrapper(cm1));

// Assert the dataType properly generated
CodegenProperty nullableMap = cm1.vars.get(0);
CodegenProperty notNullableMap = cm1.vars.get(1);
CodegenProperty defaultMap = cm1.vars.get(2);
Assert.assertEquals(nullableMap.getDataType(), "kotlin.collections.Map<kotlin.String, kotlin.String?>");
Assert.assertEquals(notNullableMap.getDataType(), "kotlin.collections.Map<kotlin.String, kotlin.String>");
Assert.assertEquals(defaultMap.getDataType(), "kotlin.collections.Map<kotlin.String, kotlin.String>");
}

@Test
public void handleUseJakartaEeTrue() {
codegen.additionalProperties().put("useJakartaEe", true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
openapi: 3.0.0
info:
title: 'Issue 16501 Nullable map'
version: latest
components:
schemas:
NullMapNotNullMap:
properties:
nullableMap:
type: object
additionalProperties:
type: string
nullable: true
notNullableMap:
type: object
additionalProperties:
type: string
nullable: false
defaultMap:
type: object
additionalProperties:
type: string