forked from loafle/openapi-generator-original
[Swift] property, parameter name mapping support (#16207)
* add property, parameter naming support to swift5 generator * revert change * remove files * update samples
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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<String, CodegenModel> 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user