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

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
changlong-liu committed May 20, 2021
1 parent 03d4897 commit fac6981
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 19 deletions.
28 changes: 18 additions & 10 deletions src/generate/codemodel/CodeModelAzImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,13 @@ export class CodeModelCliImpl implements CodeModelAz {
do {
if (
!paramRequired.has(
this.methodParameterHandler.MethodParameter_Name,
this.methodParameterHandler
.MethodParameter_FullParamPath,
)
) {
paramRequired.set(
this.methodParameterHandler.MethodParameter_Name,
this.methodParameterHandler
.MethodParameter_FullParamPath,
this.methodParameterHandler.MethodParameter_IsRequired
? 1
: 0,
Expand All @@ -207,9 +209,11 @@ export class CodeModelCliImpl implements CodeModelAz {
this.methodParameterHandler.MethodParameter_IsRequired
) {
paramRequired.set(
this.methodParameterHandler.MethodParameter_Name,
this.methodParameterHandler
.MethodParameter_FullParamPath,
paramRequired.get(
this.methodParameterHandler.MethodParameter_Name,
this.methodParameterHandler
.MethodParameter_FullParamPath,
) + 1,
);
}
Expand All @@ -221,11 +225,13 @@ export class CodeModelCliImpl implements CodeModelAz {
do {
if (
!paramRequired.has(
this.methodParameterHandler.MethodParameter_Name,
this.methodParameterHandler
.MethodParameter_FullParamPath,
)
) {
paramRequired.set(
this.methodParameterHandler.MethodParameter_Name,
this.methodParameterHandler
.MethodParameter_FullParamPath,
this.methodParameterHandler
.MethodParameter_IsRequired
? 1
Expand All @@ -235,10 +241,11 @@ export class CodeModelCliImpl implements CodeModelAz {
this.methodParameterHandler.MethodParameter_IsRequired
) {
paramRequired.set(
this.methodParameterHandler.MethodParameter_Name,
this.methodParameterHandler
.MethodParameter_FullParamPath,
paramRequired.get(
this.methodParameterHandler
.MethodParameter_Name,
.MethodParameter_FullParamPath,
) + 1,
);
}
Expand Down Expand Up @@ -276,7 +283,8 @@ export class CodeModelCliImpl implements CodeModelAz {
'RequiredByMethod'
] =
paramRequired.get(
this.methodParameterHandler.MethodParameter_Name,
this.methodParameterHandler
.MethodParameter_FullParamPath,
) === paramTime;
}
if (
Expand Down Expand Up @@ -322,7 +330,7 @@ export class CodeModelCliImpl implements CodeModelAz {
] =
paramRequired.get(
this.methodParameterHandler
.MethodParameter_Name,
.MethodParameter_NameAz,
) === paramTime;
}
if (
Expand Down
11 changes: 11 additions & 0 deletions src/generate/codemodel/MethodParameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface MethodParameterModel {
MethodParameter_PositionalKeys: string[];
MethodParameter_Features: Record<string, string | number>;
MethodParameter_Imports: Record<string, any>;
MethodParameter_FullParamPath: string;
}

export class MethodParameterModelImpl implements MethodParameterModel {
Expand Down Expand Up @@ -332,4 +333,14 @@ export class MethodParameterModelImpl implements MethodParameterModel {
public get MethodParameter_Imports(): Record<string, any> {
return this.MethodParameter.language['az']['imports'];
}

public get MethodParameter_FullParamPath(): string {
const parameter = this.MethodParameter;
const path = [];
if (parameter.language?.['cli']?.cliFlattenTrace) {
path.push(...parameter.language?.['cli']?.cliFlattenTrace);
}
path.push(this.MethodParameter_Name);
return path.join('$$');
}
}
41 changes: 34 additions & 7 deletions src/generate/renders/generated/CliCustom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ function GenerateBody(model: CodeModelAz, required: any): string[] {
return output;
}

function ConstructMethodBodyParameter(model: CodeModelAz, needGeneric = false, required: any) {
function ConstructMethodBodyParameter(
model: CodeModelAz,
needGeneric = false,
required: any,
outputParamNames: string[],
) {
const {
methodHandler,
methodParameterHandler,
Expand Down Expand Up @@ -191,6 +196,7 @@ function ConstructMethodBodyParameter(model: CodeModelAz, needGeneric = false, r
originalParameterNameStack,
null,
'{}',
outputParamNames,
),
);
}
Expand Down Expand Up @@ -256,6 +262,7 @@ function ConstructMethodBodyParameter(model: CodeModelAz, needGeneric = false, r
originalParameterNameStack,
null,
'{}',
outputParamNames,
),
);
}
Expand All @@ -279,6 +286,7 @@ function ConstructMethodBodyParameter(model: CodeModelAz, needGeneric = false, r
originalParameterNameStack,
paramName,
"'" + valueToMatch + "'",
outputParamNames,
);
} else {
continue;
Expand Down Expand Up @@ -306,6 +314,7 @@ function ConstructMethodBodyParameter(model: CodeModelAz, needGeneric = false, r
originalParameterNameStack,
paramName,
methodParameterHandler.MethodParameter_MapsTo,
outputParamNames,
defaultValue,
needIfClause,
);
Expand All @@ -330,6 +339,7 @@ function ConstructMethodBodyParameter(model: CodeModelAz, needGeneric = false, r
originalParameterNameStack,
paramName,
defaultValue,
outputParamNames,
);
}
}
Expand Down Expand Up @@ -385,6 +395,7 @@ function ConstructValuation(
classNames: string[],
paramName: string,
value: string,
outputParamNames: string[],
defaultValue: string = null,
needIfClause = true,
): string[] {
Expand All @@ -410,6 +421,13 @@ function ConstructValuation(

if (!isNullOrUndefined(paramName)) {
left = left + "['" + paramName + "']";
} else if (classNames.length == 1 && outputParamNames.indexOf(classNames[0]) >= 0) {
//in case the body parameter has the same name with an function parameter, define a temp parameter for the function parameter
str.push(prefix + `_${classNames[0]} = ${classNames[0]}`);
}
if (outputParamNames.indexOf(value) >= 0 && value == classNames[0]) {
//use the temp parameter
value = '_' + value;
}
}
str.push(left + ' = ' + value);
Expand All @@ -427,13 +445,14 @@ function ConstructValuation(
classNames,
paramName,
defaultValue,
outputParamNames,
) + ifClause,
);
}
return str;
}

function GetSingleCommandDef(model: CodeModelAz, required: any) {
function GetSingleCommandDef(model: CodeModelAz, required: any, outputParamNames: string[]) {
const {
commandGroupHandler,
commandHandler,
Expand Down Expand Up @@ -462,6 +481,7 @@ function GetSingleCommandDef(model: CodeModelAz, required: any) {
}
if (!firstLine) {
output.push(call);
outputParamNames.push(call);
firstLine = true;
}
if (methodHandler.Method_IsLongRun && commandGroupHandler.CommandGroup_HasShowCommand) {
Expand Down Expand Up @@ -512,6 +532,7 @@ function GetSingleCommandDef(model: CodeModelAz, required: any) {
allParam.set(name, true);
output[output.length - 1] += ',';
output.push(indent + name);
outputParamNames.push(name);
}
} while (model.SelectNextMethodParameter());
}
Expand All @@ -537,7 +558,10 @@ function GetSingleCommandDef(model: CodeModelAz, required: any) {
needGeneric &&
!isNullOrUndefined(genericParameter) &&
methodParameterHandler.MethodParameter_MapsTo ===
parameterHandler.Parameter_MapsTo(genericParameter)
parameterHandler.Parameter_MapsTo(genericParameter) &&
isNullOrUndefined(
methodParameterHandler.MethodParameter.language['cli']?.cliFlattenTrace,
)
) {
continue;
}
Expand Down Expand Up @@ -569,6 +593,7 @@ function GetSingleCommandDef(model: CodeModelAz, required: any) {
allParam.set(name, true);
output[output.length - 1] += ',';
output.push(indent + name + '=None');
outputParamNames.push(name);
}
} while (model.SelectNextMethodParameter());
}
Expand All @@ -578,12 +603,13 @@ function GetSingleCommandDef(model: CodeModelAz, required: any) {
if (hasLongRun) {
output[output.length - 1] += ',';
output.push(indent + 'no_wait=False');
outputParamNames.push('no_wait');
}
output[output.length - 1] += '):';
return output;
}

function GetSingleCommandBody(model: CodeModelAz, required: any) {
function GetSingleCommandBody(model: CodeModelAz, required: any, outputParamNames: string[]) {
const { methodHandler, methodParameterHandler, parameterHandler } = model.GetHandler();
let originalParameters = null;

Expand Down Expand Up @@ -722,7 +748,7 @@ function GetSingleCommandBody(model: CodeModelAz, required: any) {
}

outputBody = outputBody.concat(
ConstructMethodBodyParameter(model, needGeneric, required),
ConstructMethodBodyParameter(model, needGeneric, required, outputParamNames),
);
} while (model.SelectNextMethod());

Expand Down Expand Up @@ -811,8 +837,9 @@ function GetCommandBody(model: CodeModelAz, required: any) {
output.push('');
output.push('');

output = output.concat(GetSingleCommandDef(model, required));
output = output.concat(GetSingleCommandBody(model, required));
const outputParamNames: string[] = [];
output = output.concat(GetSingleCommandDef(model, required, outputParamNames));
output = output.concat(GetSingleCommandBody(model, required, outputParamNames));
return output;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def datafactory_trigger_update(instance,
if_match=None,
description=None,
annotations=None):
instance.properties.type = 'Trigger'
if description is not None:
instance.properties.description = description
if annotations is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,20 @@ def managed_network_managed_network_peering_policy_hub_and_spoke_topology_create
managed_network_name,
policy_name,
location,
managed_network_policy,
hub=None,
spokes=None,
mesh=None,
managed_network_policy=None,
no_wait=False):
_managed_network_policy = managed_network_policy
managed_network_policy = {}
managed_network_policy['location'] = location
managed_network_policy['properties'] = {}
managed_network_policy['properties']['type'] = 'HubAndSpokeTopology'
managed_network_policy['properties']['hub'] = hub
managed_network_policy['properties']['spokes'] = spokes
managed_network_policy['properties']['mesh'] = mesh
managed_network_policy['managed_network_policy'] = _managed_network_policy
return sdk_no_wait(no_wait,
client.begin_create_or_update,
resource_group_name=resource_group_name,
Expand All @@ -240,18 +242,20 @@ def managed_network_managed_network_peering_policy_mesh_topology_create(client,
managed_network_name,
policy_name,
location,
managed_network_policy,
hub=None,
spokes=None,
mesh=None,
managed_network_policy=None,
no_wait=False):
_managed_network_policy = managed_network_policy
managed_network_policy = {}
managed_network_policy['location'] = location
managed_network_policy['properties'] = {}
managed_network_policy['properties']['type'] = 'MeshTopology'
managed_network_policy['properties']['hub'] = hub
managed_network_policy['properties']['spokes'] = spokes
managed_network_policy['properties']['mesh'] = mesh
managed_network_policy['managed_network_policy'] = _managed_network_policy
return sdk_no_wait(no_wait,
client.begin_create_or_update,
resource_group_name=resource_group_name,
Expand All @@ -268,6 +272,7 @@ def managed_network_managed_network_peering_policy_hub_and_spoke_topology_update
hub=None,
spokes=None,
mesh=None,
managed_network_policy=None,
no_wait=False):
if location is not None:
instance.location = location
Expand All @@ -278,6 +283,8 @@ def managed_network_managed_network_peering_policy_hub_and_spoke_topology_update
instance.properties.spokes = spokes
if mesh is not None:
instance.properties.mesh = mesh
if managed_network_policy is not None:
instance.managed_network_policy = managed_network_policy
return instance


Expand All @@ -289,6 +296,7 @@ def managed_network_managed_network_peering_policy_mesh_topology_update(instance
hub=None,
spokes=None,
mesh=None,
managed_network_policy=None,
no_wait=False):
if location is not None:
instance.location = location
Expand All @@ -299,6 +307,8 @@ def managed_network_managed_network_peering_policy_mesh_topology_update(instance
instance.properties.spokes = spokes
if mesh is not None:
instance.properties.mesh = mesh
if managed_network_policy is not None:
instance.managed_network_policy = managed_network_policy
return instance


Expand Down

0 comments on commit fac6981

Please sign in to comment.