Skip to content

Commit bea930a

Browse files
committed
Fix incorrect handling of query parameters with values 0 or empty strings in CodeGeneration output
1 parent 4f3bc9f commit bea930a

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Diff for: packages/rtk-query-codegen-openapi/src/generate.ts

+5-1
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]),

Diff for: packages/rtk-query-codegen-openapi/test/generateEndpoints.test.ts

+1-1
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)