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

Commit

Permalink
Fix Hidden Issue
Browse files Browse the repository at this point in the history
  • Loading branch information
LianwMS committed Jun 2, 2020
1 parent a85f05f commit ac9a438
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 24 deletions.
13 changes: 5 additions & 8 deletions src/plugins/azgenerator/CodeModelAz.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { AnyARecord } from "dns";
import { Operation, Parameter, OperationGroup } from "@azure-tools/codemodel";
import { Property } from '@azure-tools/codemodel';
import { Operation, OperationGroup, Parameter, Property } from "@azure-tools/codemodel";

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
Expand Down Expand Up @@ -28,7 +26,7 @@ export class ExampleParam {
keys: string[];
defaultName: string;
methodParam: MethodParam;
public constructor(name: string, value: any, isJson: boolean, isKeyValues: boolean, keys:string[], defaultName: string, methodParam: MethodParam) {
public constructor(name: string, value: any, isJson: boolean, isKeyValues: boolean, keys: string[], defaultName: string, methodParam: MethodParam) {
this.name = name;
this.value = value;
this.isJson = isJson;
Expand All @@ -53,8 +51,7 @@ export class CommandExample {
public MethodParams: Map<string, MethodParam>;
}

export interface CodeModelAz
{
export interface CodeModelAz {
init(): any;
SelectFirstExtension(): boolean;
SelectNextExtension(): boolean;
Expand Down Expand Up @@ -91,7 +88,7 @@ export interface CodeModelAz
Command_CanSplit: boolean;
Command_IsLongRun: boolean;
Command_SubGroupName: string;

SelectFirstMethod(): boolean;
SelectNextMethod(): boolean;

Expand Down Expand Up @@ -136,7 +133,7 @@ export interface CodeModelAz
MethodParameter_RequiredByMethod: boolean;
MethodParameter_EnumValues: string[];
MethodParameters_AddPolySubClass(oriParam, para): boolean;
MethodParameters_DefaultValue: any | undefined;
MethodParameter_DefaultValue: any | undefined;
Parameter_Type(Parameter): string;
Schema_Type(Schema): string;
Parameter_IsList(Parameter): boolean;
Expand Down
22 changes: 20 additions & 2 deletions src/plugins/azgenerator/CodeModelAzImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1287,18 +1287,29 @@ export class CodeModelCliImpl implements CodeModelAz {
if (!parameter.language['az'].hasOwnProperty('hidden')) {
// Handle complex
let shouldHidden = undefined;
let defaultValue = undefined;
if (this.EnterSubMethodParameters(parameter))
{
shouldHidden = true;
defaultValue = "{";
if (this.SelectFirstMethodParameter()) {
do {
if (this.Parameter_Type(this.SubMethodParameter) != SchemaType.Constant
&& this.SubMethodParameter['readOnly'] != true) {
shouldHidden = false;
break;
}
else if (this.Parameter_Type(this.SubMethodParameter) == SchemaType.Constant) {
defaultValue = defaultValue + "\"" + this.Parameter_NameAz(this.SubMethodParameter) + "\": \"" + this.Parameter_DefaultValue(this.SubMethodParameter) + "\"";
}
} while (this.SelectNextMethodParameter())
}
if (shouldHidden == true) {
defaultValue = defaultValue + "}";
}
else {
defaultValue = undefined;
}
this.ExitSubMethodParameters();
}

Expand All @@ -1319,21 +1330,28 @@ export class CodeModelCliImpl implements CodeModelAz {
}
} else {
parameter.language['az'].hidden = parameter['hidden'] ?? shouldHidden ?? false;
if (!parameter.language['az'].hasOwnProperty('default-value') && defaultValue != undefined) {
parameter.language['az']['default-value'] = defaultValue;
}
}
}

return parameter.language['az'].hidden;
}

public get MethodParameters_DefaultValue(): string | undefined {
public get MethodParameter_DefaultValue(): string | undefined {
return this.Parameter_DefaultValue(this.MethodParameter);
}

public Parameter_DefaultValue(parameter: Parameter): string | undefined{
if (!parameter.language['az'].hasOwnProperty('default-value')) {
if (parameter?.language?.['cli']?.hasOwnProperty('default-value')) {
parameter.language['az']['default-value'] = parameter.language['cli']['default-value'];
} else {
}
else if (parameter.schema.type == SchemaType.Constant) {
parameter.language['az']['default-value'] = parameter.schema?.['value']?.value;
}
else {
parameter.language['az']['default-value'] = parameter.schema.defaultValue;
}
}
Expand Down
30 changes: 18 additions & 12 deletions src/plugins/azgenerator/TemplateAzureCliCustom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Operation, Parameter, SchemaType } from "@azure-tools/codemodel";
import { isNullOrUndefined } from "util";
import { Capitalize, ToCamelCase, ToMultiLine, ToPythonString } from '../../utils/helper';
import { CodeModelAz } from "./CodeModelAz";
import { SchemaType, Operation, Parameter } from "@azure-tools/codemodel";
import { HeaderGenerator } from "./Header";
import { isNullOrUndefined } from "util";
import { ToMultiLine, ToCamelCase, Capitalize, ToPythonString } from '../../utils/helper';

export function GenerateAzureCliCustom(model: CodeModelAz): string[] {
let header: HeaderGenerator = new HeaderGenerator();
Expand Down Expand Up @@ -114,10 +114,10 @@ function ConstructMethodBodyParameter(model: CodeModelAz, needGeneric: boolean =
}
else {
if (!model.MethodParameter_IsHidden) {
access = ConstructValuation(needGeneric, prefixIndent, originalParameterNameStack, paramName, model.MethodParameter_MapsTo, ToPythonString(model.MethodParameters_DefaultValue, model.MethodParameter_Type));
access = ConstructValuation(needGeneric, prefixIndent, originalParameterNameStack, paramName, model.MethodParameter_MapsTo, ToPythonString(model.MethodParameter_DefaultValue, model.MethodParameter_Type));
}
else if (!isNullOrUndefined(model.MethodParameters_DefaultValue)) {
access = ConstructValuation(needGeneric, prefixIndent, originalParameterNameStack, paramName, ToPythonString(model.MethodParameters_DefaultValue, model.MethodParameter_Type));
else if (!isNullOrUndefined(model.MethodParameter_DefaultValue)) {
access = ConstructValuation(needGeneric, prefixIndent, originalParameterNameStack, paramName, ToPythonString(model.MethodParameter_DefaultValue, model.MethodParameter_Type));
}
}
output_body.push(access);
Expand Down Expand Up @@ -339,10 +339,10 @@ function GetSingleCommandBody(model: CodeModelAz, required, originalOperation: O
output_body.push(" if isinstance(" + model.MethodParameter_MapsTo + ", str):");
output_body.push(" " + model.MethodParameter_MapsTo + " = json.loads(" + model.MethodParameter_MapsTo + ")");
}
else if (model.MethodParameters_DefaultValue !== undefined) {
else if (model.MethodParameter_DefaultValue !== undefined && model.MethodParameter_Type != SchemaType.Constant) {
// model is simple type with default value
output_body.push(" if " + model.MethodParameter_MapsTo + " == None:");
output_body.push(" " + model.MethodParameter_MapsTo + " = " + ToPythonString(model.MethodParameters_DefaultValue, model.MethodParameter_Type));
output_body.push(" " + model.MethodParameter_MapsTo + " = " + ToPythonString(model.MethodParameter_DefaultValue, model.MethodParameter_Type));
}
}
while (model.SelectNextMethodParameter());
Expand Down Expand Up @@ -406,7 +406,7 @@ function GetSingleCommandBody(model: CodeModelAz, required, originalOperation: O
if (needGeneric) {
output_method_call = output_method_call.concat(" return instance");
} else {
output_method_call = output_method_call.concat(GetMethodCall(model, prefix));
output_method_call = output_method_call.concat(GetMethodCall(model, required, prefix));
}
}
}
Expand Down Expand Up @@ -493,7 +493,7 @@ function GetPolyMethodCall(model: CodeModelAz, prefix: any, originalOperation: O
return methodCall.split("\n");
}

function GetMethodCall(model: CodeModelAz, prefix: any): string[] {
function GetMethodCall(model: CodeModelAz, required: any, prefix: any): string[] {
let methodCall: string = prefix + "return ";
//methodCall += "client." + mode.GetModuleOperationName() +"." + ctx.Methods[methodIdx].Name + "(";
let methodName = model.Method_Name;
Expand Down Expand Up @@ -526,8 +526,14 @@ function GetMethodCall(model: CodeModelAz, prefix: any): string[] {
let parameterPair = '';

if (model.MethodParameter_IsHidden) {
if (model.MethodParameters_DefaultValue) {
parameterPair = model.MethodParameter_NamePython + "=" + ToPythonString(model.MethodParameters_DefaultValue, model.MethodParameter_Type);
if (model.MethodParameter_DefaultValue) {
if (model.Schema_Type(model.MethodParameter.schema) == SchemaType.Object) {
parameterPair = model.MethodParameter_NamePython + "=json.loads(" + ToPythonString(model.MethodParameter_DefaultValue, model.MethodParameter_Type) + ")";
required['json'] = true;
}
else {
parameterPair = model.MethodParameter_NamePython + "=" + ToPythonString(model.MethodParameter_DefaultValue, model.MethodParameter_Type);
}
}
else {
parameterPair = model.MethodParameter_NamePython + "=None";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def datafactory_create(client,
if_match=if_match,
location=location,
tags=tags,
identity=None,
identity=json.loads("{\"type\": \"SystemAssigned\"}"),
repo_configuration=repo_configuration,
fake_identity=fake_identity,
zones=zones)
Expand All @@ -67,7 +67,7 @@ def datafactory_update(client,
return client.update(resource_group_name=resource_group_name,
factory_name=factory_name,
tags=tags,
identity=None)
identity=json.loads("{\"type\": \"SystemAssigned\"}"))


def datafactory_delete(client,
Expand Down

0 comments on commit ac9a438

Please sign in to comment.