quicktype
quicktype copied to clipboard
[FEATURE]: Schema to JSON
JSON schema permits the passing of default values; these could be used to generate baseline JSON data.
Currently, this feature is not supported, evident by following message:
$ quicktype -o build/config.json -l json --src-lang schema cmake/config/config.schema.json
Error: Unknown output language json.
Context (Input, Language)
Input Format: JSON schema Output Language: JSON
Description
While not a deal-breaker this could potentially make life easier, when using JSON as an application configuration language, by providing an automated method of providing a baseline configuration for the application at build time.
Currently, providing default config files would mean either
- waiting for the application to compile and dump the config (with/without sane defaults) on the target
- manually writing JSON and hoping to remember to update it when the schema changes
This is especially prominent when cross-compiling, where it'd be more effort than it's worth to create an intermediate application in the build pipeline, who's only purpose is to generate a default configuration.
Current Behaviour / Output
$ quicktype -o build/config.json -l json --src-lang schema cmake/config/config.schema.json
Error: Unknown output language json.
Proposed Behaviour / Output
Proposed behaviour would be that Quicktype generates a valid JSON file with configured defaults, null where applicable or throws an error message if no default value can be assigned.
Solution
A potential (Quick and Dirty) solution may be to utilise the class generator for Typescript, parse the schema and output a serialised object.
For this solution to work, Quicktype would need to respect default values - this is currently (at least with C++) not the case.