nickel-lang / json-schema-to-nickel

Convert JSON schemas into Nickel contracts
Apache License 2.0
29 stars 0 forks source link

Support for nested definitions #79

Closed yannham closed 3 months ago

yannham commented 3 months ago

schemars doesn't properly handle definitions that aren't at the top-level (there's no proper field), however, unsupported data like those are still stored as pure JSON values inside the extensions field.

This PR uses this field to properly handle nested definitions, by manually deserializing the JSON value obtained on-the-fly to a JSON schema. This requires sprinkling some Cow instead of pure references to make rustc happy while still borrowing data as much as possible (avoiding useless clones).

Interestingly, this approach can be extended for other JSON schema keywords that aren't currently supported by schemars.