Skip to content
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

add DEFAULT_FORMATS['uuid'] in formatter.py #374

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions bravado_core/formatter.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import pytz
import six
import typing
import uuid

from bravado_core import schema
from bravado_core.exception import SwaggerMappingError
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think JSONSchema does validate UUID, does it?
I'm also hesitant to add a default format to bravado-core that is not defined in the OpenAPI specification. If we do add it, could you please mention it in the documentation as well?

description='Converts [wire]string:uuid <=> python uuid.UUID',
)
}