Secret Sauce
Secret Sauce

Reputation: 1

Json Schema Properties with $ref

Trying to use $ref for the entirety of properties. I can't tell what this is syntax valid but doesn't validate the payload. This should fail but doesn't.

I've also tried "$ref": "file:./ref.json".

schema:

{
  "animal": {
    "properties":{
      "allOf": {"$ref": "file:./ref.json"}
    }
  },
  "required": ["animal"]
}

ref.json:

{
    "action":{
        "type": "string"
        },
    "required": ["action"]
}

payload

{
    "animal": {
        "action": 2
    }
}

Upvotes: 0

Views: 1179

Answers (1)

Ether
Ether

Reputation: 53966

  • "allOf": {"$ref": "file:./ref.json"} is not syntactically valid -- the value of an allOf must be an array. (your evaluator should be giving you a warning about this.)
  • JSON Schema evaluators are not required to support loading external files from disk or the network. Check your documentation for how to add documents to the evaluator so they can be used by $ref. (your evaluator should be giving you a warning when you reference an unknown resource.)

The reason why you are not seeing the above errors is because your overall schema has no recognized keywords in it -- you are missing a "properties": { ... } wrapped around the entire schema. The top level "keyword" is "animal", which is not recognized, therefore there are no recognized keywords anywhere in the schema, therefore there is nothing to make it return an invalid result.

Upvotes: 1

Related Questions