summaryrefslogtreecommitdiff
path: root/jsonschema
diff options
context:
space:
mode:
authorHarald Nezbeda <hn@nezhar.com>2021-06-24 19:03:25 +0200
committerHarald Nezbeda <hn@nezhar.com>2021-07-19 18:14:31 +0200
commit73ec5a45f21112d9d8233f6e374acc2163a18dbd (patch)
treea4c564fd3bbc0f7ea63768a72f15dadcb0ca9c6a /jsonschema
parent00614ccc4a8672bcdcdf87ea11687b1bb1e95278 (diff)
downloadjsonschema-73ec5a45f21112d9d8233f6e374acc2163a18dbd.tar.gz
Julian/jsonschema#782: Add validation for uuid format
Diffstat (limited to 'jsonschema')
-rw-r--r--jsonschema/_format.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/jsonschema/_format.py b/jsonschema/_format.py
index 49b6b71..f9825b0 100644
--- a/jsonschema/_format.py
+++ b/jsonschema/_format.py
@@ -1,3 +1,4 @@
+from uuid import UUID
import datetime
import ipaddress
import re
@@ -471,3 +472,15 @@ else:
if not isinstance(instance, str):
return True
return isoduration.parse_duration(instance)
+
+
+@_checks_drafts(
+ draft202012="uuid",
+ raises=ValueError,
+)
+def is_uuid(instance):
+ if not isinstance(instance, str):
+ return True
+ if "-" not in instance:
+ raise ValueError("Invalid UUID format")
+ return UUID(instance)