Enforcing that defaults validate against the associated schema

11 views
Skip to first unread message

Patrick Wang

unread,
Dec 20, 2019, 2:35:33 PM12/20/19
to jsonschema - An implementation of JSON Schema for Python
Hi!

I'm trying to validate against the OpenAPI specification: https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v3.0/schema.json
and to enforce the additional OpenAPI requirement that default values actually validate against the associated (sub-)instance.

My solution is demonstrated in the attached script. As has been done in other examples, I'm extending the properties validator.

The problem is in resolving references in the sub-instance against which we need to validate. My solution has been to generate a separate Validator based on the full instance and store it as an attribute of the main Validator ahead-of-time. It feels janky to me an I am wondering if anyone has ideas for a more elegant solution.

Thanks,
-Patrick
test_default_validation.py
Reply all
Reply to author
Forward
0 new messages