Implement optional powershell verb parsing (#8252)

* Implement optional powershell verb parsing #8233

* update doc

Co-authored-by: William Cheng <wing328hk@gmail.com>
This commit is contained in:
Wesley A
2021-01-07 10:41:43 +01:00
committed by GitHub
parent 1df719801e
commit f5b2bb5057
2 changed files with 26 additions and 13 deletions

View File

@@ -19,6 +19,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|powershellGalleryUrl|URL to the module in PowerShell Gallery (e.g. https://www.powershellgallery.com/packages/PSTwitter/).| |null|
|projectUri|A URL to the main website for this project| |null|
|releaseNotes|Release notes of the generated PowerShell module| |null|
|skipVerbParsing|Set skipVerbParsing to not try get powershell verbs of operation names| |null|
|tags|Tags applied to the generated PowerShell module. These help with module discovery in online galleries| |null|
|useOneOfDiscriminatorLookup|Use the discriminator's mapping in oneOf to speed up the model lookup. IMPORTANT: Validation (e.g. one and onlye one match in oneOf's schemas) will be skipped.| |null|

View File

@@ -55,6 +55,7 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
protected HashSet methodNames; // store a list of method names to detect duplicates
protected boolean useOneOfDiscriminatorLookup = false; // use oneOf discriminator's mapping for model lookup
protected boolean discardReadOnly = false; // Discard the readonly property in initialize cmdlet
protected boolean skipVerbParsing = false; // Attempt to parse cmdlets from operation names
protected String projectUri;
protected String licenseUri;
protected String releaseNotes;
@@ -511,6 +512,8 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
cliOptions.add(new CliOption("licenseUri","A URL to the license for the generated PowerShell module"));
cliOptions.add(new CliOption("iconUri","A URL to an icon representing the generated PowerShell module"));
cliOptions.add(new CliOption("releaseNotes","Release notes of the generated PowerShell module"));
cliOptions.add(new CliOption("skipVerbParsing", "Set skipVerbParsing to not try get powershell verbs of operation names"));
// option to change how we process + set the data in the 'additionalProperties' keyword.
CliOption disallowAdditionalPropertiesIfNotPresentOpt = CliOption.newBoolean(
CodegenConstants.DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT,
@@ -601,6 +604,7 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
this.iconUri = iconUri;
}
public void setSkipVerbParsing(boolean skipVerbParsing) { this.skipVerbParsing = skipVerbParsing; };
@Override
public void processOpts() {
@@ -628,7 +632,13 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
setDiscardReadOnly(convertPropertyToBooleanAndWriteBack("discardReadOnly"));
} else {
additionalProperties.put("discardReadOnly", discardReadOnly);
}
}
if (additionalProperties.containsKey("skipVerbParsing")) {
setSkipVerbParsing(convertPropertyToBoolean("skipVerbParsing"));
} else {
additionalProperties.put("skipVerbParsing", skipVerbParsing);
}
if (additionalProperties.containsKey("tags")) {
String[] entries = ((String) additionalProperties.get("tags")).split(",");
@@ -1212,20 +1222,22 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo
private String toMethodName(String operationId) {
String methodName = camelize(operationId);
// check if method name starts with powershell verbs
for (String verb : (HashSet<String>) powershellVerbs) {
if (methodName.startsWith(verb)) {
methodName = verb + "-" + apiNamePrefix + methodName.substring(verb.length());
LOGGER.info("Naming the method using the PowerShell verb: {} => {}", operationId, methodName);
return methodName;
if (!skipVerbParsing) {
// check if method name starts with powershell verbs
for (String verb : (HashSet<String>) powershellVerbs) {
if (methodName.startsWith(verb)) {
methodName = verb + "-" + apiNamePrefix + methodName.substring(verb.length());
LOGGER.info("Naming the method using the PowerShell verb: {} => {}", operationId, methodName);
return methodName;
}
}
}
for (Map.Entry<String, String> entry : commonVerbs.entrySet()) {
if (methodName.startsWith(entry.getKey())) {
methodName = entry.getValue() + "-" + apiNamePrefix + methodName.substring(entry.getKey().length());
LOGGER.info("Naming the method by mapping the common verbs (e.g. Create, Change) to PS verbs: {} => {}", operationId, methodName);
return methodName;
for (Map.Entry<String, String> entry : commonVerbs.entrySet()) {
if (methodName.startsWith(entry.getKey())) {
methodName = entry.getValue() + "-" + apiNamePrefix + methodName.substring(entry.getKey().length());
LOGGER.info("Naming the method by mapping the common verbs (e.g. Create, Change) to PS verbs: {} => {}", operationId, methodName);
return methodName;
}
}
}