Skip to content

Commit a3860f1

Browse files
authored
Fix incorrect handling of query parameters with values 0 or empty strings in CodeGeneration output (#4782)
1 parent c609bbe commit a3860f1

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

packages/rtk-query-codegen-openapi/src/generate.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,11 @@ export async function generateApi(
448448
const encodedValue =
449449
encodeQueryParams && param.param?.in === 'query'
450450
? factory.createConditionalExpression(
451-
value,
451+
factory.createBinaryExpression(
452+
value,
453+
ts.SyntaxKind.ExclamationEqualsToken,
454+
factory.createNull()
455+
),
452456
undefined,
453457
factory.createCallExpression(factory.createIdentifier('encodeURIComponent'), undefined, [
454458
factory.createCallExpression(factory.createIdentifier('String'), undefined, [value]),

packages/rtk-query-codegen-openapi/test/generateEndpoints.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ describe('option encodeQueryParams', () => {
242242
});
243243

244244
expect(api).toMatch(
245-
/params:\s*{\s*\n\s*status:\s*queryArg\.status\s*\?\s*encodeURIComponent\(\s*String\(queryArg\.status\)\s*\)\s*:\s*undefined\s*,?\s*\n\s*}/s
245+
/params:\s*{\s*\n\s*status:\s*queryArg\.status\s*!=\s*null\s*\?\s*encodeURIComponent\(\s*String\(queryArg\.status\)\s*\)\s*:\s*undefined\s*,?\s*\n\s*}/s
246246
);
247247
});
248248

0 commit comments

Comments
 (0)