Fix: query params object incorrectly required when all fields are optional (extractRequestParams)#1756
Open
Upgrade220 wants to merge 2 commits into
Open
Fix: query params object incorrectly required when all fields are optional (extractRequestParams)#1756Upgrade220 wants to merge 2 commits into
Upgrade220 wants to merge 2 commits into
Conversation
…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>
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 209cb7a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:The root cause is that
procedure-call.ejshardcodesoptional: falsefor the combined params argument. TheallFieldsAreOptionalflag is already computed correctly insiderequestParamsSchema.typeDataby the existingObjectSchemaParser, but it was never surfaced to the template.Solution
I propose a minimal source-level fix: expose
requestParamsSchema?.typeData?.allFieldsAreOptionalasrequestParamsOptionalon the route's request info object inparseRouteInfo()(schema-routes.ts). The template then reads this flag instead of hardcodingfalse, 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.
Changes
src/schema-routes/schema-routes.ts— addrequestParamsOptionalto the route request infotypes/index.ts— addrequestParamsOptional?: booleantoParsedRouteRequesttemplates/default/procedure-call.ejs— readroute.request.requestParamsOptionalinstead of hardcodedfalsetemplates/modular/procedure-call.ejs— same changetests/spec/extractRequestParams/schema.json— add a route with only optional query params to cover this case= {}Summary by cubic
Fixes
extractRequestParamsso 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{}.= {}when all its fields are optional and there are no path params.requestParamsSchema.typeData.allFieldsAreOptionalasrequestParamsOptionalinschema-routes.ts, and addrequestParamsOptionaltoParsedRouteRequestintypes/index.ts.templates/*/procedure-call.ejsto respectrequestParamsOptionaland setdefaultValue: '{}'when applicable.Written for commit 209cb7a. Summary will update on new commits. Review in cubic