Open theonewolf opened 3 years ago
I think the main task there is if
, then
and else
. The other keywords are largely annotative when considered in from the perspective of this library.
I rarely see if
, then
and else
used in schemas, and have never had a need for them myself. I don't expect it would be overly hard to add them however.
The first step on this journey would be enabling the draft 7 test suite here to see how many tests fail.
FWIW Draft 07 is not the latest specification. The latest specification is 2019-09, but I have little intention of supporting that draft any time soon, as it breaks compatibility with the JSON Reference specification.
I'd be interested in ideas for how if
/then
/else
will look in the models. First thing that comes to mind:
class Person(Object):
address: Object = Conditional(
if_=Element(properties={"country": Property(Element(const="USA"))}),
then=Object.inline(properties={"postcode": Property(String(pattern="[0-9]{5}(-[0-9]{4})?"))}),
else_=Object.inline(properties={"postcode": Property(String())}),
)
@themontem do you have some clean hypothetical examples you could drop in here from our large schema(s)? Also, did we move onto 2019-09
? At which point this is less useful to us.
Would also be interested in draft-07 enhancement.
+1. The CMS "Transparency in Coverage" healthcare pricing data uses a draft-07 schema.
Description of requested feature Draft 7 is the latest specification for JSON Schema and libraries such as
jsonschema
support it out of the box. I have a spec which I'd like to generate a Python class for, but am worried about subtle incompatibilities.The changes do not seem drastic: https://json-schema.org/draft-07/json-schema-release-notes.html
I think we can scope this project well.
Workaround Just try Draft 7 schemas with
statham
out of the box. They may work, especially since a lot of it is backwards compatible ("In terms of validation keywords and outcomes, it is fully backwards-compatible with draft-06.").Additional context I think primary differences are in new out of the box formats, as described on the Draft 7 release notes linked above.