Skip to content

ref.json "new scope when adjacent to keywords" test #636

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

You must be logged in to vote

$ref is not a merge. It's like allOf where all assertions apply independently. Therefore, it's possible to have conflicting assertions.

{
  "type": "string",
  "$ref": "#/$defs/foo",

  "$defs": {
    "foo": { "type": "number" }
  }
}

This example says that the JSON instance must be a string and must be a number. That's not possible, so any value you validate against this schema will fail validation. Let's look at another example where the conflicting keyword is an annotation that doesn't effect validation.

{
  "title": "Foo",
  "$ref": "#/$defs/foo",

  "$defs": {
    "foo": { "title": "Bar" }
  }
}

What will be the title of the instance evaluated by this schema, "Foo" or "Bar"? It's rea…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@redmitry
Comment options

@jdesrosiers
Comment options

@redmitry
Comment options

Answer selected by redmitry
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