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 @@ -753,7 +753,7 @@ public String getTypeDeclaration(Schema p) {
Schema inner = ModelUtils.getSchemaItems(p);
return ModelUtils.isSet(p) ? "Set<" + getTypeDeclaration(inner) + ">" : "[" + getTypeDeclaration(inner) + "]";
} else if (ModelUtils.isMapSchema(p)) {
Schema inner = ModelUtils.getAdditionalProperties(p);
Schema inner = unaliasSchema(ModelUtils.getAdditionalProperties(p));
return "[String: " + getItemsTypeDeclaration(inner) + "]";
}
return super.getTypeDeclaration(p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
import org.openapitools.codegen.DefaultCodegen;
import org.openapitools.codegen.TestUtils;
import org.openapitools.codegen.languages.Swift6ClientCodegen;
import org.openapitools.codegen.utils.ModelUtils;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.util.Map;

@SuppressWarnings("static-method")
public class Swift6ClientCodegenModelTest {

Expand Down Expand Up @@ -163,4 +166,26 @@ public void useCustomDateTimeTest() {
Assert.assertFalse(property7.isContainer);
}

@Test(description = "nested map via $ref should resolve to [String: [String: String]], not [String: Dictionary]", enabled = true)
public void nestedMapRefTypeTest() {
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/swift6_nested_map.yaml");
final Swift6ClientCodegen codegen = new Swift6ClientCodegen();
codegen.setOpenAPI(openAPI);
codegen.processOpts();

Map<String, Schema> schemas = ModelUtils.getSchemas(openAPI);
Schema emailTemplateSchema = schemas.get("EmailTemplate");
Assert.assertNotNull(emailTemplateSchema, "EmailTemplate schema should exist");

final CodegenModel cm = codegen.fromModel("EmailTemplate", emailTemplateSchema);

CodegenProperty translationProp = cm.vars.stream()
.filter(p -> p.baseName.equals("translationOverridesByLocale"))
.findFirst().orElse(null);
Assert.assertNotNull(translationProp, "translationOverridesByLocale property should exist");
// Must be [String: [String: String]], NOT [String: Dictionary]
Assert.assertEquals(translationProp.dataType, "[String: [String: String]]",
"Nested map via $ref should resolve to [String: [String: String]]");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
openapi: 3.0.0
info:
title: Nested Map Type Test
version: 1.0.0
paths: {}
components:
schemas:
StringMap:
type: object
additionalProperties:
type: string
description: A map of string to string
EmailTemplate:
type: object
required:
- id
- ejs
properties:
id:
type: string
ejs:
type: string
translationOverridesByLocale:
$ref: '#/components/schemas/NestedStringMap'
NestedStringMap:
type: object
additionalProperties:
$ref: '#/components/schemas/StringMap'
description: A map of string to map of string to string
Loading