diff --git a/README.rst b/README.rst index 7cd3101..30aa179 100644 --- a/README.rst +++ b/README.rst @@ -86,7 +86,7 @@ Request object should implement BaseOpenAPIRequest interface. You can use FlaskO .. code-block:: python from openapi_core.shortcuts import RequestValidator - from openapi_core.wrappers.flask import FlaskOpenAPIRequest + from openapi_core.contrib.flask import FlaskOpenAPIRequest openapi_request = FlaskOpenAPIRequest(flask_request) validator = RequestValidator(spec) @@ -141,7 +141,7 @@ Response object should implement BaseOpenAPIResponse interface. You can use Flas .. code-block:: python from openapi_core.shortcuts import ResponseValidator - from openapi_core.wrappers.flask import FlaskOpenAPIResponse + from openapi_core.contrib.flask import FlaskOpenAPIResponse openapi_response = FlaskOpenAPIResponse(flask_response) validator = ResponseValidator(spec) diff --git a/openapi_core/contrib/__init__.py b/openapi_core/contrib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/openapi_core/contrib/flask/__init__.py b/openapi_core/contrib/flask/__init__.py new file mode 100644 index 0000000..1c332e5 --- /dev/null +++ b/openapi_core/contrib/flask/__init__.py @@ -0,0 +1,4 @@ +from openapi_core.contrib.flask.requests import FlaskOpenAPIRequest +from openapi_core.contrib.flask.responses import FlaskOpenAPIResponse + +__all__ = ['FlaskOpenAPIRequest', 'FlaskOpenAPIResponse'] diff --git a/openapi_core/wrappers/flask.py b/openapi_core/contrib/flask/requests.py similarity index 70% rename from openapi_core/wrappers/flask.py rename to openapi_core/contrib/flask/requests.py index 14c330b..e5d260b 100644 --- a/openapi_core/wrappers/flask.py +++ b/openapi_core/contrib/flask/requests.py @@ -1,7 +1,7 @@ -"""OpenAPI core wrappers module""" +"""OpenAPI core contrib flask requests module""" import re -from openapi_core.wrappers.base import BaseOpenAPIRequest, BaseOpenAPIResponse +from openapi_core.wrappers.base import BaseOpenAPIRequest # http://flask.pocoo.org/docs/1.0/quickstart/#variable-rules PATH_PARAMETER_PATTERN = r'<(?:(?:string|int|float|path|uuid):)?(\w+)>' @@ -49,21 +49,3 @@ class FlaskOpenAPIRequest(BaseOpenAPIRequest): @property def mimetype(self): return self.request.mimetype - - -class FlaskOpenAPIResponse(BaseOpenAPIResponse): - - def __init__(self, response): - self.response = response - - @property - def data(self): - return self.response.data - - @property - def status_code(self): - return self.response._status_code - - @property - def mimetype(self): - return self.response.mimetype diff --git a/openapi_core/contrib/flask/responses.py b/openapi_core/contrib/flask/responses.py new file mode 100644 index 0000000..c2922a1 --- /dev/null +++ b/openapi_core/contrib/flask/responses.py @@ -0,0 +1,22 @@ +"""OpenAPI core contrib flask responses module""" +import re + +from openapi_core.wrappers.base import BaseOpenAPIResponse + + +class FlaskOpenAPIResponse(BaseOpenAPIResponse): + + def __init__(self, response): + self.response = response + + @property + def data(self): + return self.response.data + + @property + def status_code(self): + return self.response._status_code + + @property + def mimetype(self): + return self.response.mimetype diff --git a/openapi_core/testing/__init__.py b/openapi_core/testing/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/openapi_core/wrappers/mock.py b/openapi_core/testing/mock.py similarity index 100% rename from openapi_core/wrappers/mock.py rename to openapi_core/testing/mock.py diff --git a/tests/integration/test_wrappers.py b/tests/integration/contrib/test_flask.py similarity index 97% rename from tests/integration/test_wrappers.py rename to tests/integration/contrib/test_flask.py index 6c4b7d1..15a9149 100644 --- a/tests/integration/test_wrappers.py +++ b/tests/integration/contrib/test_flask.py @@ -1,14 +1,15 @@ from flask.wrappers import Request, Response +import pytest from werkzeug.datastructures import EnvironHeaders, ImmutableMultiDict from werkzeug.routing import Map, Rule, Subdomain from werkzeug.test import create_environ -import pytest from openapi_core.shortcuts import create_spec from openapi_core.validation.response.validators import ResponseValidator from openapi_core.validation.request.validators import RequestValidator -from openapi_core.wrappers.flask import (FlaskOpenAPIRequest, - FlaskOpenAPIResponse) +from openapi_core.contrib.flask import ( + FlaskOpenAPIRequest, FlaskOpenAPIResponse, +) @pytest.fixture diff --git a/tests/integration/validation/test_minimal.py b/tests/integration/validation/test_minimal.py index 936c27b..5eb832c 100644 --- a/tests/integration/validation/test_minimal.py +++ b/tests/integration/validation/test_minimal.py @@ -3,8 +3,8 @@ import pytest from openapi_core.schema.operations.exceptions import InvalidOperation from openapi_core.schema.paths.exceptions import InvalidPath from openapi_core.shortcuts import create_spec +from openapi_core.testing.mock import MockRequest from openapi_core.validation.request.validators import RequestValidator -from openapi_core.wrappers.mock import MockRequest class TestMinimal(object): diff --git a/tests/integration/validation/test_petstore.py b/tests/integration/validation/test_petstore.py index b07f7f0..9e46a7a 100644 --- a/tests/integration/validation/test_petstore.py +++ b/tests/integration/validation/test_petstore.py @@ -16,10 +16,10 @@ from openapi_core.schema.schemas.enums import SchemaType from openapi_core.schema.schemas.exceptions import InvalidSchemaValue from openapi_core.schema.servers.exceptions import InvalidServer from openapi_core.shortcuts import create_spec +from openapi_core.testing.mock import MockRequest, MockResponse from openapi_core.validation.request.datatypes import RequestParameters from openapi_core.validation.request.validators import RequestValidator from openapi_core.validation.response.validators import ResponseValidator -from openapi_core.wrappers.mock import MockRequest, MockResponse class TestPetstore(object): diff --git a/tests/integration/validation/test_validators.py b/tests/integration/validation/test_validators.py index c696cf1..e323c13 100644 --- a/tests/integration/validation/test_validators.py +++ b/tests/integration/validation/test_validators.py @@ -17,10 +17,10 @@ from openapi_core.schema.responses.exceptions import ( ) from openapi_core.schema.servers.exceptions import InvalidServer from openapi_core.shortcuts import create_spec +from openapi_core.testing.mock import MockRequest, MockResponse from openapi_core.validation.request.datatypes import RequestParameters from openapi_core.validation.request.validators import RequestValidator from openapi_core.validation.response.validators import ResponseValidator -from openapi_core.wrappers.mock import MockRequest, MockResponse class TestRequestValidator(object):