-
-
Notifications
You must be signed in to change notification settings - Fork 571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] oneOf and empty-string #585
Comments
You didn't pass in a format checker.
…On Wed, Jul 17, 2019, 08:35 Delf Tonder ***@***.***> wrote:
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
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#585>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AACQQXTNGLRR7N3KEUPRAJDP74GXPANCNFSM4IEP3TWQ>
.
|
Indeed, changing it to
solved it :) Thank you! |
Julian
added a commit
that referenced
this issue
Aug 17, 2022
14d05dcea Merge pull request #585 from json-schema-org/absolute-uri b643e11fa Tweak the remotes retrieval README language a bit more. 0c90a5f98 Explicitly mention the base URI for those not using jsonschema_remotes. 79daf05b6 Emit fully absolute URIs from `jsonschema_suite remotes`. git-subtree-dir: json git-subtree-split: 14d05dcea95edd138fca251b2a9cf99bd32426bf
Julian
added a commit
that referenced
this issue
Aug 17, 2022
4cfead7ba Fix #585 on Windows. git-subtree-dir: json git-subtree-split: 4cfead7ba7b1af840eaf95f19a088c89ed67b5a9
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, im struggling with a field that should either have a date or an empty string:
Both should be valid, but the empty-string causes
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
The text was updated successfully, but these errors were encountered: