Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed object in qs to be processed correctly #1872

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions src/templates/core/OpenAPI.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type OpenAPIConfig = {
PASSWORD?: string | Resolver<string> | undefined;
HEADERS?: Headers | Resolver<Headers> | undefined;
ENCODE_PATH?: ((path: string) => string) | undefined;
RESPONSE_TYPE: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream';
};

export const OpenAPI: OpenAPIConfig = {
Expand All @@ -27,4 +28,5 @@ export const OpenAPI: OpenAPIConfig = {
PASSWORD: undefined,
HEADERS: undefined,
ENCODE_PATH: undefined,
RESPONSE_TYPE: 'json',
};
2 changes: 1 addition & 1 deletion src/templates/core/angular/request.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const request = <T>(config: OpenAPIConfig, http: HttpClient, options: Api

return getHeaders(config, options).pipe(
switchMap(headers => {
return sendRequest<T>(config, options, http, url, formData, body, headers);
return sendRequest<T>(config, options, http, url, formData, config['RESPONSE_TYPE'], body, headers);
}),
map(response => {
const responseBody = getResponseBody(response);
Expand Down
1 change: 1 addition & 0 deletions src/templates/core/angular/sendRequest.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const sendRequest = <T>(
url: string,
body: any,
formData: FormData | undefined,
responseType: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream',
headers: HttpHeaders
): Observable<HttpResponse<T>> => {
return http.request<T>(options.method, url, {
Expand Down
2 changes: 1 addition & 1 deletion src/templates/core/axios/request.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions, ax
const headers = await getHeaders(config, options, formData);

if (!onCancel.isCancelled) {
const response = await sendRequest<T>(config, options, url, body, formData, headers, onCancel, axiosClient);
const response = await sendRequest<T>(config, options, url, body, formData, config['RESPONSE_TYPE'], headers, onCancel, axiosClient);
const responseBody = getResponseBody(response);
const responseHeader = getResponseHeader(response, options.responseHeader);

Expand Down
2 changes: 2 additions & 0 deletions src/templates/core/axios/sendRequest.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const sendRequest = async <T>(
url: string,
body: any,
formData: FormData | undefined,
responseType: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream',
headers: Record<string, string>,
onCancel: OnCancel,
axiosClient: AxiosInstance
Expand All @@ -16,6 +17,7 @@ export const sendRequest = async <T>(
data: body ?? formData,
method: options.method,
withCredentials: config.WITH_CREDENTIALS,
responseType,
cancelToken: source.token,
};

Expand Down
2 changes: 1 addition & 1 deletion src/templates/core/fetch/request.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): C
const headers = await getHeaders(config, options);

if (!onCancel.isCancelled) {
const response = await sendRequest(config, options, url, body, formData, headers, onCancel);
const response = await sendRequest(config, options, url, body, formData, config['RESPONSE_TYPE'], headers, onCancel);
const responseBody = await getResponseBody(response);
const responseHeader = getResponseHeader(response, options.responseHeader);

Expand Down
3 changes: 2 additions & 1 deletion src/templates/core/fetch/sendRequest.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const sendRequest = async (
url: string,
body: any,
formData: FormData | undefined,
responseType: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream',
headers: Headers,
onCancel: OnCancel
): Promise<Response> => {
Expand All @@ -13,7 +14,7 @@ export const sendRequest = async (
headers,
body: body ?? formData,
method: options.method,
signal: controller.signal,
signal: controller.signal
};

if (config.WITH_CREDENTIALS) {
Expand Down
2 changes: 1 addition & 1 deletion src/templates/core/functions/getQueryString.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const getQueryString = (params: Record<string, any>): string => {
});
} else if (typeof value === 'object') {
Object.entries(value).forEach(([k, v]) => {
process(`${key}[${k}]`, v);
process(`${k}`, v);
});
} else {
append(key, value);
Expand Down
2 changes: 1 addition & 1 deletion src/templates/core/node/request.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): C
const headers = await getHeaders(config, options);

if (!onCancel.isCancelled) {
const response = await sendRequest(options, url, body, formData, headers, onCancel);
const response = await sendRequest(options, url, body, formData, config['RESPONSE_TYPE'], headers, onCancel);
const responseBody = await getResponseBody(response);
const responseHeader = getResponseHeader(response, options.responseHeader);

Expand Down
1 change: 1 addition & 0 deletions src/templates/core/node/sendRequest.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const sendRequest = async (
url: string,
body: any,
formData: FormData | undefined,
responseType: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream',
headers: Headers,
onCancel: OnCancel
): Promise<Response> => {
Expand Down
2 changes: 1 addition & 1 deletion src/templates/core/xhr/request.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): C
const headers = await getHeaders(config, options);

if (!onCancel.isCancelled) {
const response = await sendRequest(config, options, url, body, formData, headers, onCancel);
const response = await sendRequest(config, options, url, body, formData, config['RESPONSE_TYPE'], headers, onCancel);
const responseBody = getResponseBody(response);
const responseHeader = getResponseHeader(response, options.responseHeader);

Expand Down
3 changes: 3 additions & 0 deletions src/templates/core/xhr/sendRequest.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const sendRequest = async (
url: string,
body: any,
formData: FormData | undefined,
responseType: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream',
headers: Headers,
onCancel: OnCancel
): Promise<XMLHttpRequest> => {
Expand All @@ -15,6 +16,8 @@ export const sendRequest = async (
xhr.setRequestHeader(key, value);
});

xhr.responseType = responseType;

return new Promise<XMLHttpRequest>((resolve, reject) => {
xhr.onload = () => resolve(xhr);
xhr.onabort = () => reject(new Error('Request aborted'));
Expand Down