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 UNION and NULL types #261

Merged
merged 3 commits into from
Nov 30, 2019
Merged

Fix UNION and NULL types #261

merged 3 commits into from
Nov 30, 2019

Conversation

gmathieu
Copy link
Contributor

@gmathieu gmathieu commented Sep 30, 2019

This fixes the use of UNION and NULL types (ex. { type: ['null', 'string'] }).

See snapshot diff to get a clear idea of what's happening

This is a 3 part fix:

  1. missing schema when mapping over UNION type: { type: _ } vs { ...schema, type: _ }
  2. prioritize UNION type in typeOfSchema
  3. prioritize NULL type in typeOfSchema

The parser needs to process UNION and NULL before other types suchs as ENUM, ARRAY...

This de-dupes `null` types to match existing.

For example:
- without normalizer: `role?: null | ("admin" | "collaborator" | "member"| "owner"| null)`
- with normalizer: `role?: "admin" | "collaborator" | "member"| "owner"| null`
@gmathieu
Copy link
Contributor Author

gmathieu commented Oct 2, 2019

@bcherny any thoughts?

@gmathieu
Copy link
Contributor Author

Hi, does anyone have any feedback?

Copy link
Owner

@bcherny bcherny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable -- thanks for the contribution!

@bcherny bcherny merged commit e144890 into bcherny:master Nov 30, 2019
@bcherny
Copy link
Owner

bcherny commented Nov 30, 2019

Published 8.0.0.

@gmathieu gmathieu deleted the fix_union branch January 5, 2021 17:08
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