Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
better common verb handling
  • Loading branch information
wing328 committed Apr 1, 2020
commit ef7443e1c45e0efa33b8339ba30dc99bcea320a6
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class PowerShellExperimentalClientCodegen extends DefaultCodegen implemen
protected String powershellGalleryUrl;
protected HashSet powershellVerbs;
protected Map<String, String> commonVerbs; // verbs not in the official ps verb list but can be mapped to one of the verbs
protected HashSet methodNames;

/**
* Constructs an instance of `PowerShellExperimentalClientCodegen`.
Expand Down Expand Up @@ -123,9 +124,138 @@ public PowerShellExperimentalClientCodegen() {
));

commonVerbs = new HashMap<String, String>();
commonVerbs.put("Create", "New");

Map<String, List<String>> verbMappings = new HashMap<String, List<String>>();

// common
verbMappings.put("Add", Arrays.asList("Append", "Attach", "Concatenate", "Insert"));
verbMappings.put("Clear", Arrays.asList("Flush", "Erase", "Release", "Unmark", "Unset", "Nullify"));
verbMappings.put("Close", Arrays.asList());
verbMappings.put("Copy", Arrays.asList("Duplicate", "Clone", "Replicate", "Sync"));
verbMappings.put("Enter", Arrays.asList("PushInto"));
verbMappings.put("Exit", Arrays.asList("PopOut"));
verbMappings.put("Find", Arrays.asList());
verbMappings.put("Format", Arrays.asList());
verbMappings.put("Get", Arrays.asList("Read", "Open", "Cat", "Type", "Dir", "Obtain", "Dump", "Acquire", "Examine", "Find", "Search"));
verbMappings.put("Hide", Arrays.asList("Block"));
verbMappings.put("Join", Arrays.asList("Combine", "Unite", "Connect", "Associate"));
verbMappings.put("Lock", Arrays.asList("RestrictSecure"));
verbMappings.put("Move", Arrays.asList("Transfer", "Name", "Migrate"));
verbMappings.put("New", Arrays.asList("Create", "Generate", "Build", "Make", "Allocate"));
verbMappings.put("Open", Arrays.asList());
verbMappings.put("Optimize", Arrays.asList());
verbMappings.put("Pop", Arrays.asList());
verbMappings.put("Push", Arrays.asList());
verbMappings.put("Redo", Arrays.asList());
verbMappings.put("Remove", Arrays.asList("Clear", "Cut", "Dispose", "Discard", "Erase"));
verbMappings.put("Rename", Arrays.asList("Change"));
verbMappings.put("Reset", Arrays.asList());
verbMappings.put("Search", Arrays.asList("FindLocate"));
verbMappings.put("Select", Arrays.asList("FindLocate"));
verbMappings.put("Set", Arrays.asList("Write", "Reset", "Assign", "Configure"));
verbMappings.put("Show", Arrays.asList("DisplayProduce"));
verbMappings.put("Skip", Arrays.asList("BypassJump"));
verbMappings.put("Split", Arrays.asList("parate"));
verbMappings.put("Step", Arrays.asList());
verbMappings.put("Switch", Arrays.asList());
verbMappings.put("Undo", Arrays.asList());
verbMappings.put("Unlock", Arrays.asList("Release", "Unrestrict", "Unsecure"));
verbMappings.put("Watch", Arrays.asList());

// communication
verbMappings.put("Connect", Arrays.asList("JoinTelnet"));
verbMappings.put("Disconnect", Arrays.asList("BreakLogoff"));
verbMappings.put("Read", Arrays.asList("Acquire", "Prompt", "Get"));
verbMappings.put("Receive", Arrays.asList("Read", "Accept", "Peek"));
verbMappings.put("Send", Arrays.asList("Put", "Broadcast", "Mail", "Fax"));
verbMappings.put("Write", Arrays.asList("PutPrint"));

// data
verbMappings.put("Backup", Arrays.asList(" Save", " Burn", " Replicate", "Sync"));
verbMappings.put("Checkpoint", Arrays.asList(" Diff"));
verbMappings.put("Compare", Arrays.asList(" Diff"));
verbMappings.put("Compress", Arrays.asList(" Compact"));
verbMappings.put("Convert", Arrays.asList(" Change", " Resize", "Resample"));
verbMappings.put("ConvertFrom", Arrays.asList(" Export", " Output", "Out"));
verbMappings.put("ConvertTo", Arrays.asList(" Import", " Input", "In"));
verbMappings.put("Dismount", Arrays.asList(" UnmountUnlink"));
verbMappings.put("Edit", Arrays.asList(" Change", " Update", "Modify"));
verbMappings.put("Expand", Arrays.asList(" ExplodeUncompress"));
verbMappings.put("Export", Arrays.asList(" ExtractBackup"));
verbMappings.put("Group", Arrays.asList(" Aggregate", " Arrange", " Associate", "Correlate"));
verbMappings.put("Import", Arrays.asList(" BulkLoadLoad"));
verbMappings.put("Initialize", Arrays.asList(" Erase", " Init", " Renew", " Rebuild", " Reinitialize", "Setup"));
verbMappings.put("Limit", Arrays.asList(" Quota"));
verbMappings.put("Merge", Arrays.asList(" CombineJoin"));
verbMappings.put("Mount", Arrays.asList(" Connect"));
verbMappings.put("Out", Arrays.asList());
verbMappings.put("Publish", Arrays.asList(" Deploy", " Release", "Install"));
verbMappings.put("Restore", Arrays.asList(" Repair", " Return", " Undo", "Fix"));
verbMappings.put("Save", Arrays.asList());
verbMappings.put("Sync", Arrays.asList(" Replicate", " Coerce", "Match"));
verbMappings.put("Unpublish", Arrays.asList(" Uninstall", " Revert", "Hide"));
verbMappings.put("Update", Arrays.asList(" Refresh", " Renew", " Recalculate", "Re-index"));

// diagnostic
verbMappings.put("Debug", Arrays.asList("Diagnose"));
verbMappings.put("Measure", Arrays.asList("Calculate", "Determine", "Analyze"));
verbMappings.put("Ping", Arrays.asList());
verbMappings.put("Repair", Arrays.asList("FixRestore"));
verbMappings.put("Resolve", Arrays.asList("ExpandDetermine"));
verbMappings.put("Test", Arrays.asList("Diagnose", "Analyze", "Salvage", "Verify"));
verbMappings.put("Trace", Arrays.asList("Track", "Follow", "Inspect", "Dig"));

// lifecycle
verbMappings.put("Approve", Arrays.asList());
verbMappings.put("Assert", Arrays.asList("Certify"));
verbMappings.put("Build", Arrays.asList());
verbMappings.put("Complete", Arrays.asList());
verbMappings.put("Confirm", Arrays.asList("Acknowledge", "Agree", "Certify", "Validate", "Verify"));
verbMappings.put("Deny", Arrays.asList("Block", "Object", "Refuse", "Reject"));
verbMappings.put("Deploy", Arrays.asList());
verbMappings.put("Disable", Arrays.asList("HaltHide"));
verbMappings.put("Enable", Arrays.asList("StartBegin"));
verbMappings.put("Install", Arrays.asList("Setup"));
verbMappings.put("Invoke", Arrays.asList("RunStart"));
verbMappings.put("Register", Arrays.asList());
verbMappings.put("Request", Arrays.asList());
verbMappings.put("Restart", Arrays.asList("Recycle"));
verbMappings.put("Resume", Arrays.asList());
verbMappings.put("Start", Arrays.asList("Launch", "Initiate", "Boot"));
verbMappings.put("Stop", Arrays.asList("End", "Kill", "Terminate", "Cancel"));
verbMappings.put("Submit", Arrays.asList("Post"));
verbMappings.put("Suspend", Arrays.asList("Pause"));
verbMappings.put("Uninstall", Arrays.asList());
verbMappings.put("Unregister", Arrays.asList("Remove"));
verbMappings.put("Wait", Arrays.asList("SleepPause"));

// security
verbMappings.put("Block", Arrays.asList("Prevent", "Limit", "Deny"));
verbMappings.put("Grant", Arrays.asList("AllowEnable"));
verbMappings.put("Protect", Arrays.asList("Encrypt", "Safeguard", "Seal"));
verbMappings.put("Revoke", Arrays.asList("RemoveDisable"));
verbMappings.put("Unblock", Arrays.asList("ClearAllow"));
verbMappings.put("Unprotect", Arrays.asList("DecryptUnseal"));

// other
verbMappings.put("Use", Arrays.asList());

for (Map.Entry<String, List<String>> entry : verbMappings.entrySet()) {
// loop through each verb in the list
for (String verb : entry.getValue()) {
LOGGER.debug("processing: {}", verb);

if (verbMappings.containsKey(verb)) {
// the verb to be mapped is also a common verb, do nothing
} else {
commonVerbs.put(verb, entry.getKey());
LOGGER.debug("verbmapping: adding {} => {}", verb, entry.getKey());
}
}
}

// additional common verbs mapping
commonVerbs.put("Delete", "Remove");
commonVerbs.put("Update", "Set");

powershellVerbs = new HashSet<String>(Arrays.asList(
"Add",
Expand Down Expand Up @@ -229,6 +359,7 @@ public PowerShellExperimentalClientCodegen() {
"Use"
));

methodNames = new HashSet<String>();

nullablePrimitives = new HashSet<String>(Arrays.asList(
"System.Nullable[Byte]",
Expand Down Expand Up @@ -280,7 +411,6 @@ public PowerShellExperimentalClientCodegen() {
"Where"
));


defaultIncludes = new HashSet<String>(Arrays.asList(
"Byte",
"SByte",
Expand Down Expand Up @@ -648,6 +778,13 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
} else {
op.vendorExtensions.put("x-powershell-method-name-lowercase", ((String) op.vendorExtensions.get("x-powershell-method-name")).toLowerCase(Locale.ROOT));
}

// detect duplicated method name
if (methodNames.contains(op.vendorExtensions.get("x-powershell-method-name"))) {
LOGGER.error("Duplicated method name found: {}", op.vendorExtensions.get("x-powershell-method-name"));
} else {
methodNames.add(op.vendorExtensions.get("x-powershell-method-name"));
}
}

processedModelMaps.clear();
Expand Down