-
Notifications
You must be signed in to change notification settings - Fork 430
Add support for nullable primitives #411
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
Conversation
bcherny
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! A few minor suggestions.
| delete copiedSchema.id | ||
| delete copiedSchema.nullable | ||
|
|
||
| // This stuff will be in `anyOf` instead. | ||
| delete schema.format | ||
| delete schema.type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove all of these deletes? Unclear why you need them (156 is already included in 150; 155+159+160 I'm not sure what they're here for).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need all of these deletes. After normalizing, we no longer want nullable, format, or type to appear in the root of the schema. That's what the anyOf is replacing.
For example, the following schema:
{
"id": "foo",
"type": "integer",
"format": "int32",
"nullable": true
}Should be normalized to this:
{
"id": "foo",
"anyOf": [
{
"type": "integer",
"format": "int32"
},
{
"type": "null"
}
]
}
Notice how nullable is gone, and type and format have moved into the anyOf
|
|
||
| schema.anyOf = [ | ||
| copiedSchema, | ||
| // @ts-expect-error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you rm this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get a TS error without it:
Type '{ type: "null"; }' is missing the following properties from type 'LinkedJSONSchema': additionalProperties, [Parent]ts(2739)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! Can you find a way to fix the error? eg. to add an empty additionalProperties, and to add a Parent field?
|
Bump 😭 |
|
I'd love to be able to use this feature as well. Is there anything I can do to help this PR get merged? |
|
Bump |
|
Sorry, y'all. I don't write TypeScript at my new job (unfortunately 😭) so I forgot about this PR. I just responded to a comment the maintainer had, so hopefully I'll be able to push this over the finish line soon |
|
I really need to make this change, is there anything I can do such as new pull request? @bcherny |
|
Closing in favor of #522 |
Picking up where #312 left off.
This PR adds a normalizer that converts
nullable: trueprimitive types intoanyOftypes.