[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

@ -61,6 +61,7 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
protected String releaseNotes; protected String releaseNotes;
protected String tags; protected String tags;
protected String iconUri; protected String iconUri;
protected Set<String> paramNameReservedWords;
/** /**
* Constructs an instance of `PowerShellClientCodegen`. * Constructs an instance of `PowerShellClientCodegen`.
@ -452,6 +453,30 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
"true" "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( defaultIncludes = new HashSet<String>(Arrays.asList(
"Byte", "Byte",
"SByte", "SByte",
@ -937,7 +962,17 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
@Override @Override
public String toParamName(String name) { 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 @Override