fix(openapi-typescript): emit \ as optional property (#2664)#2835
Open
EduardF1 wants to merge 1 commit into
Open
fix(openapi-typescript): emit \ as optional property (#2664)#2835EduardF1 wants to merge 1 commit into
EduardF1 wants to merge 1 commit into
Conversation
…2664) The generated $defs container was emitted as a required property, forcing consumers to supply it when using a schema as an input type even though $defs only hosts reusable subschema definitions. Mark it optional so it is no longer required on input; $refs that index into $defs continue to resolve. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🦋 Changeset detectedLatest commit: 004105f 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 |
👷 Deploy request for openapi-ts pending review.Visit the deploys page to approve it
|
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.
Changes
Fixes #2664.
The generated
$defscontainer is currently emitted as a required property of the surrounding object type. Because$defsonly hosts reusable subschema definitions (it never appears in actual request/response data), requiring it forces consumers to supply a$defsvalue whenever they use the generated schema as an input type, producing spurious type errors.This change marks the emitted
$defsproperty as optional (adds a?question token).$refs that index into$defs(e.g.components["schemas"]["OtherObject"]["$defs"]["nestedDef"]) continue to resolve, because indexed-access types work identically on optional properties — so ref resolution is fully preserved.Before
After
How to review
packages/openapi-typescript/src/transform/schema-object.ts— the emitted$defsPropertySignaturenow usesQUESTION_TOKENinstead ofundefined.test/transform/schema-object/object.test.tsandtest/index.test.ts(including theJSONSchema > $defs are respectedcase that exercises refs into$defs) updated from$defs:to$defs?:. These assertions only pass with the fix in place.Tests run
vitest run test/transform/schema-object/object.test.ts test/index.test.ts→ 56 passedvitest run test/transform test/discriminators.test.ts test/node-api.test.ts→ 194 passed (validated before submission)biome checkon the changed files → cleanA changeset (
openapi-typescriptpatch) is included.