Merge pull request #99 from domenkozar/date-time-rfc3339

openapi 3.0 defines date-time format to be rfc3339
This commit is contained in:
A 2018-09-13 20:58:14 +01:00 committed by GitHub
commit 78cf590ec8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 3 deletions

View file

@ -3,6 +3,7 @@ import datetime
from distutils.util import strtobool
from json import dumps
from six import string_types
import strict_rfc3339
def forcebool(val):
@ -21,4 +22,5 @@ def format_date(value):
def format_datetime(value):
return datetime.datetime.strptime(value, '%Y-%m-%dT%H:%M:%S')
timestamp = strict_rfc3339.rfc3339_to_timestamp(value)
return datetime.datetime.fromtimestamp(timestamp)

View file

@ -1,4 +1,5 @@
openapi-spec-validator
six
lazy-object-proxy
strict_rfc3339
attrs

View file

@ -4,4 +4,5 @@ lazy-object-proxy
backports.functools-lru-cache
backports.functools-partialmethod
enum34
strict_rfc3339
attrs

View file

@ -81,11 +81,11 @@ class TestSchemaUnmarshal(object):
def test_string_format_datetime(self):
schema = Schema('string', schema_format='date-time')
value = '2018-01-02T00:00:00'
value = '2018-01-02T00:00:00Z'
result = schema.unmarshal(value)
assert result == datetime.datetime(2018, 1, 2, 0, 0, 0)
assert result == datetime.datetime(2018, 1, 2, 0, 0)
@pytest.mark.xfail(reason="No custom formats support atm")
def test_string_format_custom(self):