santhosh-tekuri / jsonschema

JSONSchema (draft 2020-12, draft 2019-09, draft-7, draft-6, draft-4) Validation using Go
Apache License 2.0
957 stars 98 forks source link

Error when loading valid draft7 json schema #129

Closed gusfcarvalho closed 1 year ago

gusfcarvalho commented 1 year ago

When trying to compile a valid draft7 json schema like this one https://github.com/usnistgov/OSCAL/releases/download/v1.1.0/oscal_catalog_schema.json the tool returns an error as it cannot reference find valid ids on the schema.

After some troubleshooting, I think this might be related to here as in these cases, the definition both have an id and a reference to a common expression.

I already confirmed that changing it to if _, ok := m["$ref"]; ok && d.version <7 would work, but I'm not sure the impact this would have on this tool

santhosh-tekuri commented 1 year ago

EXPECTED_BEHAVIOUR

$ref keyword does not allow other keywords in draft7. it allows from draft 2019 onwards: see https://json-schema.org/draft/2019-09/release-notes.html#core-vocabulary

there is also test for this in draft 7: check this

the mentioned schema is using $id and $ref as siblings in draft07, which is not allowed. in draft07, if $ref is present, we ignore any other sibling keywords.

gusfcarvalho commented 1 year ago

Thanks for the clarification @santhosh-tekuri ! I'll take this back to usnistgov/OSVAL instead :)