title: Generator Json Schema .NET - Loading External References from Files
body: <p>I am about to write a generator, which gets a starting directory as input and from this location it opens every folder and creates concatenated json schemas.</p>
  
  <pre><code>File 1: ValidResponse.json
  {
      "$schema": "http://json-schema.org/draft-04/schema#",
      "title": "ValidResponse",
      "type": "object",
      "properties": {
          "Head": {
              "type": "object",
              "CommonResponse": {"$ref":"CommonHeader.json"},
              "required":["CommonResponse"]
          },
          "Body": {
              "type": "object"
          }
      },
      "additionalProperties": false,
      "required":["Head","Body"]
  }
  
  File 2: CommonHeader.json
  {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "CommonHeader",
    "type": "object",
    "properties": {
      "RequestArguments": {
        "type": "object",
        "properties": {
          "DataCollection": {
            "type": "string"
          },
          "DeviceClass": {
            "type": "string"
          },
          "Scope": {
            "type": "string"
          },
          "DeviceId": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "Status": {
        "type": "object",
        "properties": {
          "Code": {
            "type": "integer"
          },
          "Reason": {
            "type": "string"
          },
          "UserMessage": {
            "type": "string"
          }
        },
        "additionalProperties": false,
        "required": [
          "Code",
          "Reason",
          "UserMessage"
        ]
      },
      "Timestamp": {
        "type": "string"
      }
    },
    "additionalProperties": false,
    "required": [
      "RequestArguments",
      "Status",
      "Timestamp"
    ]
  }
  </code></pre>
  
  <p>Now what i want with this 2 Files is, to load File 1 - ValidResponse as a schema and at the "$ref..." it should load File 2 - CommonHeader and therefore creating 1 big json schema, while being able to still manipulate the files on its own, not having to worry about breaking the whole code.</p>
  
  <p>I am already using the Newtonsoft Nugget Package and can validate json schemas, but the referencing part just dont want to work</p>
  
  <pre><code>_jsonValidResponse = File.ReadAllText(_baseUri + @"\ObjectStructureOfValidResponse.json");
  _jsonString = File.ReadAllText(_baseUri+@"\jsonstring.json");
  JObject jsonString = JObject.Parse(_jsonString);
  JSchema jsonSchemaValidResponse = JSchema.Parse(_jsonValidResponse);
  jsonString.IsValid(jsonschemaValidResponse)
  </code></pre>
  
  <p>Whats the "magic" here to get this references to load during runtime?</p>