From 7120730bdeacfb83acc23e01d83b046a98c7c0c8 Mon Sep 17 00:00:00 2001 From: Jack Cross <jackjocross@gmail.com> Date: Sun, 3 May 2020 23:08:39 -0500 Subject: [PATCH 1/6] Add typescript-axios --- .../TypeScriptAxiosClientCodegen.java | 255 +++++------- .../typescript-axios/README.mustache | 45 --- .../resources/typescript-axios/api.mustache | 76 +++- .../typescript-axios/apiInner.mustache | 369 ------------------ .../typescript-axios/baseApi.mustache | 60 --- .../typescript-axios/configuration.mustache | 65 --- .../typescript-axios/git_push.sh.mustache | 58 --- .../main/resources/typescript-axios/gitignore | 4 - .../resources/typescript-axios/index.mustache | 6 - .../typescript-axios/licenseInfo.mustache | 6 +- .../resources/typescript-axios/model.mustache | 18 +- .../typescript-axios/modelAllOf.mustache | 6 - .../typescript-axios/modelEnum.mustache | 14 +- .../typescript-axios/modelGeneric.mustache | 45 +-- .../typescript-axios/modelIndex.mustache | 2 - .../typescript-axios/modelOneOf.mustache | 6 - .../main/resources/typescript-axios/npmignore | 1 - .../typescript-axios/package.mustache | 32 -- .../typescript-axios/tsconfig.mustache | 23 -- 19 files changed, 179 insertions(+), 912 deletions(-) delete mode 100644 modules/openapi-generator/src/main/resources/typescript-axios/README.mustache delete mode 100644 modules/openapi-generator/src/main/resources/typescript-axios/apiInner.mustache delete mode 100644 modules/openapi-generator/src/main/resources/typescript-axios/baseApi.mustache delete mode 100644 modules/openapi-generator/src/main/resources/typescript-axios/configuration.mustache delete mode 100755 modules/openapi-generator/src/main/resources/typescript-axios/git_push.sh.mustache delete mode 100644 modules/openapi-generator/src/main/resources/typescript-axios/gitignore delete mode 100644 modules/openapi-generator/src/main/resources/typescript-axios/index.mustache delete mode 100644 modules/openapi-generator/src/main/resources/typescript-axios/modelAllOf.mustache delete mode 100644 modules/openapi-generator/src/main/resources/typescript-axios/modelIndex.mustache delete mode 100644 modules/openapi-generator/src/main/resources/typescript-axios/modelOneOf.mustache delete mode 100644 modules/openapi-generator/src/main/resources/typescript-axios/npmignore delete mode 100644 modules/openapi-generator/src/main/resources/typescript-axios/package.mustache delete mode 100644 modules/openapi-generator/src/main/resources/typescript-axios/tsconfig.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 95ded86dce5..4c063f9df34 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 @@ -17,6 +17,9 @@ package org.openapitools.codegen.languages; +import com.google.common.collect.ImmutableMap.Builder; +import com.samskivert.mustache.Mustache.Lambda; + import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.parser.util.SchemaTypeUtil; import org.apache.commons.lang3.StringUtils; @@ -27,38 +30,26 @@ import org.openapitools.codegen.CodegenOperation; import org.openapitools.codegen.SupportingFile; import org.openapitools.codegen.meta.features.DocumentationFeature; import org.openapitools.codegen.utils.ModelUtils; +import org.openapitools.codegen.templating.mustache.CaseFormatLambda; + +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static com.google.common.base.CaseFormat.LOWER_CAMEL; +import static com.google.common.base.CaseFormat.LOWER_UNDERSCORE; import java.util.*; public class TypeScriptAxiosClientCodegen extends AbstractTypeScriptClientCodegen { - - public static final String NPM_REPOSITORY = "npmRepository"; - public static final String WITH_INTERFACES = "withInterfaces"; - public static final String SEPARATE_MODELS_AND_API = "withSeparateModelsAndApi"; - public static final String WITHOUT_PREFIX_ENUMS = "withoutPrefixEnums"; - public static final String USE_SINGLE_REQUEST_PARAMETER = "useSingleRequestParameter"; - - protected String npmRepository = null; - - private String tsModelPackage = ""; - public TypeScriptAxiosClientCodegen() { super(); - modifyFeatureSet(features -> features.includeDocumentationFeatures(DocumentationFeature.Readme)); - - // clear import mapping (from default generator) as TS does not use it - // at the moment - importMapping.clear(); - - outputFolder = "generated-code/typescript-axios"; + this.outputFolder = "generated-code/typescript-axios"; embeddedTemplateDir = templateDir = "typescript-axios"; - this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url of your private npmRepo in the package.json")); - this.cliOptions.add(new CliOption(WITH_INTERFACES, "Setting this property to true will generate interfaces next to the default class implementations.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); - this.cliOptions.add(new CliOption(SEPARATE_MODELS_AND_API, "Put the model and api in separate folders and in separate classes", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); - this.cliOptions.add(new CliOption(WITHOUT_PREFIX_ENUMS, "Don't prefix enum names with class names", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); - this.cliOptions.add(new CliOption(USE_SINGLE_REQUEST_PARAMETER, "Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); + modelTemplateFiles.put("model.mustache", ".ts"); + apiTemplateFiles.put("api.mustache", ".ts"); + + modelPackage = "models"; + apiPackage = "resources"; } @Override @@ -68,186 +59,116 @@ public class TypeScriptAxiosClientCodegen extends AbstractTypeScriptClientCodege @Override public String getHelp() { - return "Generates a TypeScript client library using axios."; + return "Generates a TypeScript client library using Axios for HTTP requests."; } - public String getNpmRepository() { - return npmRepository; + @Override + public String toModelFilename(String name) { + return toModelName(name); } - public void setNpmRepository(String npmRepository) { - this.npmRepository = npmRepository; + @Override + public String toModelImport(String name) { + return modelPackage() + "/" + toModelFilename(name); } - private static String getRelativeToRoot(String path) { - StringBuilder sb = new StringBuilder(); - int slashCount = path.split("/").length; - if (slashCount == 0) { - sb.append("./"); - } else { - for (int i = 0; i < slashCount; ++i) { - sb.append("../"); - } + @Override + public String toEnumVarName(String name, String datatype) { + if (name.length() == 0) { + return "Empty"; } - return sb.toString(); - } - @Override - public void processOpts() { - super.processOpts(); - tsModelPackage = modelPackage.replaceAll("\\.", "/"); - String tsApiPackage = apiPackage.replaceAll("\\.", "/"); - - String modelRelativeToRoot = getRelativeToRoot(tsModelPackage); - String apiRelativeToRoot = getRelativeToRoot(tsApiPackage); - - additionalProperties.put("tsModelPackage", tsModelPackage); - additionalProperties.put("tsApiPackage", tsApiPackage); - additionalProperties.put("apiRelativeToRoot", apiRelativeToRoot); - additionalProperties.put("modelRelativeToRoot", modelRelativeToRoot); - - supportingFiles.add(new SupportingFile("index.mustache", "", "index.ts")); - supportingFiles.add(new SupportingFile("baseApi.mustache", "", "base.ts")); - supportingFiles.add(new SupportingFile("api.mustache", "", "api.ts")); - supportingFiles.add(new SupportingFile("configuration.mustache", "", "configuration.ts")); - supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh")); - supportingFiles.add(new SupportingFile("gitignore", "", ".gitignore")); - supportingFiles.add(new SupportingFile("npmignore", "", ".npmignore")); - - if (additionalProperties.containsKey(SEPARATE_MODELS_AND_API)) { - boolean separateModelsAndApi = Boolean.parseBoolean(additionalProperties.get(SEPARATE_MODELS_AND_API).toString()); - if (separateModelsAndApi) { - if (StringUtils.isAnyBlank(modelPackage, apiPackage)) { - throw new RuntimeException("apiPackage and modelPackage must be defined"); - } - modelTemplateFiles.put("model.mustache", ".ts"); - apiTemplateFiles.put("apiInner.mustache", ".ts"); - supportingFiles.add(new SupportingFile("modelIndex.mustache", tsModelPackage, "index.ts")); - } + // for symbol, e.g. $, # + if (getSymbolName(name) != null) { + return camelize(getSymbolName(name)); } - if (additionalProperties.containsKey(NPM_NAME)) { - addNpmPackageGeneration(); + // number + if ("number".equals(datatype)) { + String varName = "NUMBER_" + name; + + varName = varName.replaceAll("-", "MINUS_"); + varName = varName.replaceAll("\\+", "PLUS_"); + varName = varName.replaceAll("\\.", "_DOT_"); + return varName; } + String enumName = name; + if (enumName.matches("\\d.*")) { // starts with number + return "_" + enumName; + } else { + return enumName; + } } @Override - public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) { - objs = super.postProcessOperationsWithModels(objs, allModels); - Map<String, Object> vals = (Map<String, Object>) objs.getOrDefault("operations", new HashMap<>()); - List<CodegenOperation> operations = (List<CodegenOperation>) vals.getOrDefault("operation", new ArrayList<>()); - /* - Filter all the operations that are multipart/form-data operations and set the vendor extension flag - 'multipartFormData' for the template to work with. - */ - operations.stream() - .filter(op -> op.hasConsumes) - .filter(op -> op.consumes.stream().anyMatch(opc -> opc.values().stream().anyMatch("multipart/form-data"::equals))) - .forEach(op -> op.vendorExtensions.putIfAbsent("multipartFormData", true)); - return objs; - } + public String toEnumName(CodegenProperty property) { + String enumName = toModelName(property.name); - @Override - public Map<String, Object> postProcessAllModels(Map<String, Object> objs) { - Map<String, Object> result = super.postProcessAllModels(objs); - for (Map.Entry<String, Object> entry : result.entrySet()) { - Map<String, Object> inner = (Map<String, Object>) entry.getValue(); - List<Map<String, Object>> models = (List<Map<String, Object>>) inner.get("models"); - for (Map<String, Object> model : models) { - CodegenModel codegenModel = (CodegenModel) model.get("model"); - model.put("hasAllOf", codegenModel.allOf.size() > 0); - model.put("hasOneOf", codegenModel.oneOf.size() > 0); - } + if (enumName.matches("\\d.*")) { // starts with number + return "_" + enumName; + } else { + return enumName; } - return result; } - @Override - protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) { - codegenModel.additionalPropertiesType = getTypeDeclaration(getAdditionalProperties(schema)); - addImport(codegenModel, codegenModel.additionalPropertiesType); + protected Builder<String, Lambda> addMustacheLambdas() { + return super.addMustacheLambdas().put("snakecase_param", new CaseFormatLambda(LOWER_CAMEL, LOWER_UNDERSCORE)); } @Override @SuppressWarnings("unchecked") public Map<String, Object> postProcessModels(Map<String, Object> objs) { - List<Object> models = (List<Object>) postProcessModelsEnum(objs).get("models"); - - boolean withoutPrefixEnums = false; - if (additionalProperties.containsKey(WITHOUT_PREFIX_ENUMS)) { - withoutPrefixEnums = Boolean.parseBoolean(additionalProperties.get(WITHOUT_PREFIX_ENUMS).toString()); - } + Map<String, Object> result = super.postProcessModels(objs); - for (Object _mo : models) { - Map<String, Object> mo = (Map<String, Object>) _mo; + // Add additional filename information for imports + List<Map<String, Object>> models = (List<Map<String, Object>>) postProcessModelsEnum(result).get("models"); + for (Map<String, Object> mo : models) { CodegenModel cm = (CodegenModel) mo.get("model"); - - // Deduce the model file name in kebab case - cm.classFilename = cm.classname.replaceAll("([a-z0-9])([A-Z])", "$1-$2").toLowerCase(Locale.ROOT); - - //processed enum names - if(!withoutPrefixEnums) { - cm.imports = new TreeSet(cm.imports); - // name enum with model name, e.g. StatusEnum => PetStatusEnum - for (CodegenProperty var : cm.vars) { - if (Boolean.TRUE.equals(var.isEnum)) { - var.datatypeWithEnum = var.datatypeWithEnum.replace(var.enumName, cm.classname + var.enumName); - var.enumName = var.enumName.replace(var.enumName, cm.classname + var.enumName); - } - } - if (cm.parent != null) { - for (CodegenProperty var : cm.allVars) { - if (Boolean.TRUE.equals(var.isEnum)) { - var.datatypeWithEnum = var.datatypeWithEnum.replace(var.enumName, cm.classname + var.enumName); - var.enumName = var.enumName.replace(var.enumName, cm.classname + var.enumName); - } - } - } - } + mo.put("tsImports", toTsImports(cm.imports)); } - // Apply the model file name to the imports as well - for (Map<String, String> m : (List<Map<String, String>>) objs.get("imports")) { - String javaImport = m.get("import").substring(modelPackage.length() + 1); - String tsImport = tsModelPackage + "/" + javaImport; - m.put("tsImport", tsImport); - m.put("class", javaImport); - m.put("filename", javaImport.replaceAll("([a-z0-9])([A-Z])", "$1-$2").toLowerCase(Locale.ROOT)); - } - return objs; - } - - /** - * Overriding toRegularExpression() to avoid escapeText() being called, - * as it would return a broken regular expression if any escaped character / metacharacter were present. - */ - @Override - public String toRegularExpression(String pattern) { - return addRegularExpressionDelimiter(pattern); + return result; } - @Override - public String toModelFilename(String name) { - return super.toModelFilename(name).replaceAll("([a-z0-9])([A-Z])", "$1-$2").toLowerCase(Locale.ROOT); + private List<Map<String, String>> toTsImports(Set<String> imports) { + List<Map<String, String>> tsImports = new ArrayList<>(); + for (String im : imports) { + HashMap<String, String> tsImport = new HashMap<>(); + tsImport.put("classname", im); + tsImport.put("filename", toModelFilename(im)); + tsImports.add(tsImport); + } + return tsImports; } @Override - public String toApiFilename(String name) { - return super.toApiFilename(name).replaceAll("([a-z0-9])([A-Z])", "$1-$2").toLowerCase(Locale.ROOT); - } - - private void addNpmPackageGeneration() { + public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> operations, List<Object> allModels) { + // Add additional filename information for model imports in the services + List<Map<String, Object>> imports = (List<Map<String, Object>>) operations.get("imports"); + for (Map<String, Object> im : imports) { + im.put("filename", im.get("import")); + im.put("classname", getModelnameFromModelFilename(im.get("filename").toString())); + } - if (additionalProperties.containsKey(NPM_REPOSITORY)) { - this.setNpmRepository(additionalProperties.get(NPM_REPOSITORY).toString()); + // if there are any form params, we'll need to import stringify + Map<String, Object> opsObj = (Map<String, Object>) operations.get("operations"); + List<CodegenOperation> ops = (List<CodegenOperation>) opsObj.get("operation"); + boolean anyHasFormParams = false; + for (CodegenOperation op : ops) { + if (op.getHasFormParams()) { + anyHasFormParams = true; + } + } + if (anyHasFormParams) { + operations.put("hasFormParams", true); } - //Files for building our lib - supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); - supportingFiles.add(new SupportingFile("package.mustache", "", "package.json")); - supportingFiles.add(new SupportingFile("tsconfig.mustache", "", "tsconfig.json")); + return operations; } -} + private String getModelnameFromModelFilename(String filename) { + return filename.substring((modelPackage() + "/").length()); + } +} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/README.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/README.mustache deleted file mode 100644 index 21e49aeafc4..00000000000 --- a/modules/openapi-generator/src/main/resources/typescript-axios/README.mustache +++ /dev/null @@ -1,45 +0,0 @@ -## {{npmName}}@{{npmVersion}} - -This generator creates TypeScript/JavaScript client that utilizes [axios](https://github.com/axios/axios). The generated Node module can be used in the following environments: - -Environment -* Node.js -* Webpack -* Browserify - -Language level -* ES5 - you must have a Promises/A+ library installed -* ES6 - -Module system -* CommonJS -* ES6 module system - -It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html)) - -### Building - -To build and compile the typescript sources to javascript use: -``` -npm install -npm run build -``` - -### Publishing - -First build the package then run ```npm publish``` - -### Consuming - -navigate to the folder of your consuming project and run one of the following commands. - -_published:_ - -``` -npm install {{npmName}}@{{npmVersion}} --save -``` - -_unPublished (not recommended):_ - -``` -npm install PATH_TO_GENERATED_PACKAGE --save diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/api.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/api.mustache index 19ce266882d..33ef83b5cd2 100644 --- a/modules/openapi-generator/src/main/resources/typescript-axios/api.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-axios/api.mustache @@ -1,22 +1,60 @@ -/* tslint:disable */ -/* eslint-disable */ {{>licenseInfo}} +import { AxiosRequestConfig } from 'axios'; +import { axios } from '../axios.config'; +{{#hasFormParams}} +import { stringify } from 'qs'; +{{/hasFormParams}} -{{^withSeparateModelsAndApi}} -import * as globalImportUrl from 'url'; -import { Configuration } from './configuration'; -import globalAxios, { AxiosPromise, AxiosInstance } from 'axios'; -// Some imports not used depending on template conditions -// @ts-ignore -import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from './base'; +{{#imports}} +import { {{classname}} } from '../{{filename}}'; +{{/imports}} -{{#models}} -{{#model}}{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{#oneOf}}{{#-first}}{{>modelOneOf}}{{/-first}}{{/oneOf}}{{^isEnum}}{{^oneOf}}{{>modelGeneric}}{{/oneOf}}{{/isEnum}}{{/model}} -{{/models}} -{{#apiInfo}}{{#apis}} -{{>apiInner}} -{{/apis}}{{/apiInfo}} -{{/withSeparateModelsAndApi}}{{#withSeparateModelsAndApi}} -{{#apiInfo}}{{#apis}}{{#operations}}export * from './{{tsApiPackage}}/{{classFilename}}'; -{{/operations}}{{/apis}}{{/apiInfo}} -{{/withSeparateModelsAndApi}} +/* tslint:disable:no-unused-variable member-ordering max-line-length */ +/* eslint-disable no-useless-concat */ + +{{#operations}} +{{#description}} +/** + * {{&description}} + */ +{{/description}} +export class {{classname}}Resource { + +{{#operation}} + /** + * {{summary}} + * {{notes}} + {{#allParams}}* @param {{paramName}} {{description}} + {{/allParams}}*/ + public {{nickname}}({{#allParams}}{{^isQueryParam}}{{^isCookieParam}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/isCookieParam}}{{/isQueryParam}}{{/allParams}}{{#hasQueryParams}}query?: { {{#queryParams}}{{#lambda.snakecase_param}}{{paramName}}{{/lambda.snakecase_param}}{{^required}}?{{/required}}: {{{dataType}}}{{^-last}},{{/-last}} {{/queryParams}}}, {{/hasQueryParams}}axiosConfig?: AxiosRequestConfig): Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}> { + const reqPath = '{{path}}'{{#pathParams}} + .replace('{' + '{{baseName}}}', String({{paramName}}{{#isDateTime}}.toISOString(){{/isDateTime}})){{/pathParams}}; +{{#hasFormParams}} + let reqFormParams = { +{{#formParams}} + {{baseName}}: {{paramName}}{{^-last}},{{/-last}} +{{/formParams}} + }; +{{/hasFormParams}} + let reqConfig = { + ...axiosConfig, + method: '{{httpMethod}}', + url: reqPath{{#hasQueryParams}}, + params: query{{/hasQueryParams}}{{#bodyParam}}, + data: {{paramName}}{{/bodyParam}}{{#hasFormParams}}, + headers: { 'Content-Type': 'application/x-www-form-urlencoded'}, + data: stringify(reqFormParams) +{{/hasFormParams}} + + }; + return axios.request(reqConfig) + .then(res => { + return res.data; + }); + } + +{{/operation}} +} +{{/operations}} + +export const {{classname}} = new {{classname}}Resource(); diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/apiInner.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/apiInner.mustache deleted file mode 100644 index 10bb9f95761..00000000000 --- a/modules/openapi-generator/src/main/resources/typescript-axios/apiInner.mustache +++ /dev/null @@ -1,369 +0,0 @@ -{{#withSeparateModelsAndApi}} -/* tslint:disable */ -/* eslint-disable */ -{{>licenseInfo}} - -import * as globalImportUrl from 'url'; -import globalAxios, { AxiosPromise, AxiosInstance } from 'axios'; -import { Configuration } from '{{apiRelativeToRoot}}configuration'; -// Some imports not used depending on template conditions -// @ts-ignore -import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from '{{apiRelativeToRoot}}base'; -{{#imports}} -// @ts-ignore -import { {{classname}} } from '{{apiRelativeToRoot}}{{tsModelPackage}}'; -{{/imports}} -{{/withSeparateModelsAndApi}} -{{^withSeparateModelsAndApi}} -{{/withSeparateModelsAndApi}} -{{#operations}} -/** - * {{classname}} - axios parameter creator{{#description}} - * {{&description}}{{/description}} - * @export - */ -export const {{classname}}AxiosParamCreator = function (configuration?: Configuration) { - return { - {{#operation}} - /** - * {{¬es}} - {{#summary}} - * @summary {{&summary}} - {{/summary}} - {{#allParams}} - * @param {{=<% %>=}}{<%&dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}} - {{/allParams}} - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - {{nickname}}: async ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options: any = {}): Promise<RequestArgs> => { - {{#allParams}} - {{#required}} - // verify required parameter '{{paramName}}' is not null or undefined - if ({{paramName}} === null || {{paramName}} === undefined) { - throw new RequiredError('{{paramName}}','Required parameter {{paramName}} was null or undefined when calling {{nickname}}.'); - } - {{/required}} - {{/allParams}} - const localVarPath = `{{{path}}}`{{#pathParams}} - .replace(`{${"{{baseName}}"}}`, encodeURIComponent(String({{paramName}}))){{/pathParams}}; - const localVarUrlObj = globalImportUrl.parse(localVarPath, true); - let baseOptions; - if (configuration) { - baseOptions = configuration.baseOptions; - } - const localVarRequestOptions = { method: '{{httpMethod}}', ...baseOptions, ...options}; - const localVarHeaderParameter = {} as any; - const localVarQueryParameter = {} as any;{{#vendorExtensions}}{{#hasFormParams}} - const localVarFormParams = new {{^multipartFormData}}URLSearchParams(){{/multipartFormData}}{{#multipartFormData}}FormData(){{/multipartFormData}};{{/hasFormParams}}{{/vendorExtensions}} - - {{#authMethods}} - // authentication {{name}} required - {{#isApiKey}} - {{#isKeyInHeader}} - if (configuration && configuration.apiKey) { - const localVarApiKeyValue = typeof configuration.apiKey === 'function' - ? await configuration.apiKey("{{keyParamName}}") - : await configuration.apiKey; - localVarHeaderParameter["{{keyParamName}}"] = localVarApiKeyValue; - } - {{/isKeyInHeader}} - {{#isKeyInQuery}} - if (configuration && configuration.apiKey) { - const localVarApiKeyValue = typeof configuration.apiKey === 'function' - ? await configuration.apiKey("{{keyParamName}}") - : await configuration.apiKey; - localVarQueryParameter["{{keyParamName}}"] = localVarApiKeyValue; - } - {{/isKeyInQuery}} - {{/isApiKey}} - {{#isBasicBasic}} - // http basic authentication required - if (configuration && (configuration.username || configuration.password)) { - localVarRequestOptions["auth"] = { username: configuration.username, password: configuration.password }; - } - {{/isBasicBasic}} - {{#isBasicBearer}} - // http bearer authentication required - if (configuration && configuration.accessToken) { - const accessToken = typeof configuration.accessToken === 'function' - ? configuration.accessToken() - : configuration.accessToken; - localVarHeaderParameter["Authorization"] = "Bearer " + accessToken; - } - {{/isBasicBearer}} - {{#isOAuth}} - // oauth required - if (configuration && configuration.accessToken) { - const localVarAccessTokenValue = typeof configuration.accessToken === 'function' - ? configuration.accessToken("{{name}}", [{{#scopes}}"{{{scope}}}"{{^-last}}, {{/-last}}{{/scopes}}]) - : configuration.accessToken; - localVarHeaderParameter["Authorization"] = "Bearer " + localVarAccessTokenValue; - } - {{/isOAuth}} - - {{/authMethods}} - {{#queryParams}} - {{#isListContainer}} - if ({{paramName}}) { - {{#isCollectionFormatMulti}} - localVarQueryParameter['{{baseName}}'] = {{paramName}}; - {{/isCollectionFormatMulti}} - {{^isCollectionFormatMulti}} - localVarQueryParameter['{{baseName}}'] = {{paramName}}.join(COLLECTION_FORMATS.{{collectionFormat}}); - {{/isCollectionFormatMulti}} - } - {{/isListContainer}} - {{^isListContainer}} - if ({{paramName}} !== undefined) { - {{#isDateTime}} - localVarQueryParameter['{{baseName}}'] = ({{paramName}} as any instanceof Date) ? - ({{paramName}} as any).toISOString() : - {{paramName}}; - {{/isDateTime}} - {{^isDateTime}} - {{#isDate}} - localVarQueryParameter['{{baseName}}'] = ({{paramName}} as any instanceof Date) ? - ({{paramName}} as any).toISOString().substr(0,10) : - {{paramName}}; - {{/isDate}} - {{^isDate}} - localVarQueryParameter['{{baseName}}'] = {{paramName}}; - {{/isDate}} - {{/isDateTime}} - } - {{/isListContainer}} - - {{/queryParams}} - {{#headerParams}} - {{#isListContainer}} - if ({{paramName}}) { - let mapped = {{paramName}}.map(value => (<any>"{{{dataType}}}" !== "Array<string>") ? JSON.stringify(value) : (value || "")); - localVarHeaderParameter['{{baseName}}'] = mapped.join(COLLECTION_FORMATS["{{collectionFormat}}"]); - } - {{/isListContainer}} - {{^isListContainer}} - if ({{paramName}} !== undefined && {{paramName}} !== null) { - {{#isString}} - localVarHeaderParameter['{{baseName}}'] = String({{paramName}}); - {{/isString}} - {{^isString}} - localVarHeaderParameter['{{baseName}}'] = String(JSON.stringify({{paramName}})); - {{/isString}} - } - {{/isListContainer}} - - {{/headerParams}} - {{#vendorExtensions}} - {{#formParams}} - {{#isListContainer}} - if ({{paramName}}) { - {{#isCollectionFormatMulti}} - {{paramName}}.forEach((element) => { - localVarFormParams.append('{{baseName}}', element as any); - }) - {{/isCollectionFormatMulti}} - {{^isCollectionFormatMulti}}{{^multipartFormData}} - localVarFormParams.set('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS.{{collectionFormat}}));{{/multipartFormData}}{{#multipartFormData}} - localVarFormParams.append('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS.{{collectionFormat}}));{{/multipartFormData}} - {{/isCollectionFormatMulti}} - }{{/isListContainer}} - {{^isListContainer}} - if ({{paramName}} !== undefined) { {{^multipartFormData}} - localVarFormParams.set('{{baseName}}', {{paramName}} as any);{{/multipartFormData}}{{#multipartFormData}} - localVarFormParams.append('{{baseName}}', {{paramName}} as any);{{/multipartFormData}} - } - {{/isListContainer}} - {{/formParams}}{{/vendorExtensions}} - {{#vendorExtensions}}{{#hasFormParams}}{{^multipartFormData}} - localVarHeaderParameter['Content-Type'] = 'application/x-www-form-urlencoded';{{/multipartFormData}}{{#multipartFormData}} - localVarHeaderParameter['Content-Type'] = 'multipart/form-data';{{/multipartFormData}} - {{/hasFormParams}}{{/vendorExtensions}} - {{#bodyParam}} - {{^consumes}} - localVarHeaderParameter['Content-Type'] = 'application/json'; - {{/consumes}} - {{#consumes.0}} - localVarHeaderParameter['Content-Type'] = '{{{mediaType}}}'; - {{/consumes.0}} - - {{/bodyParam}} - localVarUrlObj.query = {...localVarUrlObj.query, ...localVarQueryParameter, ...options.query}; - // fix override query string Detail: https://stackoverflow.com/a/7517673/1077943 - delete localVarUrlObj.search; - let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; - localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - {{#hasFormParams}} - localVarRequestOptions.data = localVarFormParams{{#vendorExtensions}}{{^multipartFormData}}.toString(){{/multipartFormData}}{{/vendorExtensions}}; - {{/hasFormParams}} - {{#bodyParam}} - const needsSerialization = (typeof {{paramName}} !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json'; - localVarRequestOptions.data = needsSerialization ? JSON.stringify({{paramName}} !== undefined ? {{paramName}} : {}) : ({{paramName}} || ""); - {{/bodyParam}} - - return { - url: globalImportUrl.format(localVarUrlObj), - options: localVarRequestOptions, - }; - }, - {{/operation}} - } -}; - -/** - * {{classname}} - functional programming interface{{#description}} - * {{{description}}}{{/description}} - * @export - */ -export const {{classname}}Fp = function(configuration?: Configuration) { - return { - {{#operation}} - /** - * {{¬es}} - {{#summary}} - * @summary {{&summary}} - {{/summary}} - {{#allParams}} - * @param {{=<% %>=}}{<%&dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}} - {{/allParams}} - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}>> { - const localVarAxiosArgs = await {{classname}}AxiosParamCreator(configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options); - return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => { - const axiosRequestArgs = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url}; - return axios.request(axiosRequestArgs); - }; - }, - {{/operation}} - } -}; - -/** - * {{classname}} - factory interface{{#description}} - * {{&description}}{{/description}} - * @export - */ -export const {{classname}}Factory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) { - return { - {{#operation}} - /** - * {{¬es}} - {{#summary}} - * @summary {{&summary}} - {{/summary}} - {{#allParams}} - * @param {{=<% %>=}}{<%&dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}} - {{/allParams}} - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any): AxiosPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> { - return {{classname}}Fp(configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options).then((request) => request(axios, basePath)); - }, - {{/operation}} - }; -}; - -{{#withInterfaces}} -/** - * {{classname}} - interface{{#description}} - * {{&description}}{{/description}} - * @export - * @interface {{classname}} - */ -export interface {{classname}}Interface { -{{#operation}} - /** - * {{¬es}} - {{#summary}} - * @summary {{&summary}} - {{/summary}} - {{#allParams}} - * @param {{=<% %>=}}{<%&dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}} - {{/allParams}} - * @param {*} [options] Override http request option. - * @throws {RequiredError} - * @memberof {{classname}}Interface - */ - {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any): AxiosPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}>; - -{{/operation}} -} - -{{/withInterfaces}} -{{#useSingleRequestParameter}} -{{#operation}} -{{#allParams.0}} -/** - * Request parameters for {{nickname}} operation in {{classname}}. - * @export - * @interface {{classname}}{{operationIdCamelCase}}Request - */ -export interface {{classname}}{{operationIdCamelCase}}Request { - {{#allParams}} - /** - * {{description}} - * @type {{=<% %>=}}{<%&dataType%>}<%={{ }}=%> - * @memberof {{classname}}{{operationIdCamelCase}} - */ - readonly {{paramName}}{{^required}}?{{/required}}: {{{dataType}}} - {{^-last}} - - {{/-last}} - {{/allParams}} -} - -{{/allParams.0}} -{{/operation}} -{{/useSingleRequestParameter}} -/** - * {{classname}} - object-oriented interface{{#description}} - * {{{description}}}{{/description}} - * @export - * @class {{classname}} - * @extends {BaseAPI} - */ -{{#withInterfaces}} -export class {{classname}} extends BaseAPI implements {{classname}}Interface { -{{/withInterfaces}} -{{^withInterfaces}} -export class {{classname}} extends BaseAPI { -{{/withInterfaces}} - {{#operation}} - /** - * {{¬es}} - {{#summary}} - * @summary {{&summary}} - {{/summary}} - {{#useSingleRequestParameter}} - {{#allParams.0}} - * @param {{=<% %>=}}{<%& classname %><%& operationIdCamelCase %>Request}<%={{ }}=%> requestParameters Request parameters. - {{/allParams.0}} - {{/useSingleRequestParameter}} - {{^useSingleRequestParameter}} - {{#allParams}} - * @param {{=<% %>=}}{<%&dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}} - {{/allParams}} - {{/useSingleRequestParameter}} - * @param {*} [options] Override http request option. - * @throws {RequiredError} - * @memberof {{classname}} - */ - {{#useSingleRequestParameter}} - public {{nickname}}({{#allParams.0}}requestParameters: {{classname}}{{operationIdCamelCase}}Request{{^hasRequiredParams}} = {}{{/hasRequiredParams}}, {{/allParams.0}}options?: any) { - return {{classname}}Fp(this.configuration).{{nickname}}({{#allParams.0}}{{#allParams}}requestParameters.{{paramName}}, {{/allParams}}{{/allParams.0}}options).then((request) => request(this.axios, this.basePath)); - } - {{/useSingleRequestParameter}} - {{^useSingleRequestParameter}} - public {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any) { - return {{classname}}Fp(this.configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options).then((request) => request(this.axios, this.basePath)); - } - {{/useSingleRequestParameter}} - {{^-last}} - - {{/-last}} - {{/operation}} -} -{{/operations}} diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/baseApi.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/baseApi.mustache deleted file mode 100644 index 519b7c7d948..00000000000 --- a/modules/openapi-generator/src/main/resources/typescript-axios/baseApi.mustache +++ /dev/null @@ -1,60 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -{{>licenseInfo}} - -import { Configuration } from "./configuration"; -// Some imports not used depending on template conditions -// @ts-ignore -import globalAxios, { AxiosPromise, AxiosInstance } from 'axios'; - -export const BASE_PATH = "{{{basePath}}}".replace(/\/+$/, ""); - -/** - * - * @export - */ -export const COLLECTION_FORMATS = { - csv: ",", - ssv: " ", - tsv: "\t", - pipes: "|", -}; - -/** - * - * @export - * @interface RequestArgs - */ -export interface RequestArgs { - url: string; - options: any; -} - -/** - * - * @export - * @class BaseAPI - */ -export class BaseAPI { - protected configuration: Configuration | undefined; - - constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) { - if (configuration) { - this.configuration = configuration; - this.basePath = configuration.basePath || this.basePath; - } - } -}; - -/** - * - * @export - * @class RequiredError - * @extends {Error} - */ -export class RequiredError extends Error { - name: "RequiredError" = "RequiredError"; - constructor(public field: string, msg?: string) { - super(msg); - } -} diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/configuration.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/configuration.mustache deleted file mode 100644 index 49fc09da60a..00000000000 --- a/modules/openapi-generator/src/main/resources/typescript-axios/configuration.mustache +++ /dev/null @@ -1,65 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -{{>licenseInfo}} - -export interface ConfigurationParameters { - apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>); - username?: string; - password?: string; - accessToken?: string | ((name?: string, scopes?: string[]) => string); - basePath?: string; - baseOptions?: any; -} - -export class Configuration { - /** - * parameter for apiKey security - * @param name security name - * @memberof Configuration - */ - apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>); - /** - * parameter for basic security - * - * @type {string} - * @memberof Configuration - */ - username?: string; - /** - * parameter for basic security - * - * @type {string} - * @memberof Configuration - */ - password?: string; - /** - * parameter for oauth2 security - * @param name security name - * @param scopes oauth2 scope - * @memberof Configuration - */ - accessToken?: string | ((name?: string, scopes?: string[]) => string); - /** - * override base path - * - * @type {string} - * @memberof Configuration - */ - basePath?: string; - /** - * base options for axios calls - * - * @type {any} - * @memberof Configuration - */ - baseOptions?: any; - - constructor(param: ConfigurationParameters = {}) { - this.apiKey = param.apiKey; - this.username = param.username; - this.password = param.password; - this.accessToken = param.accessToken; - this.basePath = param.basePath; - this.baseOptions = param.baseOptions; - } -} diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/git_push.sh.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/git_push.sh.mustache deleted file mode 100755 index 8b3f689c912..00000000000 --- a/modules/openapi-generator/src/main/resources/typescript-axios/git_push.sh.mustache +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/sh -# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ -# -# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" "gitlab.com" - -git_user_id=$1 -git_repo_id=$2 -release_note=$3 -git_host=$4 - -if [ "$git_host" = "" ]; then - git_host="{{{gitHost}}}" - echo "[INFO] No command line input provided. Set \$git_host to $git_host" -fi - -if [ "$git_user_id" = "" ]; then - git_user_id="{{{gitUserId}}}" - echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" -fi - -if [ "$git_repo_id" = "" ]; then - git_repo_id="{{{gitRepoId}}}" - echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" -fi - -if [ "$release_note" = "" ]; then - release_note="{{{releaseNote}}}" - echo "[INFO] No command line input provided. Set \$release_note to $release_note" -fi - -# Initialize the local directory as a Git repository -git init - -# Adds the files in the local repository and stages them for commit. -git add . - -# Commits the tracked changes and prepares them to be pushed to a remote repository. -git commit -m "$release_note" - -# Sets the new remote -git_remote=`git remote` -if [ "$git_remote" = "" ]; then # git remote not defined - - if [ "$GIT_TOKEN" = "" ]; then - echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." - git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git - else - git remote add origin https://${git_user_id}:${GIT_TOKEN}@${git_host}/${git_user_id}/${git_repo_id}.git - fi - -fi - -git pull origin master - -# Pushes (Forces) the changes in the local repository up to the remote repository -echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" -git push origin master 2>&1 | grep -v 'To https' - diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/gitignore b/modules/openapi-generator/src/main/resources/typescript-axios/gitignore deleted file mode 100644 index 205d8013f46..00000000000 --- a/modules/openapi-generator/src/main/resources/typescript-axios/gitignore +++ /dev/null @@ -1,4 +0,0 @@ -wwwroot/*.js -node_modules -typings -dist \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/index.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/index.mustache deleted file mode 100644 index b96435d71a7..00000000000 --- a/modules/openapi-generator/src/main/resources/typescript-axios/index.mustache +++ /dev/null @@ -1,6 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -{{>licenseInfo}} - -export * from "./api"; -export * from "./configuration"; diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/licenseInfo.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/licenseInfo.mustache index 9866f297a4d..bbd8742e52a 100644 --- a/modules/openapi-generator/src/main/resources/typescript-axios/licenseInfo.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-axios/licenseInfo.mustache @@ -2,10 +2,10 @@ * {{{appName}}} * {{{appDescription}}} * - * {{#version}}The version of the OpenAPI document: {{{version}}}{{/version}} + * {{#version}}OpenAPI spec version: {{{version}}}{{/version}} * {{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}} * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. */ 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 976a611b2f2..41eeb1a0a8b 100644 --- a/modules/openapi-generator/src/main/resources/typescript-axios/model.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-axios/model.mustache @@ -1,11 +1,9 @@ -/* tslint:disable */ -/* eslint-disable */ {{>licenseInfo}} -{{#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}}{{#allOf}}{{#-first}}{{>modelAllOf}}{{/-first}}{{/allOf}}{{^isEnum}}{{^oneOf}}{{^allOf}}{{>modelGeneric}}{{/allOf}}{{/oneOf}}{{/isEnum}} -{{/model}}{{/models}} - +{{#models}} +{{#model}} +{{#tsImports}} +import { {{classname}} } from './{{filename}}'; +{{/tsImports}}{{#description}} +/* {{{description}}} */{{/description}}{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{>modelGeneric}}{{/isEnum}} +{{/model}} +{{/models}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/modelAllOf.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/modelAllOf.mustache deleted file mode 100644 index 0c0dbf9fd89..00000000000 --- a/modules/openapi-generator/src/main/resources/typescript-axios/modelAllOf.mustache +++ /dev/null @@ -1,6 +0,0 @@ -/** - * @type {{classname}}{{#description}} - * {{{description}}}{{/description}} - * @export - */ -export type {{classname}} = {{#allOf}}{{{.}}}{{^-last}} & {{/-last}}{{/allOf}}; diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/modelEnum.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/modelEnum.mustache index dc04cb0bd63..2a9730ec099 100644 --- a/modules/openapi-generator/src/main/resources/typescript-axios/modelEnum.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-axios/modelEnum.mustache @@ -1,12 +1,12 @@ -/** - * {{{description}}} - * @export - * @enum {string} - */ +{{#description}} + /** + * {{{description}}} + */ +{{/description}} export enum {{classname}} { {{#allowableValues}} {{#enumVars}} - {{{name}}} = {{{value}}}{{^-last}},{{/-last}} + {{{name}}}{{^-last}},{{/-last}} {{/enumVars}} {{/allowableValues}} -} +} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/modelGeneric.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/modelGeneric.mustache index b332ec25a0e..a0ecaab97fa 100644 --- a/modules/openapi-generator/src/main/resources/typescript-axios/modelGeneric.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-axios/modelGeneric.mustache @@ -1,39 +1,26 @@ -/** - * {{{description}}} - * @export - * @interface {{classname}} - */ -export interface {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{ +export interface {{classname}} {{#parent}}extends models.{{{parent}}} {{/parent}}{ {{#additionalPropertiesType}} [key: string]: {{{additionalPropertiesType}}}{{#hasVars}} | any{{/hasVars}}; {{/additionalPropertiesType}} {{#vars}} + {{#description}} /** * {{{description}}} - * @type {{=<% %>=}}{<%&datatype%>}<%={{ }}=%> - * @memberof {{classname}} - {{#deprecated}} - * @deprecated - {{/deprecated}} */ - {{name}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{#isNullable}} | null{{/isNullable}}{{/isEnum}}; -{{/vars}} -}{{#hasEnums}} + {{/description}} + {{name}}{{^required}}?{{/required}}: {{#isEnum}}{{classname}}{{enumName}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}; -{{#vars}} -{{#isEnum}} -/** - * @export - * @enum {string} - */ -export enum {{enumName}} { -{{#allowableValues}} - {{#enumVars}} - {{{name}}} = {{{value}}}{{^-last}},{{/-last}} - {{/enumVars}} -{{/allowableValues}} -} -{{/isEnum}} {{/vars}} -{{/hasEnums}} +} + +{{#hasEnums}} +{{#vars}}{{#isEnum}} + export enum {{classname}}{{enumName}} { + {{#allowableValues}} + {{#enumVars}} + {{{name}}} = {{{value}}}{{^-last}},{{/-last}} + {{/enumVars}} + {{/allowableValues}} + }{{/isEnum}}{{/vars}} +{{/hasEnums}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/modelIndex.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/modelIndex.mustache deleted file mode 100644 index 947111206c5..00000000000 --- a/modules/openapi-generator/src/main/resources/typescript-axios/modelIndex.mustache +++ /dev/null @@ -1,2 +0,0 @@ -{{#models}}{{#model}}export * from './{{classFilename}}';{{/model}} -{{/models}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/modelOneOf.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/modelOneOf.mustache deleted file mode 100644 index ac93c4ab199..00000000000 --- a/modules/openapi-generator/src/main/resources/typescript-axios/modelOneOf.mustache +++ /dev/null @@ -1,6 +0,0 @@ -/** - * @type {{classname}}{{#description}} - * {{{description}}}{{/description}} - * @export - */ -export type {{classname}} = {{#oneOf}}{{{.}}}{{^-last}} | {{/-last}}{{/oneOf}}; diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/npmignore b/modules/openapi-generator/src/main/resources/typescript-axios/npmignore deleted file mode 100644 index 999d88df693..00000000000 --- a/modules/openapi-generator/src/main/resources/typescript-axios/npmignore +++ /dev/null @@ -1 +0,0 @@ -# empty npmignore to ensure all required files (e.g., in the dist folder) are published by npm \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/package.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/package.mustache deleted file mode 100644 index da07d370fa4..00000000000 --- a/modules/openapi-generator/src/main/resources/typescript-axios/package.mustache +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "{{npmName}}", - "version": "{{npmVersion}}", - "description": "OpenAPI client for {{npmName}}", - "author": "OpenAPI-Generator Contributors", - "keywords": [ - "axios", - "typescript", - "openapi-client", - "openapi-generator", - "{{npmName}}" - ], - "license": "Unlicense", - "main": "./dist/index.js", - "typings": "./dist/index.d.ts", - "scripts": { - "build": "tsc --outDir dist/", - "prepublishOnly": "npm run build" - }, - "dependencies": { - "axios": "^0.19.2" - }, - "devDependencies": { - "@types/node": "^12.11.5", - "typescript": "^3.6.4" - }{{#npmRepository}},{{/npmRepository}} -{{#npmRepository}} - "publishConfig": { - "registry": "{{npmRepository}}" - } -{{/npmRepository}} -} diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/tsconfig.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/tsconfig.mustache deleted file mode 100644 index c4a4cc771e7..00000000000 --- a/modules/openapi-generator/src/main/resources/typescript-axios/tsconfig.mustache +++ /dev/null @@ -1,23 +0,0 @@ -{ - "compilerOptions": { - "declaration": true, - "target": "{{#supportsES6}}es6{{/supportsES6}}{{^supportsES6}}es5{{/supportsES6}}", - "module": "commonjs", - "noImplicitAny": true, - "outDir": "dist", - "rootDir": ".", - {{^supportsES6}} - "lib": [ - "es6", - "dom" - ], - {{/supportsES6}} - "typeRoots": [ - "node_modules/@types" - ] - }, - "exclude": [ - "dist", - "node_modules" - ] -} -- GitLab From 9bac0552a72b600d441b1f49ca0c289dba7e6ddd Mon Sep 17 00:00:00 2001 From: Jack Cross <jackjocross@gmail.com> Date: Thu, 18 Jun 2020 15:36:07 -0500 Subject: [PATCH 2/6] Update model enum to include value --- .../src/main/resources/typescript-axios/modelEnum.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/modelEnum.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/modelEnum.mustache index 2a9730ec099..5761cea848f 100644 --- a/modules/openapi-generator/src/main/resources/typescript-axios/modelEnum.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-axios/modelEnum.mustache @@ -6,7 +6,7 @@ export enum {{classname}} { {{#allowableValues}} {{#enumVars}} - {{{name}}}{{^-last}},{{/-last}} + {{{name}}} = {{{value}}}{{^-last}},{{/-last}} {{/enumVars}} {{/allowableValues}} } \ No newline at end of file -- GitLab From 2f8b742c39e1c98d775e1a69b0b9ecad0a844a26 Mon Sep 17 00:00:00 2001 From: Jack Cross <jackjocross@gmail.com> Date: Thu, 13 Aug 2020 17:32:07 -0500 Subject: [PATCH 3/6] Support nullable model fields --- .../src/main/resources/typescript-axios/modelGeneric.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/modelGeneric.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/modelGeneric.mustache index a0ecaab97fa..3125ea27d46 100644 --- a/modules/openapi-generator/src/main/resources/typescript-axios/modelGeneric.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-axios/modelGeneric.mustache @@ -9,7 +9,7 @@ export interface {{classname}} {{#parent}}extends models.{{{parent}}} {{/parent} * {{{description}}} */ {{/description}} - {{name}}{{^required}}?{{/required}}: {{#isEnum}}{{classname}}{{enumName}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}; + {{name}}{{^required}}?{{/required}}: {{#isEnum}}{{classname}}{{enumName}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}{{#isNullable}} | null{{/isNullable}}; {{/vars}} } -- GitLab From 637049414178cffe3f8e4fb68e6ac2275cf36f23 Mon Sep 17 00:00:00 2001 From: Stephen Leicht <stephen@findheadway.com> Date: Fri, 30 Apr 2021 10:44:31 -0400 Subject: [PATCH 4/6] Remove override for toEnumVarName --- .../TypeScriptAxiosClientCodegen.java | 29 ------------------- 1 file changed, 29 deletions(-) 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 4c063f9df34..5899f5403c5 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 @@ -72,35 +72,6 @@ public class TypeScriptAxiosClientCodegen extends AbstractTypeScriptClientCodege return modelPackage() + "/" + toModelFilename(name); } - @Override - public String toEnumVarName(String name, String datatype) { - if (name.length() == 0) { - return "Empty"; - } - - // for symbol, e.g. $, # - if (getSymbolName(name) != null) { - return camelize(getSymbolName(name)); - } - - // number - if ("number".equals(datatype)) { - String varName = "NUMBER_" + name; - - varName = varName.replaceAll("-", "MINUS_"); - varName = varName.replaceAll("\\+", "PLUS_"); - varName = varName.replaceAll("\\.", "_DOT_"); - return varName; - } - - String enumName = name; - if (enumName.matches("\\d.*")) { // starts with number - return "_" + enumName; - } else { - return enumName; - } - } - @Override public String toEnumName(CodegenProperty property) { String enumName = toModelName(property.name); -- GitLab From 9706a6d36750310d349002227dc80456132abc80 Mon Sep 17 00:00:00 2001 From: Emily Old <emily@findheadway.com> Date: Wed, 8 Sep 2021 16:23:09 -0400 Subject: [PATCH 5/6] exclude header params --- .../src/main/resources/typescript-axios/api.mustache | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/api.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/api.mustache index 33ef83b5cd2..eefeb42c293 100644 --- a/modules/openapi-generator/src/main/resources/typescript-axios/api.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-axios/api.mustache @@ -24,9 +24,10 @@ export class {{classname}}Resource { /** * {{summary}} * {{notes}} - {{#allParams}}* @param {{paramName}} {{description}} - {{/allParams}}*/ - public {{nickname}}({{#allParams}}{{^isQueryParam}}{{^isCookieParam}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/isCookieParam}}{{/isQueryParam}}{{/allParams}}{{#hasQueryParams}}query?: { {{#queryParams}}{{#lambda.snakecase_param}}{{paramName}}{{/lambda.snakecase_param}}{{^required}}?{{/required}}: {{{dataType}}}{{^-last}},{{/-last}} {{/queryParams}}}, {{/hasQueryParams}}axiosConfig?: AxiosRequestConfig): Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}> { + {{#allParams}}{{^isCookieParam}}{{^isHeaderParam}}* @param {{paramName}} {{description}} + {{/isHeaderParam}}{{/isCookieParam}}{{/allParams}} + */ + public {{nickname}}({{#allParams}}{{^isQueryParam}}{{^isCookieParam}}{{^isHeaderParam}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/isHeaderParam}}{{/isCookieParam}}{{/isQueryParam}}{{/allParams}}{{#hasQueryParams}}query?: { {{#queryParams}}{{#lambda.snakecase_param}}{{paramName}}{{/lambda.snakecase_param}}{{^required}}?{{/required}}: {{{dataType}}}{{^-last}},{{/-last}} {{/queryParams}}}, {{/hasQueryParams}}axiosConfig?: AxiosRequestConfig): Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}> { const reqPath = '{{path}}'{{#pathParams}} .replace('{' + '{{baseName}}}', String({{paramName}}{{#isDateTime}}.toISOString(){{/isDateTime}})){{/pathParams}}; {{#hasFormParams}} -- GitLab From c42172abcc626d746ab49304404c40a8bb83e0b1 Mon Sep 17 00:00:00 2001 From: Nathan Force <nathan@findheadway.com> Date: Wed, 22 Sep 2021 12:19:58 -0400 Subject: [PATCH 6/6] narrow method from string to Method --- .../src/main/resources/typescript-axios/api.mustache | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/api.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/api.mustache index eefeb42c293..04dddc91e6c 100644 --- a/modules/openapi-generator/src/main/resources/typescript-axios/api.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-axios/api.mustache @@ -1,5 +1,5 @@ {{>licenseInfo}} -import { AxiosRequestConfig } from 'axios'; +import { AxiosRequestConfig, Method } from 'axios'; import { axios } from '../axios.config'; {{#hasFormParams}} import { stringify } from 'qs'; @@ -39,7 +39,7 @@ export class {{classname}}Resource { {{/hasFormParams}} let reqConfig = { ...axiosConfig, - method: '{{httpMethod}}', + method: '{{httpMethod}}' as Method, url: reqPath{{#hasQueryParams}}, params: query{{/hasQueryParams}}{{#bodyParam}}, data: {{paramName}}{{/bodyParam}}{{#hasFormParams}}, -- GitLab