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

encoding/jsonschema: generation of templates with regular fields and default values #3473

Open
rogpeppe opened this issue Oct 1, 2024 · 0 comments

Comments

@rogpeppe
Copy link
Member

rogpeppe commented Oct 1, 2024

In #3472, we state that to conform to the specification, the jsonschema logic should not
treat default values as part of the generated schema. But it would still be useful to
be able to make use of those default values.

Straw man feature: we could have the option to generate a "template value" for
a given JSON Schema that does define regular fields and default values.

Note that this is not a trivial thing to do, as defaults and regular fields do not
mix nicely with the validator-only nature of matchN, as generated by oneOf, allOf and anyOf.

For example:

{
    "$schema": "https://json-schema.org/draft/2019-09/schema",
    "oneOf": [
        {
            "properties": {
                "a": {
                    "type": "string",
                    "default": "foo"
                }
            }
        },
        {
            "properties": {
                "b": {
                    "type": "string",
                    "default": "bar"
                }
            }
        }
    ]
}

The natural encoding for this might be:

matchN(1, [{
    a: string | *"foo"
    ...
}, {
    b: string | *"bar"
    ...
}])

but that won't fill in defaults at all, because matchN is a pure validator. But I don't think we know how to combine templates and oneOf etc semantics right now.

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