Skip to content

Commit

Permalink
Fix incorrect handling of query parameters with values 0 or empty str…
Browse files Browse the repository at this point in the history
…ings in CodeGeneration output
  • Loading branch information
yukiyokotani committed Dec 19, 2024
1 parent 4f3bc9f commit bea930a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/rtk-query-codegen-openapi/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,11 @@ export async function generateApi(
const encodedValue =
encodeQueryParams && param.param?.in === 'query'
? factory.createConditionalExpression(
value,
factory.createBinaryExpression(
value,
ts.SyntaxKind.ExclamationEqualsToken,
factory.createNull()
),
undefined,
factory.createCallExpression(factory.createIdentifier('encodeURIComponent'), undefined, [
factory.createCallExpression(factory.createIdentifier('String'), undefined, [value]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ describe('option encodeQueryParams', () => {
});

expect(api).toMatch(
/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
/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
);
});

Expand Down

0 comments on commit bea930a

Please sign in to comment.