Until now, js2n only supported internal references to either top-level definitions or JSON pointer composed only of properties, that is /properties/x/properties/y/[...].
This PR extends the handling to many other JSON schema keyword that can appear in a valid JSON pointer, for example pointer element like items/2, contains or oneOf/0. This is in particular useful to use json-schema-to-nickel together with a schema bundler to get rid of external references: the bundler can create such currently unsupported references.
Content
This change incurred a refactoring which makes the overall environment logistic simpler: there are less ad-hoc distinctions (schemas vs contracts, properties predicates versus definitions predicates, etc.).
In the end, all references are treated as a unique elements in a flat environment (as opposed to a nested structure before) whose identifier is determined by the full pointer plus its usage (contract and predicate). The only remaining special casing is for a contract usage of a property-only path, which can be referenced directly from the converted schema and doesn't need to be duplicated in the environment.
We also got rid of the JsonPointer type in favor of a more structured SchemaPointer.
Limitations
The only remaining unsupported keywords are due to schemars limitations: schemars doesn't handle properly nested definitions (or, put differently, js2n only handles references to top-level definitions) and some less frequent keywords, such as prefixItems.
Beside keywords, remaining limitations for internal references are:
the empty path isn't supported (which should refer to the whole schema itself). It shouldn't be very hard, but require to put the whole schema in a let rec
identifier-only fragments references, like #foo. This should refers to a subschemas with the corresponding id.
Motivation
Until now, js2n only supported internal references to either top-level definitions or JSON pointer composed only of properties, that is
/properties/x/properties/y/[...]
.This PR extends the handling to many other JSON schema keyword that can appear in a valid JSON pointer, for example pointer element like
items/2
,contains
oroneOf/0
. This is in particular useful to use json-schema-to-nickel together with a schema bundler to get rid of external references: the bundler can create such currently unsupported references.Content
This change incurred a refactoring which makes the overall environment logistic simpler: there are less ad-hoc distinctions (schemas vs contracts, properties predicates versus definitions predicates, etc.).
In the end, all references are treated as a unique elements in a flat environment (as opposed to a nested structure before) whose identifier is determined by the full pointer plus its usage (contract and predicate). The only remaining special casing is for a contract usage of a property-only path, which can be referenced directly from the converted schema and doesn't need to be duplicated in the environment.
We also got rid of the
JsonPointer
type in favor of a more structuredSchemaPointer
.Limitations
The only remaining unsupported keywords are due to schemars limitations: schemars doesn't handle properly nested definitions (or, put differently, js2n only handles references to top-level definitions) and some less frequent keywords, such as
prefixItems
.Beside keywords, remaining limitations for internal references are:
let rec
#foo
. This should refers to a subschemas with the corresponding id.