json-schema-validator
json-schema-validator copied to clipboard
Please add support for minContains/maxContains of 2019-09 draft
The "contains" restriction was enhanced in 2019-09, please see https://json-schema.org/understanding-json-schema/reference/array.html#mincontains-maxcontains
I can try to add this support myself and prepare a PR but please point me in the right direction.
@sedovalx From the specification, I can see the minContains and maxContains are very similar to the minItems and maxItems in the array keyword.
https://github.com/networknt/json-schema-validator/blob/master/src/main/java/com/networknt/schema/MaxItemsValidator.java
We just need to create two new validators and wire them into the 2019-09 in https://github.com/networknt/json-schema-validator/blob/master/src/main/java/com/networknt/schema/ValidatorTypeCode.java
Let me know if you have any specific questions. Thanks a lot for the effort.
Do you have any news ? @sedovalx Did you manage to implement this?
No, got distracted as usual. Sorry :)
Hi 👋 I would be interested in the feature as well. Are you working on it actively? If so: Is there an estimate on when this might be included? Thank you for your effort!
This was resolved by PR #702
Hello, Thanks to you @fdutton for the fix. I encountered some strange behavior with it. I have tested the minContains with a very simple schema, but the error is a "contains" error and not a "minContains" error.
This is the sample schema :
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "schemas/samples/sample.mincontains.schema.json",
"properties": {
"myArray": {
"type": "array",
"minContains": 2,
"contains": {"properties": {"itemType": {"const": "type A"}}
},
"items": {"properties": {"itemType": {"type": "string"}}}
}
}
}
And this is the document to validate with this schema :
{
"$schema": "schemas/samples/sample.mincontains.schema.json",
"myArray": [{"itemType": "type A"}]
}
This is the com.networknt.schema.ValidationMessage I have as result:
| Attribute | Value |
|---|---|
| type | "contains" |
| code | "1043" |
| path | "$.myArray" |
| schemaPath | "#/properties/myArray/contains" |
| arguments | ["2", "{"properties":{..."] |
| details | null |
The ValidationMessage should have "minContains" as type value
I have tested the "normal" behavior on https://www.jsonschemavalidator.net/s/4KTe05B9