[REQ][PowerShell] Add additional reserved words list for parameter name in PowerShell (#8935)

* Add additional reserved words list for parameter name in PowerShell

Signed-off-by: SimeonGerginov <simeongerginov1@gmail.com>

* Add missing check for parameter name starting with number

Signed-off-by: SimeonGerginov <simeongerginov1@gmail.com>
This commit is contained in:
SimeonGerginov 2021-03-12 06:35:51 +02:00 committed by GitHub
parent e16ee8c6b8
commit 030cabc1cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,7 +60,8 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
protected String licenseUri;
protected String releaseNotes;
protected String tags;
protected String iconUri;
protected String iconUri;
protected Set<String> paramNameReservedWords;
/**
* Constructs an instance of `PowerShellClientCodegen`.
@ -415,7 +416,7 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
"local",
"private",
"where",
// special variables
// special variables
"args",
"consolefilename",
"error",
@ -452,6 +453,30 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
"true"
));
paramNameReservedWords = new HashSet<String>(Arrays.asList(
"args",
"error",
"executioncontext",
"false",
"home",
"host",
"input",
"myinvocation",
"nestedpromptlevel",
"null",
"pid",
"profile",
"pscommandpath",
"psculture",
"pshome",
"psscriptroot",
"psuiculture",
"psversiontable",
"shellid",
"stacktrace",
"true"
));
defaultIncludes = new HashSet<String>(Arrays.asList(
"Byte",
"SByte",
@ -639,7 +664,7 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
} else {
additionalProperties.put("skipVerbParsing", skipVerbParsing);
}
if (additionalProperties.containsKey("tags")) {
String[] entries = ((String) additionalProperties.get("tags")).split(",");
String prefix = "";
@ -937,7 +962,17 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
@Override
public String toParamName(String name) {
return toVarName(name);
// sanitize and camelize parameter name
// pet_id => PetId
name = camelize(sanitizeName(name));
// for param name reserved word or word starting with number, append _
if (paramNameReservedWords.contains(name) || name.matches("^\\d.*")) {
LOGGER.warn(name + " (reserved word or special variable name) cannot be used in naming. Renamed to " + escapeReservedWord(name));
name = escapeReservedWord(name);
}
return name;
}
@Override