Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -55,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 @@ -93,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 @@ -162,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 Expand Up @@ -290,10 +321,10 @@ private void addExtraReservedWords() {
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");
}

Expand All @@ -310,6 +341,7 @@ public ExtendedCodegenOperation(CodegenOperation o) {
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;
Expand All @@ -318,13 +350,16 @@ public ExtendedCodegenOperation(CodegenOperation o) {
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;
this.isRestfulCreate = o.isRestfulCreate;
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;
Expand All @@ -339,25 +374,32 @@ public ExtendedCodegenOperation(CodegenOperation o) {
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;
this.pathParams = o.pathParams;
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;
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 @@ -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'
};
}

Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};
}

Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};
}

Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};
}

Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};
}

Expand Down Expand Up @@ -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))
Expand Down