Skip to content

Add support for uuid4 format #671

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

Closed
charlax opened this issue Mar 25, 2020 · 1 comment
Closed

Add support for uuid4 format #671

charlax opened this issue Mar 25, 2020 · 1 comment

Comments

@charlax
Copy link

charlax commented Mar 25, 2020

Hi there,

Would it make sense to add support for the uuid4 format (and the other uuid formats?)

I had to do the following to add it manually:

import re

from jsonschema import (
    validate as jsonschema_validate,
    draft7_format_checker,
)

RE_UUID4 = re.compile(
    "^[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}", re.I
)


@draft7_format_checker.checks(format="uuid4", raises=(ValueError,))
def validate_uuid4(value: str) -> bool:
    if not RE_UUID4.match(value):
        raise ValueError(f"'{value}' is not a valid uuid4")
    return True


jsonschema_validate(
    content, schema, format_checker=draft7_format_checker,
)
@Julian
Copy link
Member

Julian commented Mar 25, 2020

Hey!

In general jsonschema supports the formats specified by the spec (and not others) -- UUID(4) was added in draft2019-09, which #613 is tracking support for (though it's not sufficiently far along yet).

In the meanwhile what you have looks reasonable if you want to use it for an earlier draft.

@Julian Julian closed this as completed Mar 26, 2020
@Julian Julian added the Wontfix label Oct 3, 2020
Julian added a commit that referenced this issue May 30, 2023
b069ac352 Add tests for non-relative URI anchor referencing
7950d9e05 Merge pull request #674 from jmigual/feature/alah
e6a089ae9 Changed description about `main` branch
b3c074773 Add comment about live at head philosophy
ab4bd012f Merge pull request #671 from marksparkza/schemaloc-fragment
e7aba0972 Include fragment in schemaLocation

git-subtree-dir: json
git-subtree-split: b069ac352c3dc1fae71f6f177dafe97001c97920
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants