Skip to content
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 @@ -754,11 +754,17 @@ public String getTypeDeclaration(Schema p) {
return ModelUtils.isSet(p) ? "Set<" + getTypeDeclaration(inner) + ">" : "[" + getTypeDeclaration(inner) + "]";
} else if (ModelUtils.isMapSchema(p)) {
Schema inner = ModelUtils.getAdditionalProperties(p);
return "[String: " + getTypeDeclaration(inner) + "]";
return "[String: " + getItemsTypeDeclaration(inner) + "]";
}
return super.getTypeDeclaration(p);
}

private String getItemsTypeDeclaration(Schema items) {
String itemsTypeDeclaration = getTypeDeclaration(items);
String nullable = items.getNullable() != null && items.getNullable() && !itemsTypeDeclaration.endsWith("?") ? "?" : "";
return itemsTypeDeclaration + nullable;
}

@Override
public String getSchemaType(Schema p) {
String openAPIType = super.getSchemaType(p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.media.Schema;
import org.openapitools.codegen.*;
import org.openapitools.codegen.config.CodegenConfigurator;
import org.openapitools.codegen.languages.Swift6ClientCodegen;
Expand Down Expand Up @@ -401,4 +402,20 @@ public void oneOfDiscriminatorFirstDecodingTest() throws IOException {
output.deleteOnExit();
}
}

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

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

// 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(), "[String: String?]");
Assert.assertEquals(notNullableMap.getDataType(), "[String: String]");
Assert.assertEquals(defaultMap.getDataType(), "[String: String]");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
openapi: 3.0.0
info:
title: 'Issue 17996 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
Loading