Reputation: 171
If I have JSON Schema such as:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/product.schema.json",
"title": "Product",
"description": "A product in the catalog",
"type": "object"
}
Is there field defined in the JSON schema spec that allows me to add options? I am thinking of using the JSON schema itself to generate a UI form but I want to add an option for hiding the field. So I am thinking about doing something like:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/product.schema.json",
"title": "Product",
"description": "A product in the catalog",
"type": "object",
"options" : {
"isVisible": false
}
}
Is this valid JSON Schema or is there standard field I can use for this purpose ?
Upvotes: 1
Views: 1034
Reputation: 53986
By default, JSON Schema evaluators will ignore keywords they don't recognize, so you are free to create new ones such as options
.
However, there is a keyword for the purpose you describe here: readOnly
and writeOnly
: https://json-schema.org/draft/2020-12/json-schema-validation.html#rfc.section.9.4 Setting "writeOnly": true
should indicate (to tools that support this keyword) that the property should never be visible.
Upvotes: 1