Open sztomi opened 1 year ago
I am facing the same problem with internal references. Were you able to figure it out?
@VoltaireNoir with a very ugly hack: https://github.com/sztomi/dap-rs/blob/main/integration_tests/src/lib.rs#L27
@VoltaireNoir with a very ugly hack: https://github.com/sztomi/dap-rs/blob/main/integration_tests/src/lib.rs#L27
Ah, I arrived at the same solution: to replace the references with the appropriate schema. I guess I'll stick with it until jsonschema is able to resolve local/internal references correctly.
I have complex schema with dependencies between files and defined objects. I can't extract an object like @sztomi has shown in his example. Is it still possible to use this subschema to validate?
I have complex schema with dependencies between files and defined objects. I can't extract an object like @sztomi has shown in his example. Is it still possible to use this subschema to validate?
I believe this library supports resolving web and file based references. Try enabling the resolve-http
and resolve-file
feature flags.
Try enabling the resolve-http and resolve-file feature flags.
This solves a small portion of my goal.
I have several files common.yml
, schema1.yml
and schema2.yml
(json schema is saved in safe yaml without references), all of these files contain all objects under $defs
. Main schema contains only schema version, it's $id
and minimal description. My goal is to create a validator object to validate by a definition for an object defined as above. Obviously loader is restricted by a folder where schemas are located and other locations are deliberately disabled to avoid security issues.
In current setup I use another validator (as it's a Python project) where I able to load given files into registry and then during application startup add referencing schemas to create an actual validator. Referencing schemas are anonymous schemas with references to an actual object defined in the registry, e.g. containing only $ref
pointing to schema1.yml:#/$defs/obj1
or urn:schema:2:id:#/$defs/obj2
(where urn:schema:2:id
is an $id
value from schema2.yml
file).
Could you please help me how to do a similar thing using this library?
This is a very useful crate. Nicely done.
I've worked around the limitation in a similar use case by iterating through the definitions and concatenating an "allOf:" [{"$ref":"#/definitions/<schema-needed-later>"}]
to the end and then compiling the full schema for the definitions I need later.
example:
{<all-definitions-here>, "allOf:" [{"$ref":"#/definitions/<schema-needed-later1>"}]}
{<all-definitions-here>, "allOf:" [{"$ref":"#/definitions/<schema-needed-later2>"}]}
This is inefficient from a compile time & memory perspective, so I'd like to +1 this request.
Options I can think of would be:
validator.validate(&json, "#/definitions/Event")
or similar).
validator = validation_options.build(&schema3, "#/definitions/Event")
or similar)
I tried to implement a facsimile of (1) by making a version of validate
that also accepts a LazyLocation, but I'm wasn't familiar enough with the code to make it work.
I think (1) would also help with this issue: https://github.com/Stranger6667/jsonschema/issues/452
I'm trying to validate JSON snippets against the DAP JSON schema: https://microsoft.github.io/debug-adapter-protocol/debugAdapterProtocol.json
Each type of message is a separate definition. I can extract and compile the relevant definition, but references are not resolved. I think I need to use the
with_document
function, but I'm not sure what the ID is supposed to be.This results in
I tried an empty string as well, but that didn't work either. Any clues?