From 9f0de7913962c9ba7b826c5d1a4a3012d3cffd83 Mon Sep 17 00:00:00 2001 From: Mikhail Kedrovskiy Date: Thu, 5 Mar 2020 16:37:55 +0200 Subject: [PATCH] add DEFAULT_FORMATS['uuid'] in formatter.py --- bravado_core/formatter.py | 8 ++++++++ 1 file changed, 8 insertions(+) mode change 100644 => 100755 bravado_core/formatter.py diff --git a/bravado_core/formatter.py b/bravado_core/formatter.py old mode 100644 new mode 100755 index 0a79db87..4e38636d --- a/bravado_core/formatter.py +++ b/bravado_core/formatter.py @@ -12,6 +12,7 @@ import pytz import six import typing +import uuid from bravado_core import schema from bravado_core.exception import SwaggerMappingError @@ -200,4 +201,11 @@ def wrapper(validatable_primitive): validate=NO_OP, # jsonschema validates integer description='Converts [wire]integer:int64 <=> python long', ), + 'uuid': SwaggerFormat( + format='byte', + to_wire=lambda u: str(u) if isinstance(u, uuid.UUID) else u, + to_python=lambda s: s if isinstance(s, uuid.UUID) else uuid.UUID(s), + validate=NO_OP, # jsonschema validates uuid + description='Converts [wire]string:uuid <=> python uuid.UUID', + ) }