JsconSchema doesn`t validate required property inside anyOf
#325 opened on Feb 24, 2017
Repository metrics
- Stars
- (1,578 stars)
- PR merge metrics
- (Avg merge 39d 6h) (1 merged PR in 30d)
Description
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.