fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #100 from nicolas-chaulet/fix/query-string-falsy

fix(request): discard only null or undefined in query string

authored by

Lubos and committed by
GitHub
25e240a3 f6da1150

+65 -129
+2 -19
package-lock.json
··· 37 37 "@types/cross-spawn": "6.0.6", 38 38 "@types/express": "4.17.21", 39 39 "@types/node": "20.11.30", 40 - "@types/qs": "6.9.13", 41 40 "@typescript-eslint/eslint-plugin": "7.3.1", 42 41 "@typescript-eslint/parser": "7.3.1", 43 42 "@vitest/coverage-v8": "1.4.0", ··· 53 52 "npm-run-all2": "6.1.2", 54 53 "prettier": "3.2.5", 55 54 "puppeteer": "22.5.0", 56 - "qs": "6.12.0", 57 55 "rimraf": "5.0.5", 58 56 "rollup": "4.13.0", 59 57 "rollup-plugin-dts": "6.1.0", ··· 61 59 "ts-node": "10.9.2", 62 60 "tslib": "2.6.2", 63 61 "typescript": "5.4.2", 64 - "vitest": "1.4.0", 65 - "zone.js": "0.14.4" 62 + "vitest": "1.4.0" 66 63 }, 67 64 "engines": { 68 65 "node": "^18.0.0 || >=20.0.0" ··· 11420 11417 "node": ">=18" 11421 11418 } 11422 11419 }, 11423 - "node_modules/qs": { 11424 - "version": "6.12.0", 11425 - "resolved": "https://registry.npmjs.org/qs/-/qs-6.12.0.tgz", 11426 - "integrity": "sha512-trVZiI6RMOkO476zLGaBIzszOdFPnCCXHPG9kn0yuS1uz6xdVxPfZdB3vUig9pxPFDM9BRAgz/YUIVQ1/vuiUg==", 11427 - "dev": true, 11428 - "dependencies": { 11429 - "side-channel": "^1.0.6" 11430 - }, 11431 - "engines": { 11432 - "node": ">=0.6" 11433 - }, 11434 - "funding": { 11435 - "url": "https://github.com/sponsors/ljharb" 11436 - } 11437 - }, 11438 11420 "node_modules/queue-microtask": { 11439 11421 "version": "1.2.3", 11440 11422 "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", ··· 14685 14667 "resolved": "https://registry.npmjs.org/zone.js/-/zone.js-0.14.4.tgz", 14686 14668 "integrity": "sha512-NtTUvIlNELez7Q1DzKVIFZBzNb646boQMgpATo9z3Ftuu/gWvzxCW7jdjcUDoRGxRikrhVHB/zLXh1hxeJawvw==", 14687 14669 "dev": true, 14670 + "peer": true, 14688 14671 "dependencies": { 14689 14672 "tslib": "^2.3.0" 14690 14673 }
+3 -6
package.json
··· 54 54 "lint": "eslint .", 55 55 "prepublishOnly": "npm run build", 56 56 "test": "vitest run --config vitest.config.unit.ts", 57 - "test:update": "vitest run --config vitest.config.unit.ts --update", 58 57 "test:coverage": "vitest run --config vitest.config.unit.ts --coverage", 59 - "test:watch": "vitest --config vitest.config.unit.ts --watch", 60 58 "test:e2e": "vitest run --config vitest.config.e2e.ts", 61 59 "test:sample": "node test/sample.cjs", 60 + "test:update": "vitest run --config vitest.config.unit.ts --update", 61 + "test:watch": "vitest --config vitest.config.unit.ts --watch", 62 62 "typecheck": "tsc --noEmit" 63 63 }, 64 64 "engines": { ··· 90 90 "@types/cross-spawn": "6.0.6", 91 91 "@types/express": "4.17.21", 92 92 "@types/node": "20.11.30", 93 - "@types/qs": "6.9.13", 94 93 "@typescript-eslint/eslint-plugin": "7.3.1", 95 94 "@typescript-eslint/parser": "7.3.1", 96 95 "@vitest/coverage-v8": "1.4.0", ··· 106 105 "npm-run-all2": "6.1.2", 107 106 "prettier": "3.2.5", 108 107 "puppeteer": "22.5.0", 109 - "qs": "6.12.0", 110 108 "rimraf": "5.0.5", 111 109 "rollup": "4.13.0", 112 110 "rollup-plugin-dts": "6.1.0", ··· 114 112 "ts-node": "10.9.2", 115 113 "tslib": "2.6.2", 116 114 "typescript": "5.4.2", 117 - "vitest": "1.4.0", 118 - "zone.js": "0.14.4" 115 + "vitest": "1.4.0" 119 116 }, 120 117 "packageManager": "npm@10.5.0+sha256.17ca6e08e7633b624e8f870db81a78f46afe119de62bcaf0a7407574139198fc" 121 118 }
+13 -21
src/templates/core/functions/getQueryString.hbs
··· 5 5 qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`); 6 6 }; 7 7 8 - const process = (key: string, value: unknown) => { 9 - if (value) { 10 - if (Array.isArray(value)) { 11 - value.forEach(v => { 12 - process(key, v); 13 - }); 14 - } else if (typeof value === 'object') { 15 - Object.entries(value).forEach(([k, v]) => { 16 - process(`${key}[${k}]`, v); 17 - }); 18 - } else { 19 - append(key, value); 20 - } 8 + const encodePair = (key: string, value: unknown) => { 9 + if (value === undefined || value === null) { 10 + return; 21 11 } 22 - }; 23 12 24 - Object.entries(params).forEach(([key, value]) => { 25 - process(key, value); 26 - }); 13 + if (Array.isArray(value)) { 14 + value.forEach(v => encodePair(key, v)); 15 + } else if (typeof value === 'object') { 16 + Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v)); 17 + } else { 18 + append(key, value); 19 + } 20 + }; 27 21 28 - if (qs.length > 0) { 29 - return `?${qs.join('&')}`; 30 - } 22 + Object.entries(params).forEach(([key, value]) => encodePair(key, value)); 31 23 32 - return ''; 24 + return qs.length ? `?${qs.join('&')}` : ''; 33 25 };
+2 -5
src/templates/core/functions/getUrl.hbs
··· 10 10 return substring; 11 11 }); 12 12 13 - const url = `${config.BASE}${path}`; 14 - if (options.query) { 15 - return `${url}${getQueryString(options.query)}`; 16 - } 17 - return url; 13 + const url = config.BASE + path; 14 + return options.query ? url + getQueryString(options.query) : url; 18 15 };
+45 -78
test/__snapshots__/index.spec.ts.snap
··· 283 283 qs.push(\`\${encodeURIComponent(key)}=\${encodeURIComponent(String(value))}\`); 284 284 }; 285 285 286 - const process = (key: string, value: unknown) => { 287 - if (value) { 288 - if (Array.isArray(value)) { 289 - value.forEach(v => { 290 - process(key, v); 291 - }); 292 - } else if (typeof value === 'object') { 293 - Object.entries(value).forEach(([k, v]) => { 294 - process(\`\${key}[\${k}]\`, v); 295 - }); 296 - } else { 297 - append(key, value); 298 - } 286 + const encodePair = (key: string, value: unknown) => { 287 + if (value === undefined || value === null) { 288 + return; 289 + } 290 + 291 + if (Array.isArray(value)) { 292 + value.forEach(v => encodePair(key, v)); 293 + } else if (typeof value === 'object') { 294 + Object.entries(value).forEach(([k, v]) => encodePair(\`\${key}[\${k}]\`, v)); 295 + } else { 296 + append(key, value); 299 297 } 300 298 }; 301 299 302 - Object.entries(params).forEach(([key, value]) => { 303 - process(key, value); 304 - }); 305 - 306 - if (qs.length > 0) { 307 - return \`?\${qs.join('&')}\`; 308 - } 300 + Object.entries(params).forEach(([key, value]) => encodePair(key, value)); 309 301 310 - return ''; 302 + return qs.length ? \`?\${qs.join('&')}\` : ''; 311 303 }; 312 304 313 305 const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => { ··· 322 314 return substring; 323 315 }); 324 316 325 - const url = \`\${config.BASE}\${path}\`; 326 - if (options.query) { 327 - return \`\${url}\${getQueryString(options.query)}\`; 328 - } 329 - return url; 317 + const url = config.BASE + path; 318 + return options.query ? url + getQueryString(options.query) : url; 330 319 }; 331 320 332 321 export const getFormData = (options: ApiRequestOptions): FormData | undefined => { ··· 3261 3250 qs.push(\`\${encodeURIComponent(key)}=\${encodeURIComponent(String(value))}\`); 3262 3251 }; 3263 3252 3264 - const process = (key: string, value: unknown) => { 3265 - if (value) { 3266 - if (Array.isArray(value)) { 3267 - value.forEach(v => { 3268 - process(key, v); 3269 - }); 3270 - } else if (typeof value === 'object') { 3271 - Object.entries(value).forEach(([k, v]) => { 3272 - process(\`\${key}[\${k}]\`, v); 3273 - }); 3274 - } else { 3275 - append(key, value); 3276 - } 3253 + const encodePair = (key: string, value: unknown) => { 3254 + if (value === undefined || value === null) { 3255 + return; 3256 + } 3257 + 3258 + if (Array.isArray(value)) { 3259 + value.forEach(v => encodePair(key, v)); 3260 + } else if (typeof value === 'object') { 3261 + Object.entries(value).forEach(([k, v]) => encodePair(\`\${key}[\${k}]\`, v)); 3262 + } else { 3263 + append(key, value); 3277 3264 } 3278 3265 }; 3279 3266 3280 - Object.entries(params).forEach(([key, value]) => { 3281 - process(key, value); 3282 - }); 3283 - 3284 - if (qs.length > 0) { 3285 - return \`?\${qs.join('&')}\`; 3286 - } 3267 + Object.entries(params).forEach(([key, value]) => encodePair(key, value)); 3287 3268 3288 - return ''; 3269 + return qs.length ? \`?\${qs.join('&')}\` : ''; 3289 3270 }; 3290 3271 3291 3272 const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => { ··· 3300 3281 return substring; 3301 3282 }); 3302 3283 3303 - const url = \`\${config.BASE}\${path}\`; 3304 - if (options.query) { 3305 - return \`\${url}\${getQueryString(options.query)}\`; 3306 - } 3307 - return url; 3284 + const url = config.BASE + path; 3285 + return options.query ? url + getQueryString(options.query) : url; 3308 3286 }; 3309 3287 3310 3288 export const getFormData = (options: ApiRequestOptions): FormData | undefined => { ··· 8352 8330 qs.push(\`\${encodeURIComponent(key)}=\${encodeURIComponent(String(value))}\`); 8353 8331 }; 8354 8332 8355 - const process = (key: string, value: unknown) => { 8356 - if (value) { 8357 - if (Array.isArray(value)) { 8358 - value.forEach(v => { 8359 - process(key, v); 8360 - }); 8361 - } else if (typeof value === 'object') { 8362 - Object.entries(value).forEach(([k, v]) => { 8363 - process(\`\${key}[\${k}]\`, v); 8364 - }); 8365 - } else { 8366 - append(key, value); 8367 - } 8333 + const encodePair = (key: string, value: unknown) => { 8334 + if (value === undefined || value === null) { 8335 + return; 8336 + } 8337 + 8338 + if (Array.isArray(value)) { 8339 + value.forEach(v => encodePair(key, v)); 8340 + } else if (typeof value === 'object') { 8341 + Object.entries(value).forEach(([k, v]) => encodePair(\`\${key}[\${k}]\`, v)); 8342 + } else { 8343 + append(key, value); 8368 8344 } 8369 8345 }; 8370 8346 8371 - Object.entries(params).forEach(([key, value]) => { 8372 - process(key, value); 8373 - }); 8374 - 8375 - if (qs.length > 0) { 8376 - return \`?\${qs.join('&')}\`; 8377 - } 8347 + Object.entries(params).forEach(([key, value]) => encodePair(key, value)); 8378 8348 8379 - return ''; 8349 + return qs.length ? \`?\${qs.join('&')}\` : ''; 8380 8350 }; 8381 8351 8382 8352 const getUrl = (config: OpenAPIConfig, options: ApiRequestOptions): string => { ··· 8391 8361 return substring; 8392 8362 }); 8393 8363 8394 - const url = \`\${config.BASE}\${path}\`; 8395 - if (options.query) { 8396 - return \`\${url}\${getQueryString(options.query)}\`; 8397 - } 8398 - return url; 8364 + const url = config.BASE + path; 8365 + return options.query ? url + getQueryString(options.query) : url; 8399 8366 }; 8400 8367 8401 8368 export const getFormData = (options: ApiRequestOptions): FormData | undefined => {