File tree Expand file tree Collapse file tree
modules/openapi-generator/src
main/java/org/openapitools/codegen/languages
java/org/openapitools/codegen/swift6 Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -754,11 +754,17 @@ public String getTypeDeclaration(Schema p) {
754754 return ModelUtils .isSet (p ) ? "Set<" + getTypeDeclaration (inner ) + ">" : "[" + getTypeDeclaration (inner ) + "]" ;
755755 } else if (ModelUtils .isMapSchema (p )) {
756756 Schema inner = ModelUtils .getAdditionalProperties (p );
757- return "[String: " + getTypeDeclaration (inner ) + "]" ;
757+ return "[String: " + getItemsTypeDeclaration (inner ) + "]" ;
758758 }
759759 return super .getTypeDeclaration (p );
760760 }
761761
762+ private String getItemsTypeDeclaration (Schema items ) {
763+ String itemsTypeDeclaration = getTypeDeclaration (items );
764+ String nullable = items .getNullable () != null && items .getNullable () && !itemsTypeDeclaration .endsWith ("?" ) ? "?" : "" ;
765+ return itemsTypeDeclaration + nullable ;
766+ }
767+
762768 @ Override
763769 public String getSchemaType (Schema p ) {
764770 String openAPIType = super .getSchemaType (p );
Original file line number Diff line number Diff line change 1919
2020import io .swagger .v3 .oas .models .OpenAPI ;
2121import io .swagger .v3 .oas .models .Operation ;
22+ import io .swagger .v3 .oas .models .media .Schema ;
2223import org .openapitools .codegen .*;
2324import org .openapitools .codegen .config .CodegenConfigurator ;
2425import org .openapitools .codegen .languages .Swift6ClientCodegen ;
@@ -401,4 +402,20 @@ public void oneOfDiscriminatorFirstDecodingTest() throws IOException {
401402 output .deleteOnExit ();
402403 }
403404 }
405+
406+ @ Test (description = "Issue #17996" )
407+ public void testNullableMap () {
408+ final OpenAPI openAPI = TestUtils .parseFlattenSpec ("src/test/resources/3_0/swift6/issue17996-nullable-map.yaml" );
409+
410+ Schema test1 = openAPI .getComponents ().getSchemas ().get ("NullMapNotNullMap" );
411+ CodegenModel cm1 = swiftCodegen .fromModel ("NullMapNotNullMap" , test1 );
412+
413+ // Assert the dataType properly generated
414+ CodegenProperty nullableMap = cm1 .vars .get (0 );
415+ CodegenProperty notNullableMap = cm1 .vars .get (1 );
416+ CodegenProperty defaultMap = cm1 .vars .get (2 );
417+ Assert .assertEquals (nullableMap .getDataType (), "[String: String?]" );
418+ Assert .assertEquals (notNullableMap .getDataType (), "[String: String]" );
419+ Assert .assertEquals (defaultMap .getDataType (), "[String: String]" );
420+ }
404421}
Original file line number Diff line number Diff line change 1+ openapi : 3.0.0
2+ info :
3+ title : ' Issue 17996 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
You can’t perform that action at this time.
0 commit comments