diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptRxjsClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptRxjsClientCodegen.java index 267711f9615..93a25c21f4c 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptRxjsClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptRxjsClientCodegen.java @@ -42,10 +42,6 @@ public class TypeScriptRxjsClientCodegen extends AbstractTypeScriptClientCodegen public TypeScriptRxjsClientCodegen() { super(); - // clear import mapping (from default generator) as TS does not use it - // at the moment - importMapping.clear(); - outputFolder = "generated-code/typescript-rxjs"; embeddedTemplateDir = templateDir = "typescript-rxjs"; @@ -55,6 +51,9 @@ public class TypeScriptRxjsClientCodegen extends AbstractTypeScriptClientCodegen this.modelTemplateFiles.put("models.mustache", ".ts"); this.addExtraReservedWords(); + languageSpecificPrimitives.add("Blob"); + typeMapping.put("file", "Blob"); + this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url 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())); } @@ -93,6 +92,11 @@ public class TypeScriptRxjsClientCodegen extends AbstractTypeScriptClientCodegen } } + @Override + public boolean isDataTypeFile(final String dataType) { + return dataType != null && dataType.equals("Blob"); + } + @Override public String getTypeDeclaration(Schema p) { Schema inner; @@ -162,6 +166,33 @@ public class TypeScriptRxjsClientCodegen extends AbstractTypeScriptClientCodegen return result; } + @Override + public void postProcessParameter(CodegenParameter parameter) { + super.postProcessParameter(parameter); + parameter.dataType = applyLocalTypeMapping(parameter.dataType); + } + + @Override + public String getSchemaType(Schema p) { + String openAPIType = super.getSchemaType(p); + if (isLanguagePrimitive(openAPIType)) { + return openAPIType; + } + applyLocalTypeMapping(openAPIType); + return openAPIType; + } + + private String applyLocalTypeMapping(String type) { + if (typeMapping.containsKey(type)) { + type = typeMapping.get(type); + } + return type; + } + + private boolean isLanguagePrimitive(String type) { + return languageSpecificPrimitives.contains(type); + } + private void addNpmPackageGeneration() { if (additionalProperties.containsKey(NPM_REPOSITORY)) { this.setNpmRepository(additionalProperties.get(NPM_REPOSITORY).toString()); @@ -290,10 +321,10 @@ public class TypeScriptRxjsClientCodegen extends AbstractTypeScriptClientCodegen this.reservedWords.add("ModelPropertyNaming"); this.reservedWords.add("RequestArgs"); this.reservedWords.add("RequestOpts"); + this.reservedWords.add("ResponseArgs"); this.reservedWords.add("exists"); - this.reservedWords.add("RequestContext"); - this.reservedWords.add("ResponseContext"); this.reservedWords.add("Middleware"); + this.reservedWords.add("AjaxRequest"); this.reservedWords.add("AjaxResponse"); } @@ -310,6 +341,7 @@ public class TypeScriptRxjsClientCodegen extends AbstractTypeScriptClientCodegen this.hasProduces = o.hasProduces; this.hasParams = o.hasParams; this.hasOptionalParams = o.hasOptionalParams; + this.hasRequiredParams = o.hasRequiredParams; this.returnTypeIsPrimitive = o.returnTypeIsPrimitive; this.returnSimpleType = o.returnSimpleType; this.subresourceOperation = o.subresourceOperation; @@ -318,6 +350,7 @@ public class TypeScriptRxjsClientCodegen extends AbstractTypeScriptClientCodegen this.isMultipart = o.isMultipart; this.hasMore = o.hasMore; this.isResponseBinary = o.isResponseBinary; + this.isResponseFile = o.isResponseFile; this.hasReference = o.hasReference; this.isRestfulIndex = o.isRestfulIndex; this.isRestfulShow = o.isRestfulShow; @@ -325,6 +358,8 @@ public class TypeScriptRxjsClientCodegen extends AbstractTypeScriptClientCodegen this.isRestfulUpdate = o.isRestfulUpdate; this.isRestfulDestroy = o.isRestfulDestroy; this.isRestful = o.isRestful; + this.isDeprecated = o.isDeprecated; + this.isCallbackRequest = o.isCallbackRequest; this.path = o.path; this.operationId = o.operationId; this.returnType = o.returnType; @@ -339,6 +374,8 @@ public class TypeScriptRxjsClientCodegen extends AbstractTypeScriptClientCodegen this.discriminator = o.discriminator; this.consumes = o.consumes; this.produces = o.produces; + this.prioritizedContentTypes = o.prioritizedContentTypes; + this.servers = o.servers; this.bodyParam = o.bodyParam; this.allParams = o.allParams; this.bodyParams = o.bodyParams; @@ -346,18 +383,23 @@ public class TypeScriptRxjsClientCodegen extends AbstractTypeScriptClientCodegen this.queryParams = o.queryParams; this.headerParams = o.headerParams; this.formParams = o.formParams; + this.cookieParams = o.cookieParams; this.requiredParams = o.requiredParams; this.optionalParams = o.optionalParams; this.authMethods = o.authMethods; this.tags = o.tags; this.responses = o.responses; + this.callbacks = o.callbacks; this.imports = o.imports; this.examples = o.examples; + this.requestBodyExamples = o.requestBodyExamples; this.externalDocs = o.externalDocs; this.vendorExtensions = o.vendorExtensions; this.nickname = o.nickname; + this.operationIdOriginal = o.operationIdOriginal; this.operationIdLowerCase = o.operationIdLowerCase; this.operationIdCamelCase = o.operationIdCamelCase; + this.operationIdSnakeCase = o.operationIdSnakeCase; // new fields this.hasHttpHeaders = o.getHasHeaderParams() || o.getHasBodyParam() || o.hasAuthMethods; diff --git a/modules/openapi-generator/src/main/resources/typescript-rxjs/apis.mustache b/modules/openapi-generator/src/main/resources/typescript-rxjs/apis.mustache index 70b0ea88721..70614d7f79a 100644 --- a/modules/openapi-generator/src/main/resources/typescript-rxjs/apis.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-rxjs/apis.mustache @@ -171,6 +171,9 @@ export class {{classname}} extends BaseAPI { {{#hasFormParams}} body: formData, {{/hasFormParams}} +{{#isResponseFile}} + responseType: 'blob' +{{/isResponseFile}} }); } diff --git a/modules/openapi-generator/src/main/resources/typescript-rxjs/runtime.mustache b/modules/openapi-generator/src/main/resources/typescript-rxjs/runtime.mustache index 9592c345d1b..429584b64c3 100644 --- a/modules/openapi-generator/src/main/resources/typescript-rxjs/runtime.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-rxjs/runtime.mustache @@ -97,6 +97,7 @@ export class BaseAPI { method: requestOpts.method, headers: requestOpts.headers, body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body), + responseType: requestOpts.responseType || 'json' }; } @@ -149,6 +150,7 @@ export interface RequestOpts { headers?: HttpHeaders; query?: HttpQuery; body?: HttpBody; + responseType?: 'json' | 'blob' | 'arraybuffer' | 'text'; } export const encodeURI = (value: any) => encodeURIComponent(String(value)) diff --git a/samples/client/petstore/typescript-rxjs/builds/default/runtime.ts b/samples/client/petstore/typescript-rxjs/builds/default/runtime.ts index 9b29b9be679..ef017aff8fa 100644 --- a/samples/client/petstore/typescript-rxjs/builds/default/runtime.ts +++ b/samples/client/petstore/typescript-rxjs/builds/default/runtime.ts @@ -108,6 +108,7 @@ export class BaseAPI { method: requestOpts.method, headers: requestOpts.headers, body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body), + responseType: requestOpts.responseType || 'json' }; } @@ -160,6 +161,7 @@ export interface RequestOpts { headers?: HttpHeaders; query?: HttpQuery; body?: HttpBody; + responseType?: 'json' | 'blob' | 'arraybuffer' | 'text'; } export const encodeURI = (value: any) => encodeURIComponent(String(value)) diff --git a/samples/client/petstore/typescript-rxjs/builds/es6-target/runtime.ts b/samples/client/petstore/typescript-rxjs/builds/es6-target/runtime.ts index 9b29b9be679..ef017aff8fa 100644 --- a/samples/client/petstore/typescript-rxjs/builds/es6-target/runtime.ts +++ b/samples/client/petstore/typescript-rxjs/builds/es6-target/runtime.ts @@ -108,6 +108,7 @@ export class BaseAPI { method: requestOpts.method, headers: requestOpts.headers, body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body), + responseType: requestOpts.responseType || 'json' }; } @@ -160,6 +161,7 @@ export interface RequestOpts { headers?: HttpHeaders; query?: HttpQuery; body?: HttpBody; + responseType?: 'json' | 'blob' | 'arraybuffer' | 'text'; } export const encodeURI = (value: any) => encodeURIComponent(String(value)) diff --git a/samples/client/petstore/typescript-rxjs/builds/with-interfaces/runtime.ts b/samples/client/petstore/typescript-rxjs/builds/with-interfaces/runtime.ts index 9b29b9be679..ef017aff8fa 100644 --- a/samples/client/petstore/typescript-rxjs/builds/with-interfaces/runtime.ts +++ b/samples/client/petstore/typescript-rxjs/builds/with-interfaces/runtime.ts @@ -108,6 +108,7 @@ export class BaseAPI { method: requestOpts.method, headers: requestOpts.headers, body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body), + responseType: requestOpts.responseType || 'json' }; } @@ -160,6 +161,7 @@ export interface RequestOpts { headers?: HttpHeaders; query?: HttpQuery; body?: HttpBody; + responseType?: 'json' | 'blob' | 'arraybuffer' | 'text'; } export const encodeURI = (value: any) => encodeURIComponent(String(value)) diff --git a/samples/client/petstore/typescript-rxjs/builds/with-npm-version/runtime.ts b/samples/client/petstore/typescript-rxjs/builds/with-npm-version/runtime.ts index 9b29b9be679..ef017aff8fa 100644 --- a/samples/client/petstore/typescript-rxjs/builds/with-npm-version/runtime.ts +++ b/samples/client/petstore/typescript-rxjs/builds/with-npm-version/runtime.ts @@ -108,6 +108,7 @@ export class BaseAPI { method: requestOpts.method, headers: requestOpts.headers, body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body), + responseType: requestOpts.responseType || 'json' }; } @@ -160,6 +161,7 @@ export interface RequestOpts { headers?: HttpHeaders; query?: HttpQuery; body?: HttpBody; + responseType?: 'json' | 'blob' | 'arraybuffer' | 'text'; } export const encodeURI = (value: any) => encodeURIComponent(String(value))