0

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
    }
}
1

1 Answer 1

1
  • "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.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for clarifying the top level keyword issue. As for the file, it's a local file in the same folder as the schema (Win10). However, with the properties added, it still resolves with no issues. ``` { "properties": { "animal": { "type": "object", "properties":{ "allOf": {"$ref": "file:./ref.json"} } } }, "required": ["animal"] } ```
Is this perhaps an issue of how Draft-7 uses $ref? As with the following, the second value works but not ideal for what I'm looking for. "$ref": "ref.json", "action":{"$ref": "ref.json"}
You cann't use $ref in a non-schema object in JSON Schema. I you want to show an updated JSON Schema given part of the answer here, it's best you add to your question. Adding code in comments here is not very useful.
You're still missing the wrapping list around the contents of allOf, as noted in the first bullet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.