diff --git a/bin/configs/swift5-nonPublicApi.yaml b/bin/configs/swift5-nonPublicApi.yaml index 1aec2c3bb165..886c9a99c936 100644 --- a/bin/configs/swift5-nonPublicApi.yaml +++ b/bin/configs/swift5-nonPublicApi.yaml @@ -10,3 +10,12 @@ additionalProperties: nonPublicApi: true projectName: PetstoreClient podHomepage: https://github.com/openapitools/openapi-generator +nameMappings: + _type: underscoreType + type_: typeWithUnderscore + -type: dashType +parameterNameMappings: + _type: underscoreType + type_: typeWithUnderscore + -type: dashType + diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift5ClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift5ClientCodegen.java index 76535094fe3c..5ae17d212c1f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift5ClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift5ClientCodegen.java @@ -300,24 +300,24 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig .defaultValue(Boolean.FALSE.toString())); cliOptions.add(new CliOption(HASHABLE_MODELS, - "Make hashable models (default: true)") - .defaultValue(Boolean.TRUE.toString())); + "Make hashable models (default: true)") + .defaultValue(Boolean.TRUE.toString())); cliOptions.add(new CliOption(USE_JSON_ENCODABLE, - "Make models conform to JSONEncodable protocol (default: true)") - .defaultValue(Boolean.TRUE.toString())); + "Make models conform to JSONEncodable protocol (default: true)") + .defaultValue(Boolean.TRUE.toString())); cliOptions.add(new CliOption(MAP_FILE_BINARY_TO_DATA, - "[WARNING] This option will be removed and enabled by default in the future once we've enhanced the code to work with `Data` in all the different situations. Map File and Binary to Data (default: false)") - .defaultValue(Boolean.FALSE.toString())); + "[WARNING] This option will be removed and enabled by default in the future once we've enhanced the code to work with `Data` in all the different situations. Map File and Binary to Data (default: false)") + .defaultValue(Boolean.FALSE.toString())); cliOptions.add(new CliOption(USE_CUSTOM_DATE_WITHOUT_TIME, - "Uses a custom type to decode and encode dates without time information to support OpenAPIs date format (default: false)") - .defaultValue(Boolean.FALSE.toString())); + "Uses a custom type to decode and encode dates without time information to support OpenAPIs date format (default: false)") + .defaultValue(Boolean.FALSE.toString())); cliOptions.add(new CliOption(VALIDATABLE, - "Make validation rules and validator for model properies (default: true)") - .defaultValue(Boolean.TRUE.toString())); + "Make validation rules and validator for model properies (default: true)") + .defaultValue(Boolean.TRUE.toString())); supportedLibraries.put(LIBRARY_URLSESSION, "[DEFAULT] HTTP client: URLSession"); supportedLibraries.put(LIBRARY_ALAMOFIRE, "HTTP client: Alamofire"); @@ -488,8 +488,8 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig sourceFolder = "Sources" + File.separator + projectName; } - if (additionalProperties.containsKey(SWIFT_PACKAGE_PATH) && ((String)additionalProperties.get(SWIFT_PACKAGE_PATH)).length() > 0) { - setSwiftPackagePath((String)additionalProperties.get(SWIFT_PACKAGE_PATH)); + if (additionalProperties.containsKey(SWIFT_PACKAGE_PATH) && ((String) additionalProperties.get(SWIFT_PACKAGE_PATH)).length() > 0) { + setSwiftPackagePath((String) additionalProperties.get(SWIFT_PACKAGE_PATH)); sourceFolder = swiftPackagePath; } @@ -593,16 +593,16 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig "OpenISO8601DateFormatter.swift")); if (useCustomDateWithoutTime) { supportingFiles.add(new SupportingFile("OpenAPIDateWithoutTime.mustache", - sourceFolder, - "OpenAPIDateWithoutTime.swift")); + sourceFolder, + "OpenAPIDateWithoutTime.swift")); } supportingFiles.add(new SupportingFile("APIs.mustache", sourceFolder, "APIs.swift")); if (validatable) { supportingFiles.add(new SupportingFile("Validation.mustache", - sourceFolder, - "Validation.swift")); + sourceFolder, + "Validation.swift")); } supportingFiles.add(new SupportingFile("gitignore.mustache", "", @@ -862,6 +862,11 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig @Override public String toVarName(String name) { + // obtain the name from nameMapping directly if provided + if (nameMapping.containsKey(name)) { + return nameMapping.get(name); + } + // sanitize name name = sanitizeName(name); @@ -889,6 +894,11 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig @Override public String toParamName(String name) { + // obtain the name from parameterNameMapping directly if provided + if (parameterNameMapping.containsKey(name)) { + return parameterNameMapping.get(name); + } + // sanitize name name = sanitizeName(name); @@ -1243,7 +1253,7 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig OperationMap objectMap = objs.getOperations(); HashMap modelMaps = new HashMap<>(); - for (ModelMap modelMap: allModels) { + for (ModelMap modelMap : allModels) { CodegenModel m = modelMap.getModel(); modelMaps.put(m.classname, m); } @@ -1376,5 +1386,7 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig } @Override - public GeneratorLanguage generatorLanguage() { return GeneratorLanguage.SWIFT; } + public GeneratorLanguage generatorLanguage() { + return GeneratorLanguage.SWIFT; + } }