-
Notifications
You must be signed in to change notification settings - Fork 81
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
feat: Add NullableFromType
option
#110
base: main
Are you sure you want to change the base?
Conversation
Reflector.NullableFromType
optionNullableFromType
option
Closes #14027 Blocked by: * cloudquery/codegen#39 * invopop/jsonschema#109 – merged to `cloudquery/jsonschema@cqmain` * invopop/jsonschema#110 – merged to `cloudquery/jsonschema@cqmain` I propose reviewing the annotations along with tests, as the JSON schemas generated are just too long to grasp visually.
@samlown I hope you're doing well in these uneasy days. I've implemented the changes in #109 & #110 & tested them via a fork at The results of using the updated code along with Could you please give an estimate when these PRs (#109 & #110) could be merged? It'll be far easier to pin an upstream version instead of maintaining a fork for these 2 changes. |
Closes cloudquery#14027 Blocked by: * cloudquery/codegen#39 * invopop/jsonschema#109 – merged to `cloudquery/jsonschema@cqmain` * invopop/jsonschema#110 – merged to `cloudquery/jsonschema@cqmain` I propose reviewing the annotations along with tests, as the JSON schemas generated are just too long to grasp visually.
Highly interested in this PR as well. Is there anything I can help with to get this merged? |
@kop I really hope @samlown has time to review/merge that. |
1db8e8d
to
0fe1690
Compare
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.
Sorry for the delay there! This looks good to me, thanks! I do think there should be some extra tests for those non-pointer reflection types though.
case reflect.Pointer, | ||
reflect.UnsafePointer, | ||
reflect.Map, | ||
reflect.Slice, | ||
reflect.Interface: | ||
return true |
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 do think there should be specific tests for these types. I also wonder if Interface
and UnsafePointer
are really necessary, if so, there should be a test to show it ;-)
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.
@samlown thanks for the review! I have an additional question here: currently the library uses {
"oneOf": [
{
"oneOf": [
{},
{
"type": "null"
}
]
},
{
"type": "null"
}
]
} If we use I can raise this as a separate issue & address it in a follow-up PR. |
79bb90b
to
8a38808
Compare
Hi! Echoing interest in this PR -- happy to help if there's anything outstanding to get it in. |
Instead of #106.
Allows to define property nullability based on the field type instead of the
jsonschema:"nullable"
tag.Useful when the types included are referenced from 3rd party packages.
Consider the following example:
The following JSON is a perfectly valid value for Go:
The schemas produced for the
TestNullableField
struct are:Old behavior (`NullableFromType:false`)
New behavior (`NullableFromType:true`)
In both cases
a
is required, but the old behavior will fail for{"a":null}
whereas the new one will succeed.