| 48 | }; |
| 49 | |
| 50 | export const getQueryString = (params: Record<string, any>): string => { |
| 51 | const qs: string[] = []; |
| 52 | |
| 53 | const append = (key: string, value: any) => { |
| 54 | qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); |
| 55 | }; |
| 56 | |
| 57 | const process = (key: string, value: any) => { |
| 58 | if (isDefined(value)) { |
| 59 | if (Array.isArray(value)) { |
| 60 | value.forEach(v => { |
| 61 | process(key, v); |
| 62 | }); |
| 63 | } else if (typeof value === 'object') { |
| 64 | Object.entries(value).forEach(([k, v]) => { |
| 65 | process(`${key}[${k}]`, v); |
| 66 | }); |
| 67 | } else { |
| 68 | append(key, value); |
| 69 | } |
| 70 | } |
| 71 | }; |
| 72 | |
| 73 | Object.entries(params).forEach(([key, value]) => { |
| 74 | process(key, value); |
| 75 | }); |
| 76 | |
| 77 | if (qs.length > 0) { |
| 78 | return `?${qs.join('&')}`; |
| 79 | } |
| 80 | |
| 81 | return ''; |
| 82 | }; |
| 83 | |
| 84 | const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => { |
| 85 | const encoder = config.ENCODE_PATH || encodeURI; |