Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(typescript-rxjs): add support for responseType blob
  • Loading branch information
denyo committed Jul 25, 2019
commit a43acfeea0ae4c5f492a105e9be70a8239626f86
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public TypeScriptRxjsClientCodegen() {
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()));
}
Expand Down Expand Up @@ -89,6 +92,11 @@ public void processOpts() {
}
}

@Override
public boolean isDataTypeFile(final String dataType) {
return dataType != null && dataType.equals("Blob");
}

@Override
public String getTypeDeclaration(Schema p) {
Schema inner;
Expand Down Expand Up @@ -158,6 +166,33 @@ public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ export class {{classname}} extends BaseAPI {
{{#hasFormParams}}
body: formData,
{{/hasFormParams}}
{{#isResponseFile}}
responseType: 'blob'
{{/isResponseFile}}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export interface RequestOpts {
headers?: HttpHeaders;
query?: HttpQuery;
body?: HttpBody;
responseType?: string;
responseType?: 'json' | 'blob' | 'arraybuffer' | 'text';
}

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