Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSONSchema split one big schema file into multiple logical smaller files

I want the common parts of json schema to be captured in a file and then reference this file from the main schema file. So basically instead of 1 big json schema file, multiple files which reference each other. Am using json-schema-validator lib to validate.

E.g.:

$ ls schemas/
response_schema.json results_schema.json

$ cat schemas/response_schema.json
{
    "$schema": "http://json-schema.org/draft-04/schema",
    "type": "object",
    "required": [ "results" ],
    "properties": {
        "results": "####Reference results_schema.json file here somehow####"
    }
}   

$ cat schemas/results_schema.json
{
    "$schema": "http://json-schema.org/draft-04/schema",
    "type": "array",
    "items": {
        "type": "object",
        "required": ["type", "name"],
        "properties": {
            "name": { "type": "string" },
            "dateOfBirth": { "type": "string" }
        }
    }
}
like image 971
nishant Avatar asked Aug 22 '13 09:08

nishant


1 Answers

Following solution worked for me:

    "results": {
        "$ref": "file:src/test/resources/schemas/results.json"
    }

The above solution satisfies my requirements:

  1. All my schema files are on local file system and not hosted by some url
  2. Path specified is relative to the directory where I run mvn goals.
like image 66
nishant Avatar answered Oct 22 '22 02:10

nishant