Skip to content

Commit

Permalink
several generation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Zim Kalinowski committed Nov 3, 2019
1 parent a615150 commit f958360
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 35 deletions.
12 changes: 10 additions & 2 deletions AzureCli/CodeModelCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,16 @@ export class CodeModelCli
}
else if (moduleExample.Method == "get")
{
// XXX - could be list
example.Method = "show";
// maybe this should be done in a different way, but if url ends with
// variable it means we are looking for specific resource instance
if (moduleExample.Url.endsWith("}"))
{
example.Method = "show";
}
else
{
example.Method = "list";
}
}
else if (moduleExample.Method == "delete")
{
Expand Down
30 changes: 12 additions & 18 deletions AzureCli/TemplateAzureCliCustom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,11 @@ export function GenerateAzureCliCustom(model: CodeModelCli) : string[] {
parts.forEach(part => {
if (part != "" && part != "*")
{
if (!isUpdate)
{
access += ".setdefault('" + part + "', {})";
}
else
{
access += "." + part;
}
access += ".setdefault('" + part + "', {})";
}
});

if (!isUpdate)
{
access += "['" + last + "'] = ";
}
else
{
access += "." + last + " = ";
}
access += "['" + last + "'] = ";

if (element.IsList)
{
Expand All @@ -192,8 +178,16 @@ export function GenerateAzureCliCustom(model: CodeModelCli) : string[] {
{
access += "json.loads(" + PythonParameterName(element.Name) + ") if isinstance(" + PythonParameterName(element.Name) + ", str) else " + PythonParameterName(element.Name)
}

output_body.push(access);

if (isUpdate)
{
output_body.push(" if " + PythonParameterName(element.Name) + " is not None:");
output_body.push(" " + access);
}
else
{
output_body.push(access);
}
}
});
}
Expand Down
10 changes: 8 additions & 2 deletions dist/AzureCli/CodeModelCli.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,14 @@ class CodeModelCli {
example.Method = "update";
}
else if (moduleExample.Method == "get") {
// XXX - could be list
example.Method = "show";
// maybe this should be done in a different way, but if url ends with
// variable it means we are looking for specific resource instance
if (moduleExample.Url.endsWith("}")) {
example.Method = "show";
}
else {
example.Method = "list";
}
}
else if (moduleExample.Method == "delete") {
example.Method = "delete";
Expand Down
22 changes: 9 additions & 13 deletions dist/AzureCli/TemplateAzureCliCustom.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,10 @@ function GenerateAzureCliCustom(model) {
let last = parts.pop();
parts.forEach(part => {
if (part != "" && part != "*") {
if (!isUpdate) {
access += ".setdefault('" + part + "', {})";
}
else {
access += "." + part;
}
access += ".setdefault('" + part + "', {})";
}
});
if (!isUpdate) {
access += "['" + last + "'] = ";
}
else {
access += "." + last + " = ";
}
access += "['" + last + "'] = ";
if (element.IsList) {
if (element.Type != "dict") {
// a comma separated list
Expand All @@ -138,7 +128,13 @@ function GenerateAzureCliCustom(model) {
else {
access += "json.loads(" + PythonParameterName(element.Name) + ") if isinstance(" + PythonParameterName(element.Name) + ", str) else " + PythonParameterName(element.Name);
}
output_body.push(access);
if (isUpdate) {
output_body.push(" if " + PythonParameterName(element.Name) + " is not None:");
output_body.push(" " + access);
}
else {
output_body.push(access);
}
}
});
}
Expand Down

0 comments on commit f958360

Please sign in to comment.