Closed
Description
Hi, im struggling with a field that should either have a date or an empty string:
from jsonschema import validate
schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "array",
"items": {
"$ref": "#/definitions/MyElement"
},
"definitions": {
"MyElement": {
"type": "object",
"properties": {
"my_date": { "$ref": "#/definitions/MaybeDate" },
}
},
"MaybeDate": {
"title": "MaybeDate",
"oneOf": [{
"type": "string",
"format": "date"
}, {
"const": ""
}]
}
}
}
data = [{
"my_date": "2018-05-05",
}]
validate(data, schema)
data = [{
"my_date": "",
}]
validate(data, schema)
Both should be valid, but the empty-string causes
Traceback (most recent call last):
File "config/scratches/scratch_25.py", line 38, in <module>
validate(data, schema)
File "/venv/lib/python3.6/site-packages/jsonschema/validators.py", line 899, in validate
raise error
jsonschema.exceptions.ValidationError: '' is valid under each of {'const': ''}, {'type': 'string', 'format': 'date'}
Failed validating 'oneOf' in schema['items']['properties']['my_date']:
{'oneOf': [{'format': 'date', 'type': 'string'}, {'const': ''}],
'title': 'MaybeDate'}
On instance[0]['my_date']:
This does not happen on https://www.jsonschemavalidator.net/ nor using the nodejs module https://www.npmjs.com/package/jsonschema
Am i missing something?
Using v3.0.1
Metadata
Metadata
Assignees
Labels
No labels