I have a general question. How do we decide if an option for a property will go in schema or ui-schema? Let’s say I have to specify options for the select input, right now I have to specify it on enum property in the schema but someone may say that It should be part of ui-schema. There are other examples as well. e.g labels for the groups and inputs, specifying options for the array, specifying the max and min rows for the input area etc.
Are there any general guidelines to follow while deciding on what goes where?
[original thread by shivgarg5676]
Information describing the data itself should be part of the JSON schema, while information describing how the data shall be rendered should be part of the ui schema. For some information there will always be a grey area where one could argue for either schema.
In general I would like to recommend to stick to the JSON Schema specification for the JSON Schema. Therefore if a feature you want to implement can be represented in your JSON Schema then go for it. Adding it there in a clean way may enable further use cases later on with JSONForms or other frameworks.
If there is no clean way to integrate it in JSON Schema feel free to adapt your UI schemas to your liking. If you want to stay compatible to JSONForms as far as possible I would like to recommend adding entries to the options object of each control. However you can of course adapt / change the whole UI schema if needed.
If a concept can’t be represented cleanly in either schema you could also implement your own additional format and process it in your renderers.
These are just general guidelines. As always those may or may not fit your specific use cases and requirements. If you want to discuss a specific example feel free to describe it here or in a new question.
Thanks @sdirix for clarification over here. That explains a lot of things.
If I talk about string type element then we(jsonform) has properties like “description” to be specified in the schema. But if we see json-schema specification for type string there is no such property called description. So I got confused that if that should be part of schema or ui-schema.
Therefore if a feature you want to implement can be represented in your JSON Schema then go for it. Adding it there in a clean way may enable further use cases later on with JSONForms or other frameworks quote explained the particular use case. Am I right?
More to this, I recently implemented functionality to sort arrays. For that I added the option named
showSortButtons in the ui schema. Would have it been better if I had placed an option in schema itself for type array something like this
description keywords are part of the JSON Schema Validation Specification. Note that many frameworks supporting JSON Schema are actually supporting JSON Schema Core + JSON Schema Validation.
If title and description would not be part of JSON Schema I would have recommend adding them to the UI schema to avoid using an unspecified keyword in JSON Schema.
Got it, Then array implementation was right. Thanks!!
As I don’t know of any way to specify this functionality within JSON Schema I would like to recommend to add it to the UI schema. Note that we already implemented functionality for manual sorting which can be enabled with
showSortButtons: true in the options field of an array control. You can also check the
Glad to help! Just to clarify: I would recommend adding your sorting option to the UI schema, not the JSON schema. So I would not use the JSON Schema you showcased above.