Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE]: Schema to JSON #2683

Open
SimonCahill opened this issue Feb 5, 2025 · 0 comments
Open

[FEATURE]: Schema to JSON #2683

SimonCahill opened this issue Feb 5, 2025 · 0 comments

Comments

@SimonCahill
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant