Skip to content
13 changes: 13 additions & 0 deletions scene_common/src/scene_common/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

import json
import uuid
from jsonschema import FormatChecker
from fastjsonschema import compile

Expand All @@ -17,6 +18,18 @@ def __init__(self, schema_path, is_multi_message=False):

def compileValidators(self):
checker = FormatChecker()

@checker.checks('uuid', raises=ValueError)
def checkUuid(instance):
"""Validate UUID format (accepts UUIDv1-v5)"""
if not isinstance(instance, str):
return False
try:
uuid.UUID(instance)
return True
except (ValueError, AttributeError):
return False

formats = {}
for key in checker.checkers:
formatType = checker.checkers[key][0]
Expand Down
Loading