jsonschema icon indicating copy to clipboard operation
jsonschema copied to clipboard

$ref is now permitted next to other keywords

Open douglasramiro opened this issue 5 years ago • 2 comments

Hi,

Given the following scenario:

var addressSchema = { "id": "/SimpleAddress", "type": "object", "properties": { "city": {"type": "string"}, "country": {"type": "string", "required": true} }, };

and

var schema = { "id": "/SimplePerson", "type": "object", "properties": { "name": { "type": "string", "required": true }, "address": { "$ref": "/SimpleAddress", "required": true } } };

v.validate({}, "/SimplePerson");

Validating an empty person, the property name is returned as required. However, the address property is not.

One detail, if you pass an empty address, the address required properties are returned.

Is this an expected behavior?

Regards

douglasramiro avatar Aug 29 '19 18:08 douglasramiro

I have a similar issue where when using "$ref", all other properties seem discarded.

I would expect a kind of merge such as this:

{ 
"id": "/Common/id",
"type": "string"
// ... other properties 
}

{ 
 "id": "/OtherSchema/WhereINeedARequiredId",
"$ref": "/Common/id",
"required": true // I would expect the API to merge this object with the "ID",
"additionalProperties": false
}

{
 "id": "/ASchema/WhereOptionalIdIsNeeded",
"$ref": "/Common/id"
}

Any thoughts on this ?

anthonyjlmorel avatar Dec 23 '19 09:12 anthonyjlmorel

This is a change in behavior in some of the recent updates of JSON Schema. It used to be the case that objects with $ref were not considered JSON Schemas, but were actually a feature defined in a different specification. This is no longer the case, and this should get fixed.

awwright avatar Dec 23 '19 12:12 awwright