Skip to content

Conversation

@luqasn
Copy link

@luqasn luqasn commented Nov 23, 2025

Changes

This PR introduces a new option that makes it possible to request that non-required parameters still be generated as non-optional (no question token) if they have a default value set in their schema.

This allows to generate types for certain server implementation use where the default value is injected automatically for the handling function to consume (I am working on one atm) and the signature on the handler should indicate that the value can not be undefined.

This makes it so that the default value can be derived and set by the framework from the openapi spec and does not need to be repeated by the person implementing the operation.

This an example of an implementation that leverages the new setting: henhal/openapi-ts-backend@ee87617

Fixes #2319

Checklist

  • Unit tests updated
  • docs/ updated (if necessary)
  • pnpm run update:examples run (only applicable for openapi-typescript)

@luqasn luqasn requested a review from a team as a code owner November 23, 2025 13:12
@luqasn luqasn requested a review from duncanbeevers November 23, 2025 13:12
@netlify
Copy link

netlify bot commented Nov 23, 2025

👷 Deploy request for openapi-ts pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 83a26e9

@changeset-bot
Copy link

changeset-bot bot commented Nov 23, 2025

🦋 Changeset detected

Latest commit: 83a26e9

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

This PR includes changesets to release 2 packages
Name Type
openapi-typescript Minor
swr-openapi Major

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

@luqasn luqasn force-pushed the optional-param-with-default branch from 7eb397e to 3f0607e Compare November 23, 2025 13:15
@luqasn
Copy link
Author

luqasn commented Nov 23, 2025

Test failure seems unrelated, docly have refactored their tests and moved a bunch of files: Redocly/redocly-cli@cf26d60#diff-819418d7530fd6a1220968de72601d679939eb5a01c3b9cc9e388050bd58ff77

@sacha-c
Copy link
Contributor

sacha-c commented Dec 3, 2025

Test failure seems unrelated, docly have refactored their tests and moved a bunch of files: Redocly/redocly-cli@cf26d60#diff-819418d7530fd6a1220968de72601d679939eb5a01c3b9cc9e388050bd58ff77

Indeed, I've address this in a separate PR a few weeks back which is awaiting review: #2522

@luqasn luqasn force-pushed the optional-param-with-default branch from 5d314f4 to 83a26e9 Compare December 4, 2025 22:11
@luqasn
Copy link
Author

luqasn commented Dec 4, 2025

Thanks @sacha-c, I rebased on top of your merged commit and removed my fixes.

@duncanbeevers could you have a look? Or is there someone else I should ask for a review?

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.

query parameters with default value are marked as optional

2 participants