I read the specification. But, I didn't find any information about how to use the readOnly of Array. And a single readonly property is not enough to cover different scenarios.
An example array schema like below:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/product.schema.json",
"title": "Products",
"type": "array",
"items": {
"type": "object",
"properties": {
"productId": {
"description": "The unique identifier for a product",
"type": "integer"
},
"productName": {
"description": "Name of the product",
"type": "string"
},
"price": {
"description": "The price of the product",
"type": "number"
}
}
}
}
Is it possible to achieve the following objectives?
- The array is not allowed to add/remove any item of the array. However, it's allowed to update any item of the array.
- The array is not allowed to update any item of the array. However, it's allowed to add/remove item of the array. Once an item is added to the array, the only action I can take is "remove".
readOnlyis too blunt an instrument to describe those kinds of constraints. However, with a small change, you can express it with JSON Hyper-Schema. You would have to model the individual products and the list of products separately. UnlikereadOnlywhich says what you can't do,linkssay what you can do. Here's what it would look like for each of the cases you identified.