metomi / rose

:rose: Rose is a toolkit for writing, editing and running application configurations.
https://metomi.github.io/rose/
GNU General Public License v3.0
55 stars 50 forks source link

edit: decide on a schema #2643

Open oliver-sanders opened 1 year ago

oliver-sanders commented 1 year ago

We are currently considering JSON Schema, however, we should have a quick look around to make sure this is the best choice.

Points in favour of JSON Schema:

aenglyst commented 1 year ago

Assessment of JSON Schema

The current version is 2020-12

Specification links can be found here:

Specification Links | JSON Schema (json-schema.org)

aenglyst commented 1 year ago

Pros

Cons

aenglyst commented 1 year ago

Alternatives

Other JSON data validators exist, and these can be used alongside tools such as jsonlint, for validating JSON for the correct format rather than allowing for custom validation of JSON instances.

Other alternative architectures for API consideration include:

OpenAPI, AsyncAPI.

Some of the alternatives to JSON Schema are TypeSchema or JTD, that instead of focusing on validation, focus on the definition of data models. Although the addition of such an extra layer may just add unnecessary complexity.

TypeSchema

TypeSchema is a code generator friendly alternative to JsonSchema explained as:

For code generators it is difficult to work with JSON Schema since it is designed to validate JSON data. In JSON Schema you don't need to provide any keywords i.e. {} is a valid JSON Schema which basically allows every value and the defined keywords are applied based on the actual data. This means you can interpret a schema only if you have also the actual data. A code generator on the other hand needs to determine a concrete type of a schema without the actual data.

Because of this TypeSchema is designed in such a way that it is possible to determine a concrete type based on the used keywords. You can think: TypeSchema is to JsonSchema what TypeScript is to Javascript, a more type safe version which has also keywords for better inheritance, union/intersection and generic handling.

JTD - jtd (jsontypedef.github.io)

Validating JSON data in shell scripts with jtd-validate (jsontypedef.com)

JSON Type Definition, aka RFC 8927, is an easy-to-learn, standardized way to define a schema for JSON data. You can use JSON Typedef to portably validate data across programming languages, create dummy data, generate code, and more.

This jtd package is a JavaScript / TypeScript implementation of JSON Type Definition. It lets you validate input data against JSON Type Definition schemas. jtd works in Node.js and web browsers.

If you're looking to generate code from schemas, check out "Generating TypeScript from JSON Typedef schemas" in the JSON Typedef docs.

Other options: Standards for describing JSON structures:

aenglyst commented 1 year ago

Conclusion

In summary, although there are some limitations, json-schema seems to be a good fit for allowing validation of translated metadata and there are many implementations and pre-existing tooling to facilitate an end-to-end metadata configuration editor in a modern web driven context. This is a good technology solution, although some further work is needed to verify extensibility options and for enabling custom widget capabilities.