schemasafe
schemasafe copied to clipboard
Question: Null or reference?
This is probably not a problem with schemasafe, just a question:
Is it possible to have a property either be a reference or null?
In Webstorm for example this works if I want media to be nullable:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "my.schema",
"type": "object",
"additionalProperties": false,
"title": "my secret schema",
"required": [
"ownerNumber"
],
"media": {
"oneOf": [
{
"type": "null"
},
{
"$ref": "media.schema.json"
}
]
}
}
If I send media as object everything works as it should, but if I send media: null I get this error message from schemasafe:
{
"keywordLocation": "#/properties/objects/items/$ref/properties/media/oneOf/1/$ref/type",
"instanceLocation": "#/objects/0/media"
}
So is it possible to allow both null and the reference?
Media is actually under "properties", I didn't want to post my whole schema.
Perhaps it satisfies both conditions, and oneOf
is looking for exactly one per spec?
Does using anyOf
help? It's hard to tell without media.schema.json
(i.e. does null
pass it or not).
See https://json-schema.org/understanding-json-schema/reference/combining.html#oneof for an explainer.
Also, sorry for the late response.
Going to close as answered, please comment if this should be reopened.