spec-tools
spec-tools copied to clipboard
s/pos? & s/neg? produce invalid schema
The following Spec
(s/def :my.namespace/sort (s/and number? pos?))
produces:
"sort": {
"allOf": [
{
"type": "number",
"format": "double"
},
{
"minimum": 0,
"exclusiveMinimum": true
}
]
}
Suspect: https://github.com/metosin/spec-tools/blob/b33fcea9f24920b15b47392d693089aa799c66ae/src/spec_tools/json_schema.cljc#L41-L43
This causes following errror in python/jsonschema validation on exclusiveMinimum
jsonschema.exceptions.SchemaError: True is not of type 'number'
Note that docs also suggest that both should not be specified: https://json-schema.org/understanding-json-schema/reference/numeric.html#range
Also note if the Spec is changed to:
(s/def :my.namespace/sort (s/and number? #(> % 0)))
The resulting schema works but omits the extra test by the anon fn. But understandably anon fn can't be represented. Perhaps this should cause a console warning so it doesn't go undetected.
Hi, the generated output is valid for JSON Schema Draft 04.
@miikka Hi, when I specify :json-schema/$schema "http://json-schema.org/draft-04/schema#"
it fails with the following but it wasn't immediately obvious which part of the schema it is complaining about.
Failed validating 'anyOf' in metaschema['properties']['properties']['additionalProperties']['properties']['additionalProperties']:
{'anyOf': [{'type': 'boolean'}, {'$ref': '#'}], 'default': {}}
As soon as I bump specify "...draft-05/schema#"
or later, the validation in python works. Might be a bug in the python implementation. When I get a chance I will try and get a minimal example and report back.