Skip to content

Add default injection #1017

@wassupxP

Description

@wassupxP

Hi,
First of all, thank you for this library. The performance difference over pure Python jsonschema is massive, and it's made a real difference for us.

Unfortunately, we're missing two things that would make jsonschema_rs a complete solution rather than requiring a second post-processing layer. If this was already discussed (or is already present and I just didn't find it), I apologize.

1. Default injection

Fill missing instance keys from default values declared in the schema.
I guess this is a controversial topic, as this is discussed in multiple places already (e.g., https://www.learnjsonschema.com/2020-12/meta-data/default/ / https://python-jsonschema.readthedocs.io/en/stable/faq/#why-doesn-t-my-schema-s-default-property-set-the-default-on-my-instance ), but we believe it would be incredibly useful as an optional feature.

2. Schema metadata access - for keys that have default values.

Retrieve the sub-schema governing a given instance path - specifically to read custom annotation keywords on fields that may not even be present in the instance yet (because they'll be filled from default).
Our specific use case: we mark certain fields in the schema with is_path: true to indicate that their values are paths and should be normalized after validation. This works fine for fields the user actually provides - we can iterate over the annotations. But for fields that are absent and would be filled using the default values, there's no way to know which of those injected values are paths and which aren't, without walking the schema tree ourselves. If we had access to the part of the schema that's being used for the validation of the current instance, we could easily get that information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions