JSON FHIR schema validation with Newtonsoft.Json.Schema

Hi,

I am trying to use Newtonsoft.Json.Schema to validate FHIR resource, but it seems that it does not like the references in the schema, i.e., “$ref”, even it is a internal reference.

For example, Element schema:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "id": "http://hl7.org/fhir/json-schema/Element",
  "$ref": "#/definitions/Element",
  "description": "see http://hl7.org/fhir/json.html#schema for information about the FHIR Json Schemas",
  "definitions": {
    "Element": {
      "allOf": [
        {
          "description": "Base definition for all elements in a resource.",
          "properties": {
            "id": {
              "description": "unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.",
              "type": "string"
            },
            "_id": {
              "description": "Extensions for id",
              "$ref": "Element.schema.json#/definitions/Element"
            },
            "extension": {
              "description": "May be used to represent additional information that is not part of the basic definition of the element. In order to make the use of extensions safe and manageable, there is a strict set of governance  applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.",
              "type": "array",
              "items": {
                "$ref": "Extension.schema.json#/definitions/Extension"
              }
            }
          }
        }
      ]
    }
  }
}

If I change “$schema” to use draft 3 instead, it seems OK for the validator, something are incompatible with draft 4 in the schema, following is the comment from Jame NK (author of Newtonsoft.Json.Schema):

(https://github.com/JamesNK/Newtonsoft.Json.Schema/issues/119):
It is because in draft4 id will create a new id container scope in JSON Schema. That id container scope is preventing the $ref path from being resolved.

What should I do then?