Fix generated SDK query parameter names#754
Conversation
Greptile SummaryThis PR fixes the TypeScript SDK generator so that hyphenated (or otherwise non-identifier) OpenAPI query parameter names are sent using their original wire-level keys instead of the sanitized TypeScript names. The caller-facing interface keeps the ergonomic
Confidence Score: 4/5Safe to merge; the change is small and targeted, and the existing request() method already filters out undefined values so the always-present mapping object introduces no behavioural regression for optional params. The fix is correct and well-scoped. The only gap is that the new test only exercises the single-hyphenated-param case; a multi-param operation mixing a hyphenated name with a plain identifier would confirm the mapping loop handles both branches together. packages/openapi/src/gen-sdk-ts/index.test.ts — the test fixture covers only one query param; extending it to include a plain-identifier param alongside page-size would give fuller coverage. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[renderMethod called with Operation] --> B{queryParams.length > 0?}
B -- No --> C[callParts stays empty]
B -- Yes --> D["For each param p in queryParams"]
D --> E["key = JSON.stringify(p.name)"]
D --> F["accessor = safe(p.name)"]
E & F --> G["emit: key: opts.query?.accessor"]
G --> H["callParts.push query mapping object"]
H --> I["request() receives explicit query map"]
I --> J["request() iterates entries, skips undefined/null"]
J --> K["url.searchParams uses original OpenAPI key"]
C --> L[No query object in request call]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A[renderMethod called with Operation] --> B{queryParams.length > 0?}
B -- No --> C[callParts stays empty]
B -- Yes --> D["For each param p in queryParams"]
D --> E["key = JSON.stringify(p.name)"]
D --> F["accessor = safe(p.name)"]
E & F --> G["emit: key: opts.query?.accessor"]
G --> H["callParts.push query mapping object"]
H --> I["request() receives explicit query map"]
I --> J["request() iterates entries, skips undefined/null"]
J --> K["url.searchParams uses original OpenAPI key"]
C --> L[No query object in request call]
Reviews (1): Last reviewed commit: "Fix generated SDK query parameter names" | Re-trigger Greptile |
| get: { | ||
| operationId: 'listPets', | ||
| tags: ['pets'], | ||
| parameters: [{ name: 'page-size', in: 'query', schema: { type: 'integer' } }], |
There was a problem hiding this comment.
The test only exercises one query parameter at a time. It verifies that
page-size maps to _page_size, but it doesn't confirm that a valid-identifier param coexisting in the same operation still gets the right wire key. Adding a second param (e.g. limit) to the fixture and asserting "limit": opts.query?.limit in the generated output would give complete confidence that the mapping loop works across both the transformed-name and unchanged-name branches.
| parameters: [{ name: 'page-size', in: 'query', schema: { type: 'integer' } }], | |
| parameters: [ | |
| { name: 'page-size', in: 'query', schema: { type: 'integer' } }, | |
| { name: 'limit', in: 'query', schema: { type: 'integer' } }, | |
| ], |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
Summary
request.page-size).Verification
pnpm exec vitest run packages/openapi/src/gen-sdk-ts/index.test.tspnpm --filter @profullstack/sh1pt-openapi typecheck