mirror of
https://github.com/correl/openapi-core.git
synced 2024-11-29 03:00:12 +00:00
a08b62035e
Before this change, if a UUID instance got received as value in the Schema, it was breaking the unmarshal because UUID instances can't be used as values to instantiate other UUIDs.
33 lines
698 B
Python
33 lines
698 B
Python
"""OpenAPI core schemas util module"""
|
|
import datetime
|
|
from distutils.util import strtobool
|
|
from json import dumps
|
|
from six import string_types
|
|
import strict_rfc3339
|
|
from uuid import UUID
|
|
|
|
|
|
def forcebool(val):
|
|
if isinstance(val, string_types):
|
|
val = strtobool(val)
|
|
|
|
return bool(val)
|
|
|
|
|
|
def dicthash(d):
|
|
return hash(dumps(d, sort_keys=True))
|
|
|
|
|
|
def format_date(value):
|
|
return datetime.datetime.strptime(value, '%Y-%m-%d').date()
|
|
|
|
|
|
def format_datetime(value):
|
|
timestamp = strict_rfc3339.rfc3339_to_timestamp(value)
|
|
return datetime.datetime.utcfromtimestamp(timestamp)
|
|
|
|
|
|
def format_uuid(value):
|
|
if isinstance(value, UUID):
|
|
return value
|
|
return UUID(value)
|