Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Commit

Permalink
fix invalid custom generated issue (#864)
Browse files Browse the repository at this point in the history
* fix invalid custom

* fix #861

* fix test
  • Loading branch information
kairu-ms authored Jul 21, 2021
1 parent 5ab34ef commit 2c670a3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 38 deletions.
78 changes: 42 additions & 36 deletions src/generate/renders/generated/CliCustom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,48 +388,42 @@ function ConstructValuation(
defaultValue: string = null,
needIfClause = true,
): string[] {
let str = [];
if (isNullOrUndefined(defaultValue)) {
let left = '';
if (isGeneric) {
if (value.startsWith("'") && value.endsWith("'")) {
left = prefix + GetInstancePath(model, required) + '.';
} else {
str.push(prefix + 'if ' + value + ' is not None:');
left = prefix + ' ' + GetInstancePath(model, required) + '.';
}
for (let i = 1; i < classNames.length; ++i) {
left = left + classNames[i] + '.';
}
left = left + paramName;
} else {
left = prefix + classNames[0];
for (let i = 1; i < classNames.length; ++i) {
left = left + "['" + classNames[i] + "']";
}
const str = [];
let sentence = '';
if (isGeneric) {
if (
!(value.startsWith("'") && value.endsWith("'")) &&
!(value.startsWith('"') && value.endsWith('"'))
) {
str.push(prefix + 'if ' + value + ' is not None:');
prefix += ' ';
}

if (!isNullOrUndefined(paramName)) {
left = left + "['" + paramName + "']";
}
sentence = prefix + GetInstancePath(model, required) + '.';
for (let i = 1; i < classNames.length; ++i) {
sentence += classNames[i] + '.';
}
sentence += paramName;
} else {
sentence = prefix + classNames[0];
for (let i = 1; i < classNames.length; ++i) {
sentence += "['" + classNames[i] + "']";
}

if (!isNullOrUndefined(paramName)) {
sentence += "['" + paramName + "']";
}
str.push(left + ' = ' + value);
}

if (isNullOrUndefined(defaultValue)) {
sentence += ' = ' + value;
} else {
let ifClause = '';
sentence += ' = ' + defaultValue;
if (needIfClause) {
ifClause = ' if ' + value + ' is None else ' + value;
sentence += ' if ' + value + ' is None else ' + value;
}
str = str.concat(
ConstructValuation(
model,
required,
isGeneric,
prefix,
classNames,
paramName,
defaultValue,
) + ifClause,
);
}
str.push(sentence);
return str;
}

Expand Down Expand Up @@ -955,6 +949,12 @@ function GetSimpleCallItem(
parameterHandler.Parameter_Type(param),
);
}
} else if (param.required) {
if (schemaHandler.Schema_Type(param.schema) === SchemaType.Object) {
parameterPair = paramNamePython + '={}';
} else {
parameterPair = paramNamePython + '=None';
}
} else {
parameterPair = paramNamePython + '=None';
}
Expand Down Expand Up @@ -985,6 +985,12 @@ function GetSimpleCallItem(
'=' +
ToPythonString(paramDefaultValue, parameterHandler.Parameter_Type(param));
}
} else if (param.required) {
if (schemaHandler.Schema_Type(param.schema) === SchemaType.Object) {
parameterPair = paramNamePython + '={}';
} else {
parameterPair = paramNamePython + '=None';
}
} else {
parameterPair = paramNamePython + '=None';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ def managed_network_mn_group_update(instance,
no_wait=False):
if location is not None:
instance.location = location
if "Connectivity" is not None:
instance.kind = "Connectivity"
instance.kind = "Connectivity"
if management_groups is not None:
instance.management_groups = management_groups
if subscriptions is not None:
Expand Down

0 comments on commit 2c670a3

Please sign in to comment.