Skip to content
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

Closed
kripanshu opened this issue Sep 14, 2020 · 7 comments
Closed

The uuid format is not supported ? #737

kripanshu opened this issue Sep 14, 2020 · 7 comments
Labels
Invalid Not a bug, PEBKAC, or an unsupported setup

Comments

@kripanshu
Copy link

kripanshu commented Sep 14, 2020

I am trying to validate uuid(v4) in the instance I provide. But it is not able to validate it properly. For example,

from jsonschema import validate, draft7_format_checker
schema = {
 "type" : "object",
 "properties" : {
     "price" : {"type" : "number"},
     "id" : {"type" : "string", "format":"uuid", },
 },
}
try:
  validate(instance={"id" : "hello", "price" : 34.99}, schema=schema, format_checker=draft7_format_checker)
  print('valid')
except Exception as e:
  print('Error ----> ', e)

expected:

Error -----> : Not a valid UUID

Result:

valid

It should have thrown error. Am I missing something in implementation?

@Julian
Copy link
Member

Julian commented Sep 14, 2020

There is no uuid format in draft 7. (You certainly can add one though.)

@Julian Julian closed this as completed Sep 14, 2020
@Julian Julian added the Invalid Not a bug, PEBKAC, or an unsupported setup label Oct 3, 2020
@gricey432
Copy link

gricey432 commented Feb 26, 2021

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
Edit: My bad, it was added in the 2019-09 standard https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.7.3.5 so it'd be part of #613

@Bktero
Copy link

Bktero commented Mar 30, 2023

I see in code that the "uuid" format is supported:

def is_uuid(instance: object) -> bool:

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

@Julian
Copy link
Member

Julian commented Mar 30, 2023

That's correct behavior, as you haven't enabled format assertion behavior.

See the FAQ.

@Julian
Copy link
Member

Julian commented Mar 30, 2023 via email

@Bktero
Copy link

Bktero commented Mar 30, 2023

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!

@Julian
Copy link
Member

Julian commented Mar 30, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Invalid Not a bug, PEBKAC, or an unsupported setup
Projects
None yet
Development

No branches or pull requests

4 participants