Skip to content

Is it mandatory to use $defs for reused blocks #151

Answered by jdesrosiers
martpio asked this question in Q&A
Discussion options

You must be logged in to vote

The only problem with that approach is that you don't get meta-schema validation if put your schemas somewhere that the dialect doesn't recognize as a schema. Take this schema for example.

{
  "$defs": {
    "foo": { "type": "invalid" },
    "bar": {
      "nested": { "type": "invalid" }
    }
  }
}

Implementations are likely to recognize #/$defs/foo/type has an error, but not #/$defs/bar/nested/type. Instead of telling you your schema has an error in the normal way, it will probably just blow up and you'll have to sift through the wreckage to figure out what went wrong.

If you want to have nested definitions, you could use $id to create a separate context. It's a bit more verbose, but it…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@martpio
Comment options

Answer selected by martpio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants