1

I am creating thousands of definitions and making it available on remote so that any one can reuse the defined schema by referring remote ref. at the time of definition creation i want something which can check the $ref and throw error if it is not available

{
      "definitions":{
        "description100Type":{
          "$ref":"#/definitions/additinalType"
        }
      },
      "$schema":"http://json-schema.org/draft-07/schema#",
      "$id":"http://example.com/root.json"

    }

In the above example description100Type referring additinalType which was not defined. How to validate the above case ? i am using ajv for validations.

note:ajv is throwing proper error if description100Type is referred inside properties

{
  "properties":{
    "checked":{
      "$id":"#/properties/checked",
      "$ref":"#/definitions/description100Type"
    }
  }
}
eagle
  • 312
  • 1
  • 13
  • 1
    The schema you have currently provided does not make sense or is not complete. Can you please provide your complete schema, or explain what you think it should do? The error is correct. What is your expected behaviour? – Relequestual Jan 08 '19 at 11:09
  • I just need to validate definitions part present in JSON schema – eagle Jan 08 '19 at 11:29
  • I'm sorry, I still do not understand what you want to do, because what you are asking to do does not make sense. Can you start again, and modify your question to explain what you are doing and what you expect to happen please? – Relequestual Jan 08 '19 at 11:30
  • The JSON Schema you have provided includes a reference to another schema, which you haven't included in the provided schema. In addition you do not reference the definition you have provided anywhere. Did you write this schema or was it provided for you? – Relequestual Jan 08 '19 at 11:32
  • if anything inside definitions (like description100Type) referring another definitions (#/definitions/additinalType) which is not present then the error like :Can't resolve reference #/definitions/additinalType – eagle Jan 08 '19 at 11:33
  • That is correct. I think you may need to check you have a correct understanding of `$ref` and `definitions`: https://json-schema.org/understanding-json-schema/structuring.html#reuse – Relequestual Jan 08 '19 at 11:36
  • Thanks for the clarification. I am creating thousands of definitions and making it available on remote so that any one can reuse the defined schema by referring remote ref. at the time of definition creation i want something which can check the $ref and throw error if it is not availble – eagle Jan 08 '19 at 11:42
  • OK. Please take a moment to read the StackOverflow guide on how to ask a good question: https://stackoverflow.com/help/how-to-ask – Relequestual Jan 08 '19 at 11:46
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/186351/discussion-between-monica-garud-and-relequestual). – eagle Jan 08 '19 at 11:53

0 Answers0