From 286e26c4ed516d9e3d5a5f71b8b38a9f204714e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Wed, 12 Sep 2018 15:09:10 +0100 Subject: [PATCH] openapi 3.0 defines date-time format to be rfc3339 --- openapi_core/schema/schemas/util.py | 4 +++- requirements.txt | 1 + requirements_2.7.txt | 1 + setup.py | 1 + tests/unit/schema/test_schemas.py | 4 ++-- 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/openapi_core/schema/schemas/util.py b/openapi_core/schema/schemas/util.py index ce3b977..7acb9b0 100644 --- a/openapi_core/schema/schemas/util.py +++ b/openapi_core/schema/schemas/util.py @@ -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) diff --git a/requirements.txt b/requirements.txt index f13ec83..d4b732b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ openapi-spec-validator six lazy-object-proxy +strict_rfc3339 diff --git a/requirements_2.7.txt b/requirements_2.7.txt index 19ba7bb..bd9236f 100644 --- a/requirements_2.7.txt +++ b/requirements_2.7.txt @@ -4,3 +4,4 @@ lazy-object-proxy backports.functools-lru-cache backports.functools-partialmethod enum34 +strict_rfc3339 diff --git a/setup.py b/setup.py index 483c4f9..42ea7dc 100644 --- a/setup.py +++ b/setup.py @@ -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 diff --git a/tests/unit/schema/test_schemas.py b/tests/unit/schema/test_schemas.py index eb489e1..fb9675e 100644 --- a/tests/unit/schema/test_schemas.py +++ b/tests/unit/schema/test_schemas.py @@ -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):