-
Notifications
You must be signed in to change notification settings - Fork 87
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 NullableFromJSONSchemaTags
option
#106
Conversation
@samlown this changes the default behavior to be closer to default The other option could be make the default behavior to look for tags & only explicitly use field type for nullability (when some option is set). |
@candiduslynx thanks for this, but I'm trying to understand what exact problem you're trying to solve with this PR. For me, the nullable type is implied when there is no value, I'm really not sure why you'd want to define it explicitly. |
@samlown consider json Consider the example added in 26eed64: type TestNullableField struct {
A *string `json:"a"`
} Old behavior (`NullableFromJSONSchemaTags:true`)
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://github.com/invopop/jsonschema/test-nullable-field",
"$ref": "#/$defs/TestNullableField",
"$defs": {
"TestNullableField": {
"properties": {
"a": {
"type": "string"
}
},
"additionalProperties": false,
"type": "object",
"required": [
"a"
]
}
}
} New behavior (`NullableFromJSONSchemaTags:false`)
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://github.com/invopop/jsonschema/test-nullable-field",
"$ref": "#/$defs/TestNullableField",
"$defs": {
"TestNullableField": {
"properties": {
"a": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false,
"type": "object",
"required": [
"a"
]
}
}
} In both cases |
c3d819f
to
26eed64
Compare
I'm going to reopen a fresh version that preserves default behavior + add README.md doc for this |
Replaced by #110 |
This changes default behavior to look for the
jsonschema:"nullable"
tag to mark field optional onlyReflector.NullableFromJSONSchemaTags
is set totrue
.In Go it's perfectly fine to unmarshal the following types from
null
:This PR also includes the changes from #107, so it might be better to merge that one first.