forked from loafle/openapi-generator-original
[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:
parent
e16ee8c6b8
commit
030cabc1cc
@ -60,7 +60,8 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
protected String licenseUri;
|
protected String licenseUri;
|
||||||
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`.
|
||||||
@ -415,7 +416,7 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
"local",
|
"local",
|
||||||
"private",
|
"private",
|
||||||
"where",
|
"where",
|
||||||
// special variables
|
// special variables
|
||||||
"args",
|
"args",
|
||||||
"consolefilename",
|
"consolefilename",
|
||||||
"error",
|
"error",
|
||||||
@ -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",
|
||||||
@ -639,7 +664,7 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
} else {
|
} else {
|
||||||
additionalProperties.put("skipVerbParsing", skipVerbParsing);
|
additionalProperties.put("skipVerbParsing", skipVerbParsing);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey("tags")) {
|
if (additionalProperties.containsKey("tags")) {
|
||||||
String[] entries = ((String) additionalProperties.get("tags")).split(",");
|
String[] entries = ((String) additionalProperties.get("tags")).split(",");
|
||||||
String prefix = "";
|
String prefix = "";
|
||||||
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user