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

Commit 2c670a3

Browse files
authored
fix invalid custom generated issue (#864)
* fix invalid custom * fix #861 * fix test
1 parent 5ab34ef commit 2c670a3

2 files changed

Lines changed: 43 additions & 38 deletions

File tree

  • src/generate/renders/generated
  • test/scenarios/managed-network/output/src/managed-network/azext_managed_network/generated

src/generate/renders/generated/CliCustom.ts

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -388,48 +388,42 @@ function ConstructValuation(
388388
defaultValue: string = null,
389389
needIfClause = true,
390390
): string[] {
391-
let str = [];
392-
if (isNullOrUndefined(defaultValue)) {
393-
let left = '';
394-
if (isGeneric) {
395-
if (value.startsWith("'") && value.endsWith("'")) {
396-
left = prefix + GetInstancePath(model, required) + '.';
397-
} else {
398-
str.push(prefix + 'if ' + value + ' is not None:');
399-
left = prefix + ' ' + GetInstancePath(model, required) + '.';
400-
}
401-
for (let i = 1; i < classNames.length; ++i) {
402-
left = left + classNames[i] + '.';
403-
}
404-
left = left + paramName;
405-
} else {
406-
left = prefix + classNames[0];
407-
for (let i = 1; i < classNames.length; ++i) {
408-
left = left + "['" + classNames[i] + "']";
409-
}
391+
const str = [];
392+
let sentence = '';
393+
if (isGeneric) {
394+
if (
395+
!(value.startsWith("'") && value.endsWith("'")) &&
396+
!(value.startsWith('"') && value.endsWith('"'))
397+
) {
398+
str.push(prefix + 'if ' + value + ' is not None:');
399+
prefix += ' ';
400+
}
410401

411-
if (!isNullOrUndefined(paramName)) {
412-
left = left + "['" + paramName + "']";
413-
}
402+
sentence = prefix + GetInstancePath(model, required) + '.';
403+
for (let i = 1; i < classNames.length; ++i) {
404+
sentence += classNames[i] + '.';
405+
}
406+
sentence += paramName;
407+
} else {
408+
sentence = prefix + classNames[0];
409+
for (let i = 1; i < classNames.length; ++i) {
410+
sentence += "['" + classNames[i] + "']";
411+
}
412+
413+
if (!isNullOrUndefined(paramName)) {
414+
sentence += "['" + paramName + "']";
414415
}
415-
str.push(left + ' = ' + value);
416+
}
417+
418+
if (isNullOrUndefined(defaultValue)) {
419+
sentence += ' = ' + value;
416420
} else {
417-
let ifClause = '';
421+
sentence += ' = ' + defaultValue;
418422
if (needIfClause) {
419-
ifClause = ' if ' + value + ' is None else ' + value;
423+
sentence += ' if ' + value + ' is None else ' + value;
420424
}
421-
str = str.concat(
422-
ConstructValuation(
423-
model,
424-
required,
425-
isGeneric,
426-
prefix,
427-
classNames,
428-
paramName,
429-
defaultValue,
430-
) + ifClause,
431-
);
432425
}
426+
str.push(sentence);
433427
return str;
434428
}
435429

@@ -955,6 +949,12 @@ function GetSimpleCallItem(
955949
parameterHandler.Parameter_Type(param),
956950
);
957951
}
952+
} else if (param.required) {
953+
if (schemaHandler.Schema_Type(param.schema) === SchemaType.Object) {
954+
parameterPair = paramNamePython + '={}';
955+
} else {
956+
parameterPair = paramNamePython + '=None';
957+
}
958958
} else {
959959
parameterPair = paramNamePython + '=None';
960960
}
@@ -985,6 +985,12 @@ function GetSimpleCallItem(
985985
'=' +
986986
ToPythonString(paramDefaultValue, parameterHandler.Parameter_Type(param));
987987
}
988+
} else if (param.required) {
989+
if (schemaHandler.Schema_Type(param.schema) === SchemaType.Object) {
990+
parameterPair = paramNamePython + '={}';
991+
} else {
992+
parameterPair = paramNamePython + '=None';
993+
}
988994
} else {
989995
parameterPair = paramNamePython + '=None';
990996
}

test/scenarios/managed-network/output/src/managed-network/azext_managed_network/generated/custom.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,7 @@ def managed_network_mn_group_update(instance,
168168
no_wait=False):
169169
if location is not None:
170170
instance.location = location
171-
if "Connectivity" is not None:
172-
instance.kind = "Connectivity"
171+
instance.kind = "Connectivity"
173172
if management_groups is not None:
174173
instance.management_groups = management_groups
175174
if subscriptions is not None:

0 commit comments

Comments
 (0)