fix: Avoid schema key collision when extracting request params - #1835
Merged
js2me merged 1 commit intoSep 18, 2026
Merged
Conversation
With extractRequestParams enabled, the generated <operationId>Params type was registered without checking whether components.schemas already had a schema of that name. When it did (e.g. a getOrder operation whose request body model is called GetOrderParams), the model was overwritten by the route's path/query params and the method's body argument was typed as the path params. Route createRequestParamsSchema through the same schema-key collision guard that extractResponseBody and extractResponseError already use. Co-authored-by: Cursor <cursoragent@cursor.com>
🦋 Changeset detectedLatest commit: 38190c6 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 |
Member
|
@ryanb93 thank you! |
Merged
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.
Problem
With
extractRequestParams: true, the extracted<operationId>Paramstype is registered as#/components/schemas/<operationId>Paramswithout checking whether that key already exists in the spec. When it does, the existing model is silently overwritten.This is easy to hit in practice: an operation
getOrderwhose request body model is calledGetOrderParams. Since 13.2.9 (#1381) path-only routes also produce an extracted params type, so any route with a path parameter is exposed, not just routes with query params.Given this spec fragment:
the generated output on
mainis:The method still compiles, so nothing flags it —
datais just typed as the path params instead of the body.Solution
extractResponseBodyandextractResponseErroralready handle this viaextractTypeNameWithoutSchemaKeyCollision, which checks the candidate name against the registered components and reserves/retries until it finds a free one.createRequestParamsSchemacalledresolveTypeNamedirectly and skipped that guard. This PR routes it through the same helper.With the fix the output becomes:
The
1suffix is the existing fallback behaviour ofNameResolver, consistent with how response-body collisions are already resolved. Users who want a nicer name can still supplyextractingOptions.requestParamsNameResolver.I considered instead reserving all schema names in
componentTypeNameResolverup front, but that would change name resolution for every extractor and is a larger behavioural change than this bug warrants.Verification
tests/spec/extractRequestParams-schema-name-collisionwith a minimal schema reproducing the collision (path-param route + same-named body model, plus a control route with path + query params). It fails onmain(the body model's fields disappear) and passes with this change.bun run format:checkis clean.bun run lintreports the same pre-existingnoExplicitAnywarnings asmain; nothing new in the touched files.Summary by cubic
Fixes
extractRequestParamsoverwriting a component schema when its name matches<operationId>Params(for example agetOrderoperation whose request body model isGetOrderParams). Route params now use the same schema-key collision guard as response extractors, so the original model keeps its name and the extracted params type is renamed to the next free name likeGetOrderParams1.Notes
extractingOptions.requestParamsNameResolver.Written for commit 38190c6. Summary will update on new commits.