Merge pull request #63 from Azure/single-prop-flatten
Single prop flatten & fix visibility check for polymorphism
This commit is contained in:
Коммит
78c175c2c7
|
@ -192,10 +192,15 @@ export class FlattenSetter {
|
||||||
|
|
||||||
private flattenSchemaFromPayload(schema: Schema, curLevel: number, flattenSimpleObject: boolean, flattenConfig: FlattenConfig) {
|
private flattenSchemaFromPayload(schema: Schema, curLevel: number, flattenSimpleObject: boolean, flattenConfig: FlattenConfig) {
|
||||||
|
|
||||||
if (curLevel >= flattenConfig.maxLevel)
|
|
||||||
return;
|
|
||||||
if (!(schema instanceof ObjectSchema))
|
if (!(schema instanceof ObjectSchema))
|
||||||
return;
|
return;
|
||||||
|
if (curLevel >= flattenConfig.maxLevel) {
|
||||||
|
let indicator = NodeHelper.getSimplifyIndicator(schema);
|
||||||
|
// Continue flatten if there is only one property even when we hit the max level
|
||||||
|
if (indicator.simplifiable !== true || indicator.propertyCountIfSimplify !== 1)
|
||||||
|
return;
|
||||||
|
Helper.logDebug(`continue flatten ${schema.language.default.name} when maxLevel is met because it's simplifiyIndicator.propertyCountIfSimplify is ${indicator.propertyCountIfSimplify}`);
|
||||||
|
}
|
||||||
|
|
||||||
for (let prop of getAllProperties(schema)) {
|
for (let prop of getAllProperties(schema)) {
|
||||||
if (prop.readOnly)
|
if (prop.readOnly)
|
||||||
|
@ -205,8 +210,11 @@ export class FlattenSetter {
|
||||||
this.flattenPolySchema(prop.schema, NodeHelper.getCliKey(prop, "noParamCliKey"), curLevel, flattenSimpleObject, flattenConfig);
|
this.flattenPolySchema(prop.schema, NodeHelper.getCliKey(prop, "noParamCliKey"), curLevel, flattenSimpleObject, flattenConfig);
|
||||||
}
|
}
|
||||||
else if (NodeHelper.getInCircle(prop.schema) !== true) {
|
else if (NodeHelper.getInCircle(prop.schema) !== true) {
|
||||||
if (flattenSimpleObject || NodeHelper.getComplexity(prop.schema) !== CliCommonSchema.CodeModel.Complexity.object_simple)
|
if (flattenSimpleObject ||
|
||||||
|
NodeHelper.getComplexity(prop.schema) !== CliCommonSchema.CodeModel.Complexity.object_simple ||
|
||||||
|
NodeHelper.getSimplifyIndicator(prop.schema).propertyCountIfSimplify == 1) {
|
||||||
NodeHelper.setFlatten(prop, true, flattenConfig.overwriteSwagger);
|
NodeHelper.setFlatten(prop, true, flattenConfig.overwriteSwagger);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (prop.schema instanceof ArraySchema) {
|
else if (prop.schema instanceof ArraySchema) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Host, Session, startSession } from "@azure-tools/autorest-extension-base";
|
import { Host, Session, startSession } from "@azure-tools/autorest-extension-base";
|
||||||
import { CodeModel, Request, codeModelSchema, Metadata, ObjectSchema, isObjectSchema, Property, Extensions, Scheme, ComplexSchema, Operation, OperationGroup, Parameter, VirtualParameter, ImplementationLocation, ArraySchema, DictionarySchema, ConstantSchema } from "@azure-tools/codemodel";
|
import { CodeModel, Request, codeModelSchema, Metadata, ObjectSchema, isObjectSchema, Property, Extensions, Scheme, ComplexSchema, Operation, OperationGroup, Parameter, VirtualParameter, ImplementationLocation, ArraySchema, DictionarySchema, ConstantSchema, getAllProperties } from "@azure-tools/codemodel";
|
||||||
import { isNullOrUndefined, isArray, isNull } from "util";
|
import { isNullOrUndefined, isArray, isNull } from "util";
|
||||||
import { Helper } from "../helper";
|
import { Helper } from "../helper";
|
||||||
import { CliConst, M4Node, CliCommonSchema } from "../schema";
|
import { CliConst, M4Node, CliCommonSchema } from "../schema";
|
||||||
|
@ -52,6 +52,18 @@ class VisibilityCleaner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (visible === CliCommonSchema.CodeModel.Visibility.false) {
|
||||||
|
if (NodeHelper.HasSubClass(schema)) {
|
||||||
|
for (let subClass of NodeHelper.getSubClasses(schema, true)) {
|
||||||
|
if (this.calcObject(subClass) === CliCommonSchema.CodeModel.Visibility.true) {
|
||||||
|
visible = CliCommonSchema.CodeModel.Visibility.true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
NodeHelper.setIsVisibleFlag(schema, visible);
|
NodeHelper.setIsVisibleFlag(schema, visible);
|
||||||
return visible;
|
return visible;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче