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

Commit

Permalink
fix-empty-object-default-value for issue #676
Browse files Browse the repository at this point in the history
  • Loading branch information
qiaozha committed Dec 14, 2020
1 parent 4818d70 commit ac88afe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/plugins/azgenerator/CodeModelAzImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1629,7 +1629,6 @@ export class CodeModelCliImpl implements CodeModelAz {
// Handle complex
let shouldHidden = undefined;
let defaultValue = undefined;
let hasDefault = false;
if (this.EnterSubMethodParameters(parameter)) {
shouldHidden = true;
defaultValue = "{";
Expand All @@ -1642,11 +1641,10 @@ export class CodeModelCliImpl implements CodeModelAz {
}
else if (this.Parameter_Type(this.SubMethodParameter) == SchemaType.Constant) {
defaultValue = defaultValue + "\"" + this.Parameter_NameAz(this.SubMethodParameter) + "\": \"" + this.Parameter_DefaultValue(this.SubMethodParameter) + "\"";
hasDefault = true;
}
} while (this.SelectNextMethodParameter())
}
if (shouldHidden == true && hasDefault) {
if (shouldHidden == true) {
defaultValue = defaultValue + "}";
}
else {
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/azgenerator/templates/generated/CliCustom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ function ConstructMethodBodyParameter(model: CodeModelAz, needGeneric: boolean =
}
else {
let defaultValue = ToPythonString(model.MethodParameter_DefaultValue, model.MethodParameter_Type);
if (model.MethodParameter_DefaultValue == "{}") {
defaultValue = "{}";
}
if (!model.MethodParameter_IsHidden) {
let needIfClause = true;
if (model.MethodParameter_Type == SchemaType.Constant) {
Expand All @@ -171,7 +174,7 @@ function ConstructMethodBodyParameter(model: CodeModelAz, needGeneric: boolean =
access = ConstructValuation(model, required, needGeneric, prefixIndent, originalParameterNameStack, paramName, model.MethodParameter_MapsTo, defaultValue, needIfClause);
}
else if (!isNullOrUndefined(model.MethodParameter_DefaultValue)) {
if (model.isComplexSchema(model.MethodParameter_Type)) {
if (model.isComplexSchema(model.MethodParameter_Type) && defaultValue != "{}") {
defaultValue = "json.loads(" + defaultValue + ")";
required['json'] = true;
}
Expand Down

0 comments on commit ac88afe

Please sign in to comment.