private static IJsonSchema _FromJson(JsonValue json, SchemaFactory schemaFactory, Uri documentPath = null) { if (json == null) { return(null); } IJsonSchema schema = null; switch (json.Type) { case JsonValueType.Object: var schemaDeclaration = json.Object.TryGetString("$schema"); var factory = _schemaFactories.FirstOrDefault(f => f.Id == schemaDeclaration); if (factory != null) { var id = json.Object.TryGetString(factory.IdKey); if (id == factory.MetaSchema.Id) { return(factory.MetaSchema); } schema = factory.Factory(); } schema = schema ?? schemaFactory.Factory(); if (json.Object.ContainsKey("$ref")) { schema = json.Object.Count > 1 ? new JsonSchemaReference(schema.GetType()) { Base = schema } } : new JsonSchemaReference(schema.GetType()); break; case JsonValueType.Array: schema = new JsonSchemaCollection(); break; case JsonValueType.Boolean: // not determining draft here is fine // True is intended to pass all instances // False is intended to fail all instances schema = new JsonSchema06(); break; default: throw new SchemaLoadException($"JSON Schema must be objects; actual type: {json.Type}"); } schema.DocumentPath = documentPath; schema.FromJson(json, null); return(schema); }