Fix: keep type information for nullable fields when possible #1524
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
The PR #1468 was too aggressive in its use of
unknown
for nullable fields. It makes sense to useunknown
when there is notype
defined in the schema. But in cases where there is type information available, we should not discard it.The changes in the snapshots show that richer types are preserved when possible. I wrote a comment on the original PR relating to this, but it's possible it got missed.
Essentially, we use the "old" behavior where we have some type info available in the schema, and the "new" behavior otherwise. The original bug report #1407 says (emphasis mine):
This PR ensures the "has no type information" part is respected.
How to Review
The snapshots and tests should give enough context to evaluate the PR, and hopefully my justification makes sense.
Checklist
docs/
updated (if necessary)pnpm run update:examples
run (only applicable for openapi-typescript)