Skip to content

Fix: query params object incorrectly required when all fields are optional (extractRequestParams)#1756

Open
Upgrade220 wants to merge 2 commits into
acacode:mainfrom
Upgrade220:fix/optional-query-params
Open

Fix: query params object incorrectly required when all fields are optional (extractRequestParams)#1756
Upgrade220 wants to merge 2 commits into
acacode:mainfrom
Upgrade220:fix/optional-query-params

Conversation

@Upgrade220
Copy link
Copy Markdown

@Upgrade220 Upgrade220 commented May 19, 2026

Closes #1755

Problem

When using extractRequestParams: true, if a route has only optional query parameters and no path parameters, the generated method signature forces callers to pass an explicit argument even though every field inside it is optional:

// generated — wrong
getItems(query: GetItemsParams, params?: RequestParams)

// caller is forced to write
api.items.getItems({})
// instead of simply
api.items.getItems()

The root cause is that procedure-call.ejs hardcodes optional: false for the combined params argument. The allFieldsAreOptional flag is already computed correctly inside requestParamsSchema.typeData by the existing ObjectSchemaParser, but it was never surfaced to the template.

Solution

I propose a minimal source-level fix: expose requestParamsSchema?.typeData?.allFieldsAreOptional as requestParamsOptional on the route's request info object in parseRouteInfo() (schema-routes.ts). The template then reads this flag instead of hardcoding false, and adds = {} as the default value when the params object is optional.

No schema construction changes are needed — the data was already correct, just unexposed.

// generated — correct
getItems(query: GetItemsParams = {}, params?: RequestParams)

Changes

  • src/schema-routes/schema-routes.ts — add requestParamsOptional to the route request info
  • types/index.ts — add requestParamsOptional?: boolean to ParsedRouteRequest
  • templates/default/procedure-call.ejs — read route.request.requestParamsOptional instead of hardcoded false
  • templates/modular/procedure-call.ejs — same change
  • tests/spec/extractRequestParams/schema.json — add a route with only optional query params to cover this case
  • Snapshot updates across extended tests where routes with all-optional query params now correctly get = {}

Summary by cubic

Fixes extractRequestParams so routes with only optional query params no longer force callers to pass {}. Generated methods now make the combined query object optional and default it to {}.

  • Bug Fixes
    • Mark the combined query params object as optional and add = {} when all its fields are optional and there are no path params.
    • Surface requestParamsSchema.typeData.allFieldsAreOptional as requestParamsOptional in schema-routes.ts, and add requestParamsOptional to ParsedRouteRequest in types/index.ts.
    • Update templates/*/procedure-call.ejs to respect requestParamsOptional and set defaultValue: '{}' when applicable.
    • Add a covering test route and update snapshots; add a patch changeset.

Written for commit 209cb7a. Summary will update on new commits. Review in cubic

…ctRequestParams

Surfaces requestParamsSchema.typeData.allFieldsAreOptional from
schema-routes.ts as requestParamsOptional on the route request info,
so procedure-call.ejs can use it instead of hardcoding optional: false.

Closes acacode#1755

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 6 files

Re-trigger cubic

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 19, 2026

🦋 Changeset detected

Latest commit: 209cb7a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
swagger-typescript-api Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

extractRequestParams: query params object required even when all fields are optional

1 participant