santhosh-tekuri/jsonschema

Support for $defs and definition keyword in Schema object.

Closed this issue · 3 comments

Currently the schema object does not have a property to hold schema definition(defined by definitions or $defs keyword defined by the top level schema. Any plans to add the field to do the same. Since, if the schemas aren't referenced, they aren't available to be referenced in the top level schema.

I've got the same issue. This is just a small snippet of my huge json schema with the error message below.

[...]
"filter": {
                "type": "object",
                "required": [
                  "objective"
                ],
                "properties": {
                  "$ref": "#/$defs/objective"
                }
              },
[...]

jsonschema file:///.../config-v2-schema.json compilation failed: '/properties/v2/properties/account/items/properties/filter/properties/$ref' does not validate with https://json-schema.org/draft/2020-12/schema#/allOf/1/$ref/properties/properties/additionalProperties/$dynamicRef/allOf/1/$ref/properties/properties/additionalProperties/$dynamicRef/allOf/1/$ref/properties/items/$dynamicRef/allOf/1/$ref/properties/properties/additionalProperties/$dynamicRef/allOf/1/$ref/properties/properties/additionalProperties/$dynamicRef/type: expected object or boolean, but got string

I don't think the error is related to the issue, in your case, the $defs resolution is working, it's just that your jsonschema is incompatible with draft 2020 spec. @maribowman

NOT_PLANNED

currently we compile only the schemas that are referenced. since validation does not use those unreferenced schemas it would be waste of time to spend cpu cycles compiling them.

if you want you can manually compile them:

compiler.Compile("schema.json#/$defs/first")
compiler.Compile("schema.json#/$defs/second")