From 3a2c2fa6439c2fd830c6348b4d67c8d49f7877fe Mon Sep 17 00:00:00 2001 From: Rodge Fu Date: Mon, 18 May 2020 00:18:28 +0800 Subject: [PATCH] reusing existing method instead of creating a new one --- src/plugins/flattenSetter/flattenSetter.ts | 25 +++++----------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/src/plugins/flattenSetter/flattenSetter.ts b/src/plugins/flattenSetter/flattenSetter.ts index d3ace95..8d8d3bb 100644 --- a/src/plugins/flattenSetter/flattenSetter.ts +++ b/src/plugins/flattenSetter/flattenSetter.ts @@ -190,31 +190,16 @@ export class FlattenSetter { } } - private flattenSchemaWithSingleProperty(schema: ObjectSchema, flattenConfig: FlattenConfig) { - let propCount = 0; - if (NodeHelper.getSimplifyIndicator(schema).propertyCountIfSimplify != 1) { - return; - } - for (let prop of getAllProperties(schema)) { - if (prop.readOnly) - continue; - if (prop.schema instanceof ObjectSchema) { - if (NodeHelper.HasSubClass(prop.schema) !== true && NodeHelper.getInCircle(prop.schema) !== true) { - NodeHelper.setFlatten(prop, true, flattenConfig.overwriteSwagger); - Helper.logDebug("single property schema to flatten: " + schema.language.default.name); - this.flattenSchemaWithSingleProperty(prop.schema, flattenConfig); - } - } - } - } - private flattenSchemaFromPayload(schema: Schema, curLevel: number, flattenSimpleObject: boolean, flattenConfig: FlattenConfig) { if (!(schema instanceof ObjectSchema)) return; if (curLevel >= flattenConfig.maxLevel) { - this.flattenSchemaWithSingleProperty(schema, flattenConfig); - return; + 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)) {