minProperties constraint ignored when using definitions/references in JSON schema
See original GitHub issueI have a JSON schema that defines a type language_object
with some properties and then uses that on one of the fields, along with a minProperties
constraint.
However, when validating against this schema, submitting an empty object in said field does not raise a ValidationException
. It appears that the minProperties
constraint is ignored when it is placed alongside $ref
I have prepared a schema that defines my field once as name
using references and once as nameEx
with explicit properties. As far as I can tell these should be equivalent:
{
"type":"object",
"$schema":"http://json-schema.org/draft-04/schema#",
"definitions":{
"language_object":{
"type":"object",
"additionalProperties":false,
"patternProperties":{
"^[a-z]{2}$":{
"type":"string"
}
}
}
},
"properties":{
"name":{
"$ref":"#/definitions/language_object",
"minProperties":1
},
"nameEx":{
"type":"object",
"patternProperties":{
"^[a-z]{2}$":{
"type":"string"
}
},
"additionalProperties":false,
"minProperties":1
},
"date":{
"type":"string",
"format":"date-time"
}
}
}
When I validate the following JSON
{
"name":{},
"nameEx":{}
}
I only get #/nameEx: minimum size: [1], found: [0]
, not both. Other situations, like this disallowed key/property work fine on both:
{
"name":{"nbb":"bla"},
"nameEx":{"nbb":"bla"}
}
Returns
#: 2 schema violations found
#/nameEx: extraneous key [nbb] is not permitted
#/name: extraneous key [nbb] is not permitted
Thank you for your patience!
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
object — Understanding JSON Schema 2020-12 documentation
Any property that doesn't match any of the property names in the properties keyword is ignored by this keyword. Note. See Additional Properties...
Read more >Apply addtional constraints to a refered definition in JSON ...
Is there any way I can apply the constraint directly without copy&paste the content of the validType ? Schema: { "type": "object", "definition": ......
Read more >JSON Schema vs. OpenAPI - codeburst
The number of properties on an object can be restricted using the minProperties and maxProperties keywords. Each of these must be a non-negative ......
Read more >Min Properties - Liquid Technologies
If the schema is not allowed to contain an object the constraint is ignored, and not shown in the property grid. The constraint...
Read more >Object type | Opis JSON Schema
objects representing valid json schemas, and the whole object must match the entire schema. * Starting with draft 2019-09 you should use dependentSchemas...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks, I followed the discussions in the comments. You are awesome.
@Antares42 version 1.2.0 is available on maven central with the bugfix (also with “format” support)