Skip to content

Commit f57df76

Browse files
decazsloria
authored andcommitted
Fix compatibility with apispec==3.0.0 (#164)
1 parent c6f6c8d commit f57df76

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

flask_apispec/apidoc.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import six
66

7+
import apispec
78
from apispec.core import VALID_METHODS
89
from apispec.ext.marshmallow import MarshmallowPlugin
910

@@ -13,6 +14,10 @@
1314
from flask_apispec.paths import rule_to_path, rule_to_params
1415
from flask_apispec.utils import resolve_resource, resolve_annotations, merge_recursive
1516

17+
APISPEC_VERSION_INFO = tuple(
18+
[int(part) for part in apispec.__version__.split('.') if part.isdigit()]
19+
)
20+
1621
class Converter(object):
1722

1823
def __init__(self, app, spec):
@@ -67,7 +72,10 @@ def get_parent(self, view):
6772
return None
6873

6974
def get_parameters(self, rule, view, docs, parent=None):
70-
openapi = self.marshmallow_plugin.openapi
75+
if APISPEC_VERSION_INFO[0] < 3:
76+
openapi = self.marshmallow_plugin.openapi
77+
else:
78+
openapi = self.marshmallow_plugin.converter
7179
annotation = resolve_annotations(view, 'args', parent)
7280
extra_params = []
7381
for args in annotation.options:

tests/test_openapi.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from flask_apispec.paths import rule_to_params
1010
from flask_apispec.views import MethodResource
1111
from flask_apispec import doc, use_kwargs, marshal_with
12-
from flask_apispec.apidoc import ViewConverter, ResourceConverter
12+
from flask_apispec.apidoc import APISPEC_VERSION_INFO, ViewConverter, ResourceConverter
1313

1414
@pytest.fixture()
1515
def marshmallow_plugin():
@@ -26,7 +26,10 @@ def spec(marshmallow_plugin):
2626

2727
@pytest.fixture()
2828
def openapi(marshmallow_plugin):
29-
return marshmallow_plugin.openapi
29+
if APISPEC_VERSION_INFO[0] < 3:
30+
return marshmallow_plugin.openapi
31+
else:
32+
return marshmallow_plugin.converter
3033

3134
def ref_path(spec):
3235
if spec.openapi_version.version[0] < 3:

0 commit comments

Comments
 (0)