-
-
Notifications
You must be signed in to change notification settings - Fork 582
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
The uuid
format is not supported ?
#737
Comments
There is no |
Just updating this ticket (since it comes up in search), uuid is now a format in 2020-12 https://json-schema.org/draft/2020-12/json-schema-validation.html#rfc.section.7.3.5 so this issue should be resolved by #782 |
I see in code that the "uuid" format is supported: jsonschema/jsonschema/_format.py Line 518 in 10fab77
Is this bug related to this code? A small test on my side shows that UUID doesn't work. The following code doesn't raise any exception: import jsonschema
schema = {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"id": {
"type": "string",
"format": "uuid"
}
}
}
jsonschema.validate({"id": "7CBD0EE5-EC30-47CE-B8B2-2DC3A363D04D"}, schema)
jsonschema.validate({"id": "7CBD0EE5-EC30-47CE-B8B2-2DC3A363D04"}, schema) # should fail
jsonschema.validate({"id": "random text"}, schema) # should fail |
That's correct behavior, as you haven't enabled format assertion behavior. See the FAQ. |
Not sure what you mean I'm afraid, that works just fine:
```
⊙ python3.11 -m venv venv; venv/bin/python -m pip install --quiet
jsonschema'[format]==4.17.3' && venv/bin/python -c 'from jsonschema import
validate, Draft202012Validator; validate(instance="-12", schema={"format":
"uuid"}, format_checker=Draft202012Validator.FORMAT_CHECKER)'
[notice] A new release of pip available: 22.3.1 -> 23.0.1
[notice] To update, run: /Users/julian/Desktop/venv/bin/python -m pip
install --upgrade pip
Traceback (most recent call last):
File
"/Users/julian/Desktop/venv/lib/python3.11/site-packages/jsonschema/_format.py",
line 135, in check
result = func(instance)
^^^^^^^^^^^^^^
File
"/Users/julian/Desktop/venv/lib/python3.11/site-packages/jsonschema/_format.py",
line 517, in is_uuid
UUID(instance)
File ***@***.***/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/uuid.py",
line 178, in __init__
raise ValueError('badly formed hexadecimal UUID string')
ValueError: badly formed hexadecimal UUID string
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File
"/Users/julian/Desktop/venv/lib/python3.11/site-packages/jsonschema/validators.py",
line 1121, in validate
raise error
jsonschema.exceptions.ValidationError: '-12' is not a 'uuid'
Failed validating 'format' in schema:
{'format': 'uuid'}
On instance:
'-12'
```
…On Thu, Mar 30, 2023 at 12:39 PM Bktero ***@***.***> wrote:
My bad!
I have followed the link, installed jsonschema[format]==4.17.3. Still,
the following code doesn't raise:
from jsonschema import validate, Draft202012Validator
validate(
instance="-12",
schema={"format": "ipv4"},
format_checker=Draft202012Validator.FORMAT_CHECKER,
)
validate(
instance="-12",
schema={"type": "string", "format": "uuid"},
format_checker=Draft202012Validator.FORMAT_CHECKER,
)
The first code is from the FAQ.
Pycharm tells me "Unresolved attribute reference 'FORMAT_CHECKER' for
class 'Draft202012Validator'.
In the FAQ, there is a table for the dependencies for the various format.
"uuid" isn't it there, is this simply a documentation error?
—
Reply to this email directly, view it on GitHub
<#737 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACQQXUPVJQHL5THIBBKLZ3W6WZKNANCNFSM4RLYIIZQ>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
|
Sorry, I deleted a bad message but you were super fast to answer... It does work properly, my bad. Thanks a lot for the support! |
Np all good glad it works!
…On Thu, Mar 30, 2023 at 12:46 PM Bktero ***@***.***> wrote:
Sorry, I deleted a bad message but you were super fast to answer... It
does work properly, my bad. Thanks a lot for the support!
—
Reply to this email directly, view it on GitHub
<#737 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACQQXXC23A2HEUWS27QDODW6W2FTANCNFSM4RLYIIZQ>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
|
I am trying to validate
uuid
(v4) in the instance I provide. But it is not able to validate it properly. For example,expected:
Result:
It should have thrown error. Am I missing something in implementation?
The text was updated successfully, but these errors were encountered: