diff --git a/docs/source/tour.rst b/docs/source/tour.rst index 792ac927..e629efe4 100644 --- a/docs/source/tour.rst +++ b/docs/source/tour.rst @@ -61,7 +61,6 @@ You can make use of Responder's Request and Response objects in your GraphQL res OpenAPI Schema Support ---------------------- - Responder comes with built-in support for OpenAPI / marshmallow:: pip install 'responder[openapi]' @@ -69,7 +68,7 @@ Responder comes with built-in support for OpenAPI / marshmallow:: New in Responder `1.4.0`:: import responder - from responder.ext.schema import Schema as OpenAPISchema + from responder.ext.openapi import OpenAPISchema from marshmallow import Schema, fields contact = { @@ -200,12 +199,11 @@ Responder can automatically supply API Documentation for you. Using the example The new and recommended way:: - ... - from responder.ext.schema import Schema - ... + from responder.ext.openapi import OpenAPISchema + api = responder.API() - schema = Schema( + schema = OpenAPISchema( app=api, title="Web Service", version="1.0", @@ -220,7 +218,7 @@ The new and recommended way:: ) -The old way :: +The old way:: api = responder.API( title="Web Service", diff --git a/responder/api.py b/responder/api.py index 51526fd4..1538a933 100644 --- a/responder/api.py +++ b/responder/api.py @@ -109,7 +109,13 @@ def __init__( self.add_middleware(SessionMiddleware, secret_key=self.secret_key) if openapi or docs_route: - from .ext.schema import OpenAPISchema + try: + from .ext.openapi import OpenAPISchema + except ImportError as ex: + raise ImportError( + "Dependencies for OpenAPI extension not found. " + "Install them using: pip install 'responder[openapi]'" + ) from ex self.openapi = OpenAPISchema( app=self, diff --git a/responder/ext/schema/__init__.py b/responder/ext/openapi/__init__.py similarity index 100% rename from responder/ext/schema/__init__.py rename to responder/ext/openapi/__init__.py diff --git a/responder/ext/schema/docs/elements.html b/responder/ext/openapi/docs/elements.html similarity index 100% rename from responder/ext/schema/docs/elements.html rename to responder/ext/openapi/docs/elements.html diff --git a/responder/ext/schema/docs/rapidoc.html b/responder/ext/openapi/docs/rapidoc.html similarity index 100% rename from responder/ext/schema/docs/rapidoc.html rename to responder/ext/openapi/docs/rapidoc.html diff --git a/responder/ext/schema/docs/redoc.html b/responder/ext/openapi/docs/redoc.html similarity index 100% rename from responder/ext/schema/docs/redoc.html rename to responder/ext/openapi/docs/redoc.html diff --git a/responder/ext/schema/docs/swagger_ui.html b/responder/ext/openapi/docs/swagger_ui.html similarity index 100% rename from responder/ext/schema/docs/swagger_ui.html rename to responder/ext/openapi/docs/swagger_ui.html diff --git a/tests/test_responder.py b/tests/test_responder.py index 730a9f9c..0ce99319 100644 --- a/tests/test_responder.py +++ b/tests/test_responder.py @@ -326,7 +326,7 @@ def test_schema_generation_explicit(needs_openapi): import marshmallow import responder - from responder.ext.schema import OpenAPISchema + from responder.ext.openapi import OpenAPISchema api = responder.API() @@ -393,7 +393,7 @@ def test_documentation_explicit(needs_openapi): import marshmallow import responder - from responder.ext.schema import OpenAPISchema + from responder.ext.openapi import OpenAPISchema description = "This is a sample server for a pet store." terms_of_service = "http://example.com/terms/"