Skip to content

Commit

Permalink
OpenAPI: Refactor module to responder.ext.openapi
Browse files Browse the repository at this point in the history
It has been `responder.ext.schema` before.
  • Loading branch information
amotl committed Oct 27, 2024
1 parent db73ee1 commit 1c491e1
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 10 deletions.
12 changes: 5 additions & 7 deletions docs/source/tour.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,14 @@ 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]'

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 = {
Expand Down Expand Up @@ -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",
Expand All @@ -220,7 +218,7 @@ The new and recommended way::
)

The old way ::
The old way::

api = responder.API(
title="Web Service",
Expand Down
8 changes: 7 additions & 1 deletion responder/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions tests/test_responder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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/"
Expand Down

0 comments on commit 1c491e1

Please sign in to comment.