Skip to content

Commit 8231cbf

Browse files
denyomacjohnny
authored andcommitted
[typescript-rxjs]: support reponseType blob (#3437)
* feat(typescript-rxjs): add optional responseType to RequestOpts * refactor(typescript-rxjs): remove redundant importMapping.clear() in codegen constructor * feat(typescript-rxjs): update this.reservedWords * fix(typescript-rxjs): add missing fields copied to ExtendedCodegenOperation * feat(typescript-rxjs): add support for responseType blob * feat(typescript-rxjs): regenerate samples
1 parent a3cf964 commit 8231cbf

File tree

7 files changed

+61
-6
lines changed

7 files changed

+61
-6
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptRxjsClientCodegen.java

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ public class TypeScriptRxjsClientCodegen extends AbstractTypeScriptClientCodegen
4242
public TypeScriptRxjsClientCodegen() {
4343
super();
4444

45-
// clear import mapping (from default generator) as TS does not use it
46-
// at the moment
47-
importMapping.clear();
48-
4945
outputFolder = "generated-code/typescript-rxjs";
5046
embeddedTemplateDir = templateDir = "typescript-rxjs";
5147

@@ -55,6 +51,9 @@ public TypeScriptRxjsClientCodegen() {
5551
this.modelTemplateFiles.put("models.mustache", ".ts");
5652
this.addExtraReservedWords();
5753

54+
languageSpecificPrimitives.add("Blob");
55+
typeMapping.put("file", "Blob");
56+
5857
this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json"));
5958
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()));
6059
}
@@ -93,6 +92,11 @@ public void processOpts() {
9392
}
9493
}
9594

95+
@Override
96+
public boolean isDataTypeFile(final String dataType) {
97+
return dataType != null && dataType.equals("Blob");
98+
}
99+
96100
@Override
97101
public String getTypeDeclaration(Schema p) {
98102
Schema inner;
@@ -162,6 +166,33 @@ public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
162166
return result;
163167
}
164168

169+
@Override
170+
public void postProcessParameter(CodegenParameter parameter) {
171+
super.postProcessParameter(parameter);
172+
parameter.dataType = applyLocalTypeMapping(parameter.dataType);
173+
}
174+
175+
@Override
176+
public String getSchemaType(Schema p) {
177+
String openAPIType = super.getSchemaType(p);
178+
if (isLanguagePrimitive(openAPIType)) {
179+
return openAPIType;
180+
}
181+
applyLocalTypeMapping(openAPIType);
182+
return openAPIType;
183+
}
184+
185+
private String applyLocalTypeMapping(String type) {
186+
if (typeMapping.containsKey(type)) {
187+
type = typeMapping.get(type);
188+
}
189+
return type;
190+
}
191+
192+
private boolean isLanguagePrimitive(String type) {
193+
return languageSpecificPrimitives.contains(type);
194+
}
195+
165196
private void addNpmPackageGeneration() {
166197
if (additionalProperties.containsKey(NPM_REPOSITORY)) {
167198
this.setNpmRepository(additionalProperties.get(NPM_REPOSITORY).toString());
@@ -290,10 +321,10 @@ private void addExtraReservedWords() {
290321
this.reservedWords.add("ModelPropertyNaming");
291322
this.reservedWords.add("RequestArgs");
292323
this.reservedWords.add("RequestOpts");
324+
this.reservedWords.add("ResponseArgs");
293325
this.reservedWords.add("exists");
294-
this.reservedWords.add("RequestContext");
295-
this.reservedWords.add("ResponseContext");
296326
this.reservedWords.add("Middleware");
327+
this.reservedWords.add("AjaxRequest");
297328
this.reservedWords.add("AjaxResponse");
298329
}
299330

@@ -310,6 +341,7 @@ public ExtendedCodegenOperation(CodegenOperation o) {
310341
this.hasProduces = o.hasProduces;
311342
this.hasParams = o.hasParams;
312343
this.hasOptionalParams = o.hasOptionalParams;
344+
this.hasRequiredParams = o.hasRequiredParams;
313345
this.returnTypeIsPrimitive = o.returnTypeIsPrimitive;
314346
this.returnSimpleType = o.returnSimpleType;
315347
this.subresourceOperation = o.subresourceOperation;
@@ -318,13 +350,16 @@ public ExtendedCodegenOperation(CodegenOperation o) {
318350
this.isMultipart = o.isMultipart;
319351
this.hasMore = o.hasMore;
320352
this.isResponseBinary = o.isResponseBinary;
353+
this.isResponseFile = o.isResponseFile;
321354
this.hasReference = o.hasReference;
322355
this.isRestfulIndex = o.isRestfulIndex;
323356
this.isRestfulShow = o.isRestfulShow;
324357
this.isRestfulCreate = o.isRestfulCreate;
325358
this.isRestfulUpdate = o.isRestfulUpdate;
326359
this.isRestfulDestroy = o.isRestfulDestroy;
327360
this.isRestful = o.isRestful;
361+
this.isDeprecated = o.isDeprecated;
362+
this.isCallbackRequest = o.isCallbackRequest;
328363
this.path = o.path;
329364
this.operationId = o.operationId;
330365
this.returnType = o.returnType;
@@ -339,25 +374,32 @@ public ExtendedCodegenOperation(CodegenOperation o) {
339374
this.discriminator = o.discriminator;
340375
this.consumes = o.consumes;
341376
this.produces = o.produces;
377+
this.prioritizedContentTypes = o.prioritizedContentTypes;
378+
this.servers = o.servers;
342379
this.bodyParam = o.bodyParam;
343380
this.allParams = o.allParams;
344381
this.bodyParams = o.bodyParams;
345382
this.pathParams = o.pathParams;
346383
this.queryParams = o.queryParams;
347384
this.headerParams = o.headerParams;
348385
this.formParams = o.formParams;
386+
this.cookieParams = o.cookieParams;
349387
this.requiredParams = o.requiredParams;
350388
this.optionalParams = o.optionalParams;
351389
this.authMethods = o.authMethods;
352390
this.tags = o.tags;
353391
this.responses = o.responses;
392+
this.callbacks = o.callbacks;
354393
this.imports = o.imports;
355394
this.examples = o.examples;
395+
this.requestBodyExamples = o.requestBodyExamples;
356396
this.externalDocs = o.externalDocs;
357397
this.vendorExtensions = o.vendorExtensions;
358398
this.nickname = o.nickname;
399+
this.operationIdOriginal = o.operationIdOriginal;
359400
this.operationIdLowerCase = o.operationIdLowerCase;
360401
this.operationIdCamelCase = o.operationIdCamelCase;
402+
this.operationIdSnakeCase = o.operationIdSnakeCase;
361403

362404
// new fields
363405
this.hasHttpHeaders = o.getHasHeaderParams() || o.getHasBodyParam() || o.hasAuthMethods;

modules/openapi-generator/src/main/resources/typescript-rxjs/apis.mustache

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ export class {{classname}} extends BaseAPI {
171171
{{#hasFormParams}}
172172
body: formData,
173173
{{/hasFormParams}}
174+
{{#isResponseFile}}
175+
responseType: 'blob'
176+
{{/isResponseFile}}
174177
});
175178
}
176179

modules/openapi-generator/src/main/resources/typescript-rxjs/runtime.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export class BaseAPI {
9797
method: requestOpts.method,
9898
headers: requestOpts.headers,
9999
body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body),
100+
responseType: requestOpts.responseType || 'json'
100101
};
101102
}
102103

@@ -149,6 +150,7 @@ export interface RequestOpts {
149150
headers?: HttpHeaders;
150151
query?: HttpQuery;
151152
body?: HttpBody;
153+
responseType?: 'json' | 'blob' | 'arraybuffer' | 'text';
152154
}
153155

154156
export const encodeURI = (value: any) => encodeURIComponent(String(value))

samples/client/petstore/typescript-rxjs/builds/default/runtime.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export class BaseAPI {
108108
method: requestOpts.method,
109109
headers: requestOpts.headers,
110110
body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body),
111+
responseType: requestOpts.responseType || 'json'
111112
};
112113
}
113114

@@ -160,6 +161,7 @@ export interface RequestOpts {
160161
headers?: HttpHeaders;
161162
query?: HttpQuery;
162163
body?: HttpBody;
164+
responseType?: 'json' | 'blob' | 'arraybuffer' | 'text';
163165
}
164166

165167
export const encodeURI = (value: any) => encodeURIComponent(String(value))

samples/client/petstore/typescript-rxjs/builds/es6-target/runtime.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export class BaseAPI {
108108
method: requestOpts.method,
109109
headers: requestOpts.headers,
110110
body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body),
111+
responseType: requestOpts.responseType || 'json'
111112
};
112113
}
113114

@@ -160,6 +161,7 @@ export interface RequestOpts {
160161
headers?: HttpHeaders;
161162
query?: HttpQuery;
162163
body?: HttpBody;
164+
responseType?: 'json' | 'blob' | 'arraybuffer' | 'text';
163165
}
164166

165167
export const encodeURI = (value: any) => encodeURIComponent(String(value))

samples/client/petstore/typescript-rxjs/builds/with-interfaces/runtime.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export class BaseAPI {
108108
method: requestOpts.method,
109109
headers: requestOpts.headers,
110110
body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body),
111+
responseType: requestOpts.responseType || 'json'
111112
};
112113
}
113114

@@ -160,6 +161,7 @@ export interface RequestOpts {
160161
headers?: HttpHeaders;
161162
query?: HttpQuery;
162163
body?: HttpBody;
164+
responseType?: 'json' | 'blob' | 'arraybuffer' | 'text';
163165
}
164166

165167
export const encodeURI = (value: any) => encodeURIComponent(String(value))

samples/client/petstore/typescript-rxjs/builds/with-npm-version/runtime.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export class BaseAPI {
108108
method: requestOpts.method,
109109
headers: requestOpts.headers,
110110
body: requestOpts.body instanceof FormData ? requestOpts.body : JSON.stringify(requestOpts.body),
111+
responseType: requestOpts.responseType || 'json'
111112
};
112113
}
113114

@@ -160,6 +161,7 @@ export interface RequestOpts {
160161
headers?: HttpHeaders;
161162
query?: HttpQuery;
162163
body?: HttpBody;
164+
responseType?: 'json' | 'blob' | 'arraybuffer' | 'text';
163165
}
164166

165167
export const encodeURI = (value: any) => encodeURIComponent(String(value))

0 commit comments

Comments
 (0)