Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: keep type information for nullable fields when possible #1524

Merged
merged 4 commits into from
Feb 3, 2024

Conversation

WickyNilliams
Copy link
Contributor

@WickyNilliams WickyNilliams commented Jan 30, 2024

Changes

The PR #1468 was too aggressive in its use of unknown for nullable fields. It makes sense to use unknown when there is no type 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):

I found that when a field has no type information, but nullable: true, the resulting Typescript is Record<string, unknown> | null.

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

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

Copy link

changeset-bot bot commented Jan 30, 2024

🦋 Changeset detected

Latest commit: fe6c6d1

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

This PR includes changesets to release 1 package
Name Type
openapi-typescript Patch

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

@WickyNilliams WickyNilliams changed the title Fix/improve nullable field Fix: keep type information for nullable fields when possible Jan 30, 2024
@WickyNilliams
Copy link
Contributor Author

@davidleger95 i'd be interested in your thoughts, since this is a refinement of your PR

@drwpow
Copy link
Owner

drwpow commented Feb 3, 2024

I’m OK with this change! Would welcome @davidleger95’s thoughts async on this as well, but I also think this is an improvement (I wouldn’t consider changes to unknown a significant breaking change)

@drwpow drwpow merged commit 0b50c1e into drwpow:6.x Feb 3, 2024
6 checks passed
@WickyNilliams
Copy link
Contributor Author

Appreciate it! Can probably close #1407 as fixed now?

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.

None yet

2 participants