json-schema-validator icon indicating copy to clipboard operation
json-schema-validator copied to clipboard

unevaluatedProperties and unevaluatedItems keywords are not implemented

Open ssilverman opened this issue 5 years ago • 17 comments

According to my testing, it doesn't appear that unevaluatedProperties from 2019-09 is implemented. If I'm correct, are there plans to add support?

ssilverman avatar Mar 21 '20 22:03 ssilverman

@ssilverman You are correct that it is not implemented yet. We implemented most of the validators but there are still some pending. I am wondering if you could submit a PR for this validator. Thanks.

stevehu avatar Mar 21 '20 23:03 stevehu

Ah, I hadn't realized the 2019-09 support wasn't complete yet, that's why I filed this issue. I can't promise I have time at the moment, but I'm going to have a look at the code. Any implementation guidance for newcomers? Specifically, unevaluatedProperties needs to be evaluated after a few other properties are evaluated and collect info from them.

ssilverman avatar Mar 22 '20 20:03 ssilverman

@ssilverman The library is a flexible plugin structure. Here are some of the points that I can think of.

  • Create a new validator
  • Register the validator to the ValidatorTypeCode
  • There are two ways to carry the context information across multiple validators. ValidationContext or ThreadLocal. There are examples in the library about how these two options work.

Let me know when you encounter any specific questions. Thanks.

stevehu avatar Mar 22 '20 20:03 stevehu

I started here: https://github.com/ssilverman/json-schema-validator/commit/35a8889d03e9c8810bf1ace058dfe4be95793c53

Does this look correct so far? What is versionCode in ValidatorTypeCode for? I used 15 because that's what ADDITIONAL_PROPERTIES did.

I think I'll need some guidance when adding "peering into" the in-place applicators (allOf, anyOf, oneOf, and not; and also $ref (may or may not point to an applicator, but may point to a properties-related value)) because they'll need some recursion, terminating at schemas.

ssilverman avatar Mar 22 '20 22:03 ssilverman

You are on the right path. Here is the document talking about the version.

https://github.com/networknt/json-schema-validator/blob/master/doc/specversion.md

stevehu avatar Mar 22 '20 23:03 stevehu

I added the in-place applicator collection in the UnevaluatedProperties constructor, but I'm not 100% clear on how to go about adding $ref and in-place applicator results to validate.

See: https://github.com/ssilverman/json-schema-validator/commits/add-unevaluated-props

ssilverman avatar Mar 24 '20 20:03 ssilverman

@ssilverman To be honest, I am far behind as I am still learning the spec. I am wondering if this is already published or not. The only document I can find is this issue. Let me know if you have any official links for us to learn.

I looked at your code and it looks pretty complicated. I am wondering if you could create a document in the /doc folder to write down your implementation ideas. In this way, it might be easier for other developers to understand what you are trying to archive and help you if needed. Thanks.

stevehu avatar Mar 24 '20 21:03 stevehu

It's published in the 2019-09 draft (https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.9.3.2.4).

As for the complexity, I'm just following the existing code style for the other validators. "unevaluatedProperties" is similar to "additionalProperties", but it also has to look at any sibling "additionalProperties", "oneOf", "allOf", "anyOf", "not", and "ref" contents. How could I make it simpler? I don't yet know your code base that well.

ssilverman avatar Mar 24 '20 23:03 ssilverman

@ssilverman Thanks for the link. It is not very clear what needs to be done by reading for that paragraph :) My understanding is that we need to iterate all the siblings. Do we need to drill down to the siblings? Or we just need to evaluate it at the same level? I don't think there is a simpler way to do so. @prashanthjos has created a collector to collect useful info during the validation and it could iterate all validators. I am wondering if it could help. https://github.com/networknt/json-schema-validator/pull/268

stevehu avatar Mar 25 '20 02:03 stevehu

Since the new keyword unevaluatedItems (see https://json-schema.org/draft/2019-09/release-notes.html#applicator-vocabulary) is also not implemented, maybe take these together (and change the title of this issue to unevaluatedProperties and unevaluatedItems keywords not implemented)?

gjvoosten avatar Aug 17 '20 15:08 gjvoosten

@gjvoosten Good idea. I have changed the title to cover both keywords. Thanks.

stevehu avatar Aug 17 '20 16:08 stevehu

@ssilverman Just looking at your branch. Maybe it would be better to add an interface, something like:

public boolean wouldHandleProperty(JsonNode node, String propertyName);

Then the UnevaluatedPropertiesValidator could call the other validators with wouldHandleProperty() to figure out which properties have been handled?

Gaff avatar Oct 13 '20 15:10 Gaff

@Gaff I ended up writing my own validator :)

ssilverman avatar Oct 23 '20 03:10 ssilverman

@ssilverman I am assuming you add some dummy validators that doing nothing to map to these keywords.

stevehu avatar Oct 23 '20 12:10 stevehu

@stevehu do you mean in my validator?

ssilverman avatar Oct 23 '20 13:10 ssilverman

@ssilverman I am sorry. I thought this thread is talking about the warning messages for the un-implemented keywords. Please ignore my message above. Thanks.

stevehu avatar Oct 23 '20 14:10 stevehu

Any PR?

Johnlon avatar Jul 09 '21 16:07 Johnlon

Resolved in #716 and #749

fdutton avatar May 22 '23 12:05 fdutton