Skip to content

Commit

Permalink
Compatibility with apispec 3.0 and drops support of <3.0. Closes #63
Browse files Browse the repository at this point in the history
  • Loading branch information
maximdanilchenko committed Sep 23, 2019
1 parent 6c0d081 commit 4e76b52
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions aiohttp_apispec/aiohttp_apispec.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

_AiohttpView = Callable[[web.Request], Awaitable[web.StreamResponse]]

VALID_RESPONSE_FIELDS = {"schema", "description", "headers", "examples"}
VALID_RESPONSE_FIELDS = {"description", "headers", "examples"}


class AiohttpApiSpec:
Expand Down Expand Up @@ -45,9 +45,11 @@ def __init__(
self.register(app, in_place)

def swagger_dict(self):
""" Returns swagger spec representation in JSON format """
return self.spec.to_dict()

def register(self, app: web.Application, in_place: bool = False):
""" Creates spec based on registered app routes and registers needed view """
if self._registered is True:
return None

Expand Down Expand Up @@ -119,7 +121,7 @@ def _update_paths(self, data: dict, method: str, url_path: str):
if method not in VALID_METHODS_OPENAPI_V2:
return None
if "schema" in data:
parameters = self.plugin.openapi.schema2parameters(
parameters = self.plugin.converter.schema2parameters(
data.pop("schema"), **data.pop("options")
)
data["parameters"].extend(parameters)
Expand All @@ -135,15 +137,15 @@ def _update_paths(self, data: dict, method: str, url_path: str):
responses = {}
for code, params in data["responses"].items():
if "schema" in params:
raw_parameters = self.plugin.openapi.schema2parameters(
raw_parameters = self.plugin.converter.schema2parameters(
params["schema"], required=params.get("required", False)
)[0]
# https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#responseObject
parameters = {
k: v
for k, v in raw_parameters.items()
if k in VALID_RESPONSE_FIELDS
}
parameters['schema'] = params["schema"]
for extra_info in ("description", "headers", "examples"):
if extra_info in params:
parameters[extra_info] = params[extra_info]
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
aiohttp>=3.0.1
apispec>=1.0.0
apispec>=3.0.0
webargs
jinja2
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def read(file_name):

setup(
name='aiohttp-apispec',
version='1.4.0',
version='1.5.0',
description='Build and document REST APIs with aiohttp and apispec',
long_description=read('README.md'),
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 4e76b52

Please sign in to comment.