Skip to content

Commit

Permalink
fix typescript-axios model type error & lost import
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoub committed Sep 2, 2021
1 parent 97bf30f commit 6f916fe
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,7 @@
import io.swagger.codegen.v3.ISchemaHandler;
import io.swagger.codegen.v3.generators.DefaultCodegenConfig;
import io.swagger.codegen.v3.generators.util.OpenAPIUtil;
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.BooleanSchema;
import io.swagger.v3.oas.models.media.ComposedSchema;
import io.swagger.v3.oas.models.media.DateSchema;
import io.swagger.v3.oas.models.media.DateTimeSchema;
import io.swagger.v3.oas.models.media.IntegerSchema;
import io.swagger.v3.oas.models.media.MapSchema;
import io.swagger.v3.oas.models.media.NumberSchema;
import io.swagger.v3.oas.models.media.ObjectSchema;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.media.StringSchema;
import io.swagger.v3.oas.models.media.*;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -238,17 +228,24 @@ public CodegenModel fromModel(String name, Schema schema, Map<String, Schema> al

@Override
public String getTypeDeclaration(Schema propertySchema) {
if (propertySchema instanceof ArraySchema) {
Schema inner = ((ArraySchema) propertySchema).getItems();
return String.format("%s<%s>", getSchemaType(propertySchema), getTypeDeclaration(inner));
} else if (propertySchema instanceof MapSchema && hasSchemaProperties(propertySchema)) {
Schema inner = (Schema) propertySchema.getAdditionalProperties();
return String.format("{ [key, string]: %s;}", getTypeDeclaration(inner));
Schema inner;
if(propertySchema instanceof ArraySchema) {
ArraySchema arraySchema = (ArraySchema)propertySchema;
inner = arraySchema.getItems();
return this.getSchemaType(propertySchema) + "<" + this.getTypeDeclaration(inner) + ">";
} else if(propertySchema instanceof MapSchema && hasSchemaProperties(propertySchema)) {
inner = (Schema) propertySchema.getAdditionalProperties();
return "{ [key: string]: " + this.getTypeDeclaration(inner) + "; }";
} else if (propertySchema instanceof MapSchema && hasTrueAdditionalProperties(propertySchema)) {
Schema inner = new ObjectSchema();
return String.format("{ [key, string]: %s;}", getTypeDeclaration(inner));
inner = new ObjectSchema();
return "{ [key: string]: " + this.getTypeDeclaration(inner) + "; }";
} else if(propertySchema instanceof FileSchema || propertySchema instanceof BinarySchema) {
return "Blob";
} else if(propertySchema instanceof ObjectSchema) {
return "any";
} else {
return super.getTypeDeclaration(propertySchema);
}
return super.getTypeDeclaration(propertySchema);
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/handlebars/typescript-axios/model.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
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}}
{{#imports}}
import { {{class}} } from './{{filename}}';
{{/imports}}
{{#models}}{{#model}}
{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{#oneOf}}{{#@first}}{{>modelOneOf}}{{/@first}}{{/oneOf}}{{#allOf}}{{#@first}}{{>modelAllOf}}{{/@first}}{{/allOf}}{{^isEnum}}{{^oneOf}}{{^allOf}}{{>modelGeneric}}{{/allOf}}{{/oneOf}}{{/isEnum}}
{{/model}}{{/models}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export interface {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{
{{#vars}}
/**
* {{{description}}}
* @type {{braces "left"}}{{datatype}}{{braces "right"}}
* @memberof {{classname}}
* @type {{braces "left"}}{{{datatype}}}{{braces "right"}}
* @memberof {{{classname}}}
{{#deprecated}}
* @deprecated
{{/deprecated}}
*/
{{name}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{#isNullable}} | null{{/isNullable}}{{/isEnum}};
{{name}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{#isNullable}} | null{{/isNullable}}{{/isEnum}};
{{/vars}}
}{{#hasEnums}}

Expand Down

0 comments on commit 6f916fe

Please sign in to comment.