-
-
Notifications
You must be signed in to change notification settings - Fork 603
Description
This issue is a follow up on issue 698.
The feature request, describes how to enhance the best_match function in order to prioritize the type of the rule with the type of the instance. Example : if an array is presented in an instance, array related rules should be prioritized against other type of rules.
As shown in the following example, this currently isn't reliable :
The rule :
{
"properties" : {
"value" : {
"anyOf" : [
{"type" : "number","maximum":0},
{"type" : "array", "items" : {"type":"number", "minimum" : 0}},
{"type":"string", "const" : "check"}
]
}
}
}
With :
{"value" : 2}
Expected result (OK) :
2 is greater than the maximum of 0
Failed validating 'maximum' in schema[0]:
{'maximum': 0, 'type': 'number'}
Current result :
2 is greater than the maximum of 0
Failed validating 'maximum' in schema[0]:
{'maximum': 0, 'type': 'number'}
With :
{"value" : [-3]}
Expected result (OK) :
-3 is less than the minimum of 0
Failed validating 'minimum' in schema[1]['items']:
{'minimum': 0, 'type': 'number'}
Current result
-3 is less than the minimum of 0
Failed validating 'minimum' in schema[1]['items']:
{'minimum': 0, 'type': 'number'}
With :
{"value": "something"}
Expected result (NOK) :
'check' was expected
Failed validating 'const' in schema[0]:
{'const': 'check', 'type': 'string'}
Current result :
'something' is not of type 'number'
Failed validating 'type' in schema[0]:
{'maximum': 0, 'type': 'number'}
On the implementation of such feature, I believe if we were to add a field on _Error to capture if the rule is of the same_type as the instance, and then changing the return function of by_relevance by adding the error.same_type on the tuple being returned, would solve that issue.
I just had a look on how to do it, there are probably better ways of doing this, I am not familiar with the code base.