From b70db1a58d823bbf084ee26d2f739a099389f1f1 Mon Sep 17 00:00:00 2001 From: Rodge Fu Date: Sun, 22 Mar 2020 15:57:55 +0800 Subject: [PATCH] turn on poly-resource by default --- README.md | 4 ++-- src/helper.ts | 14 +++++++------- src/nodeHelper.ts | 2 +- src/plugins/polyAsResourceModifier.ts | 3 +++ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c953320..e1bfe30 100644 --- a/README.md +++ b/README.md @@ -101,8 +101,8 @@ cli: # prop: propertyName # flatten: true polymorphism: - expand-as-resource: false - auto-parameter-hidden: true + expand-as-resource: true + auto-parameter-hidden: false naming: cli: appliedTo: diff --git a/src/helper.ts b/src/helper.ts index 7459e09..df5c5fc 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -340,20 +340,20 @@ export class Helper { `${NEW_LINE}${tab(2)}operations:${NEW_LINE}`.concat( v.operations.map(vv => `${tab(2)}- operationName: ${generateCliValue(vv, 3)}` + - (isNullOrUndefined(NodeHelper.getPolyAsResourceParam(vv)) ? '' : `${NEW_LINE}${tab(3)}polyAsResourceParam: ${NodeHelper.getCliKey(NodeHelper.getPolyAsResourceParam(vv), '')}`) + + (isNullOrUndefined(NodeHelper.getPolyAsResourceParam(vv)) ? '' : `${NEW_LINE}${tab(3)}cli-poly-as-resource-subclass-param: ${NodeHelper.getCliKey(NodeHelper.getPolyAsResourceParam(vv), '')}`) + `${NEW_LINE}${tab(3)}parameters:${NEW_LINE}`.concat( vv.parameters.map(vvv => `${tab(3)}- parameterName: ${generateCliValue(vvv, 4)}${generatePropertyFlattenValue(vvv, 4)}${generateDiscriminatorValueForParam(vvv, 4)}${NEW_LINE}` + - (isNullOrUndefined(NodeHelper.getPolyAsResourceBaseSchema(vvv)) ? '' : `${tab(4)}polyAsResourceBaseSchema: ${NodeHelper.getCliKey(NodeHelper.getPolyAsResourceBaseSchema(vvv), '')}${NEW_LINE}`) + - (isNullOrUndefined(NodeHelper.getPolyAsParamBaseSchema(vvv)) ? '' : `${tab(4)}polyAsParamBaseSchema: ${NodeHelper.getCliKey(NodeHelper.getPolyAsParamBaseSchema(vvv), '')}${NEW_LINE}`) + - (isNullOrUndefined(NodeHelper.getPolyAsParamOriginalParam(vvv)) ? '' : `${tab(4)}polyAsParamOriginalParam: ${NodeHelper.getCliKey(NodeHelper.getPolyAsParamOriginalParam(vvv), '')}${NEW_LINE}`) + + (isNullOrUndefined(NodeHelper.getPolyAsResourceBaseSchema(vvv)) ? '' : `${tab(4)}cli-poly-as-resource-base-schema: ${NodeHelper.getCliKey(NodeHelper.getPolyAsResourceBaseSchema(vvv), '')}${NEW_LINE}`) + + (isNullOrUndefined(NodeHelper.getPolyAsParamBaseSchema(vvv)) ? '' : `${tab(4)}cli-poly-as-param-base-schema: ${NodeHelper.getCliKey(NodeHelper.getPolyAsParamBaseSchema(vvv), '')}${NEW_LINE}`) + + (isNullOrUndefined(NodeHelper.getPolyAsParamOriginalParam(vvv)) ? '' : `${tab(4)}cli-poly-as-param-expanded: ${NodeHelper.getCliKey(NodeHelper.getPolyAsParamOriginalParam(vvv), '')}${NEW_LINE}`) + (((!isNullOrUndefined(vvv.protocol?.http?.in)) && vvv.protocol.http.in === 'body') ? `${tab(4)}bodySchema: ${vvv.schema.language.default.name}${NEW_LINE}` : '')).join('')) + vv.requests.map((req, index) => isNullOrUndefined(req.parameters) ? '' : req.parameters.map((vvv) => `${tab(3)}- parameterName[${index}]: ${generateCliValue(vvv, 4)}${generatePropertyFlattenValue(vvv, 4)}${generateDiscriminatorValueForParam(vvv, 4)}${NEW_LINE}` + - (isNullOrUndefined(NodeHelper.getPolyAsResourceBaseSchema(vvv)) ? '' : `${tab(4)}polyAsResourceBaseSchema: ${NodeHelper.getCliKey(NodeHelper.getPolyAsResourceBaseSchema(vvv), '')}${NEW_LINE}`) + - (isNullOrUndefined(NodeHelper.getPolyAsParamBaseSchema(vvv)) ? '' : `${tab(4)}polyAsParamBaseSchema: ${NodeHelper.getCliKey(NodeHelper.getPolyAsParamBaseSchema(vvv), '')}${NEW_LINE}`) + - (isNullOrUndefined(NodeHelper.getPolyAsParamOriginalParam(vvv)) ? '' : `${tab(4)}polyAsParamOriginalParam: ${NodeHelper.getCliKey(NodeHelper.getPolyAsParamOriginalParam(vvv), '')}${NEW_LINE}`) + + (isNullOrUndefined(NodeHelper.getPolyAsResourceBaseSchema(vvv)) ? '' : `${tab(4)}cli-poly-as-resource-base-schema: ${NodeHelper.getCliKey(NodeHelper.getPolyAsResourceBaseSchema(vvv), '')}${NEW_LINE}`) + + (isNullOrUndefined(NodeHelper.getPolyAsParamBaseSchema(vvv)) ? '' : `${tab(4)}cli-poly-as-param-base-schema: ${NodeHelper.getCliKey(NodeHelper.getPolyAsParamBaseSchema(vvv), '')}${NEW_LINE}`) + + (isNullOrUndefined(NodeHelper.getPolyAsParamOriginalParam(vvv)) ? '' : `${tab(4)}cli-poly-as-param-expanded: ${NodeHelper.getCliKey(NodeHelper.getPolyAsParamOriginalParam(vvv), '')}${NEW_LINE}`) + (((!isNullOrUndefined(vvv.protocol?.http?.in)) && vvv.protocol.http.in === 'body') ? `${tab(4)}bodySchema: ${vvv.schema.language.default.name}${NEW_LINE}` : '')).join('')) ).join('')) diff --git a/src/nodeHelper.ts b/src/nodeHelper.ts index fa415e8..503ee5f 100644 --- a/src/nodeHelper.ts +++ b/src/nodeHelper.ts @@ -19,7 +19,7 @@ export class NodeHelper { private static readonly POLY_AS_RESOURCE_BASE_SCHEMA = 'cli-poly-as-resource-base-schema'; private static readonly POLY_AS_PARAM_BASE_SCHEMA = 'cli-poly-as-param-base-schema'; private static readonly POLY_AS_PARAM_ORIGINIAL_PARAMETER = 'cli-poly-as-param-original-parameter'; - private static readonly POLY_AS_PARAM_EXPANDED = 'cli-poly-asparam-expanded'; + private static readonly POLY_AS_PARAM_EXPANDED = 'cli-poly-as-param-expanded'; private static visitedKeyDict = {}; diff --git a/src/plugins/polyAsResourceModifier.ts b/src/plugins/polyAsResourceModifier.ts index bd88b6a..ba7e73b 100644 --- a/src/plugins/polyAsResourceModifier.ts +++ b/src/plugins/polyAsResourceModifier.ts @@ -173,6 +173,9 @@ export async function processRequest(host: Host) { let rd = new PolyAsResourceModifier(session); rd.process(); } + else { + Helper.logWarning("cli.polymorphism.expand-as-resource is not true, poly-resource will be ignored"); + } Helper.dumper.dumpCodeModel('poly-as-resource-post');