From 375f24f60595da87aa2175b2b24e42d0c2e13691 Mon Sep 17 00:00:00 2001 From: tanmen Date: Thu, 19 Dec 2019 01:16:34 +0900 Subject: [PATCH] fix unused import in allOf (#4805) nested model --- .../languages/TypeScriptAxiosClientCodegen.java | 16 ++++++++++++++++ .../resources/typescript-axios/model.mustache | 8 +++++--- .../typescript-axios/modelAllOf.mustache | 6 ++++++ 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 modules/openapi-generator/src/main/resources/typescript-axios/modelAllOf.mustache diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAxiosClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAxiosClientCodegen.java index 30f924fda4c..3976629470b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAxiosClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAxiosClientCodegen.java @@ -144,6 +144,22 @@ public class TypeScriptAxiosClientCodegen extends AbstractTypeScriptClientCodege return objs; } + @Override + public Map postProcessAllModels(Map objs) { + Map result = super.postProcessAllModels(objs); + for (Map.Entry entry : result.entrySet()) { + Map inner = (Map) entry.getValue(); + List> models = (List>) inner.get("models"); + for (Map model : models) { + CodegenModel codegenModel = (CodegenModel) model.get("model"); + model.put("hasAllOf", codegenModel.allOf.size() > 0); + model.put("hasOneOf", codegenModel.oneOf.size() > 0); + } + } + return result; + } + + @Override protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) { codegenModel.additionalPropertiesType = getTypeDeclaration(ModelUtils.getAdditionalProperties(schema)); diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/model.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/model.mustache index a460d5ce588..db2738d890f 100644 --- a/modules/openapi-generator/src/main/resources/typescript-axios/model.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-axios/model.mustache @@ -1,8 +1,10 @@ // tslint:disable {{>licenseInfo}} -{{#withSeparateModelsAndApi}}{{#imports}} -import { {{class}} } from './{{filename}}';{{/imports}}{{/withSeparateModelsAndApi}} +{{#withSeparateModelsAndApi}}{{#hasAllOf}}{{#allOf}} +import { {{class}} } from './{{filename}}';{{/allOf}}{{/hasAllOf}}{{#hasOneOf}}{{#oneOf}} +import { {{class}} } from './{{filename}}';{{/oneOf}}{{/hasOneOf}}{{^hasAllOf}}{{^hasOneOf}}{{#imports}} +import { {{class}} } from './{{filename}}';{{/imports}}{{/hasOneOf}}{{/hasAllOf}}{{/withSeparateModelsAndApi}} {{#models}}{{#model}} -{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{#oneOf}}{{#-first}}{{>modelOneOf}}{{/-first}}{{/oneOf}}{{^isEnum}}{{^oneOf}}{{>modelGeneric}}{{/oneOf}}{{/isEnum}} +{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{#oneOf}}{{#-first}}{{>modelOneOf}}{{/-first}}{{/oneOf}}{{#allOf}}{{#-first}}{{>modelAllOf}}{{/-first}}{{/allOf}}{{^isEnum}}{{^oneOf}}{{^allOf}}{{>modelGeneric}}{{/allOf}}{{/oneOf}}{{/isEnum}} {{/model}}{{/models}} diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/modelAllOf.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/modelAllOf.mustache new file mode 100644 index 00000000000..0c0dbf9fd89 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/typescript-axios/modelAllOf.mustache @@ -0,0 +1,6 @@ +/** + * @type {{classname}}{{#description}} + * {{{description}}}{{/description}} + * @export + */ +export type {{classname}} = {{#allOf}}{{{.}}}{{^-last}} & {{/-last}}{{/allOf}};