From e8f25d6f0c11546e10979979cf99e28c2e5a308a Mon Sep 17 00:00:00 2001 From: ochafik Date: Sun, 10 Mar 2024 16:50:06 +0000 Subject: [PATCH] json: handle uuid string format --- examples/json-schema-to-grammar.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/json-schema-to-grammar.py b/examples/json-schema-to-grammar.py index 78356ef9b..33ab3ad9b 100755 --- a/examples/json-schema-to-grammar.py +++ b/examples/json-schema-to-grammar.py @@ -298,6 +298,9 @@ class SchemaConverter: elif schema_type in (None, 'string') and 'pattern' in schema: return self._visit_pattern(schema['pattern'], rule_name) + elif schema_type in (None, 'string') and re.match(r'^uuid[1-5]?$', schema.get('format', '')): + return self._visit_pattern('^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$', 'uuid') + elif schema_type == 'object' and len(schema) == 1 or schema_type is None and len(schema) == 0: # This depends on all primitive types for t, r in PRIMITIVE_RULES.items():