Skip to content

Fix generated SDK query parameter names#754

Merged
ralyodio merged 1 commit into
profullstack:masterfrom
JoesnageL:codex/openapi-query-param-original-name
Jun 18, 2026
Merged

Fix generated SDK query parameter names#754
ralyodio merged 1 commit into
profullstack:masterfrom
JoesnageL:codex/openapi-query-param-original-name

Conversation

@JoesnageL

Copy link
Copy Markdown
Contributor

Summary

  • Preserve original OpenAPI query parameter names when generating TypeScript SDK request options.
  • Keep sanitized TypeScript option names for caller ergonomics, but map them back to the wire-level query keys before calling request.
  • Add regression coverage for a hyphenated query parameter (page-size).

Verification

  • pnpm exec vitest run packages/openapi/src/gen-sdk-ts/index.test.ts
  • pnpm --filter @profullstack/sh1pt-openapi typecheck

@greptile-apps

greptile-apps Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This 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 _page_size identifier, while the internal request() call now maps each param back to its OpenAPI name (e.g. "page-size").

  • index.ts: Replaces the simple query: opts.query passthrough with an explicit per-parameter mapping — { "page-size": opts.query?._page_size } — so the HTTP query string always uses the spec-defined key.
  • index.test.ts: Adds a page-size parameter to the listPets fixture and asserts both the sanitized TypeScript signature and the correct wire-key in the generated output.

Confidence Score: 4/5

Safe 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

Filename Overview
packages/openapi/src/gen-sdk-ts/index.ts Core fix: replaces query: opts.query passthrough with an explicit name-mapping object so wire-level keys use the original OpenAPI name while TypeScript callers use the sanitized identifier.
packages/openapi/src/gen-sdk-ts/index.test.ts Adds a hyphenated query parameter (page-size) to the fixture and asserts both the sanitized TypeScript signature and the correct wire-key mapping; only covers the single-param hyphenated case.

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]
Loading
%%{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]
Loading

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' } }],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

Suggested change
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!

@github-actions

Copy link
Copy Markdown

🤖 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: git fetch upstream master && git rebase upstream/master.

@ralyodio ralyodio merged commit 68818d4 into profullstack:master Jun 18, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants