RicoSuter/NJsonSchema

JsconSchema doesn`t validate required property inside anyOf

开放

#325 创建于 2017年2月24日

 (11 条评论) (0 个反应) (0 位负责人)C# (549 个派生)github user discovery
help wantedtype: bug

仓库指标

星标
 (1,581 个星标)
PR 合并指标
 (平均合并 39天 6小时) (30 天内合并 1 个 PR)

描述

I have this json schema which is being used in the code below. { "definitions": { "Test": { "id": "Jsonschemas/", "type": "object", "properties": { "url": { "type": "string" }, "canceledOnDate": { "type": "string" }, "address": { "$ref": "address.json#/definitions/address" }, "coordinates": { "$ref": "coordinates.json#/definitions/coordinates" } }, "additionalProperties": false, "required": ["canceledOnDate" ], "anyOf": [ { "required": [ "address" ] }, { "required": [ "coordinates" ] } ] } } }

I have this C# code which is using JsonSchema4.

JsonSchema4 schema = new JsonSchema4();
schema = await JsonSchema4.FromFileAsync(Path.Combine(HttpContext.Current.Server.MapPath("~"), @"JsonSchema/Test.json")); schema.Validate(actualJsonData);

I am expecting that based on the schema if I dont provide either address or cocrdinates, the Validate method should return me error. But it doesn`t validate the required field in anyOf at all. The validation always passes even if address and coordinates both are not provided.

Is it not supported with JsonSchema4? I am looking for help to fix this problem or a work around to fix this issue.

贡献者指南