openapi 3.0 defines date-time format to be rfc3339

This commit is contained in:
Domen Kožar 2018-09-12 15:09:10 +01:00
parent 032aecdd5f
commit 286e26c4ed
No known key found for this signature in database
GPG key ID: C2FFBCAFD2C24246
5 changed files with 8 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,3 +1,4 @@
openapi-spec-validator
six
lazy-object-proxy
strict_rfc3339

View file

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

View file

@ -44,6 +44,7 @@ class PyTest(TestCommand):
'--cov', 'openapi_core',
'--cov-report', 'term-missing',
'--cov-report', 'xml:reports/coverage.xml',
'tests',
]
self.test_suite = True

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):