From 24568f99934d4cdfc5e2c2b6327c01e9ac1ad60f Mon Sep 17 00:00:00 2001 From: Ashley Sommer Date: Tue, 31 Aug 2021 11:40:35 +1000 Subject: [PATCH] Add compat for Sanic v21.6 release v0.6.1 --- package-lock.json | 2 +- package.json | 2 +- requirements/install.pip | 3 ++- sanic_restplus/__about__.py | 2 +- sanic_restplus/api.py | 16 ++++++++-------- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7e515a5b..e0f23fde 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "sanic_restplus", - "version": "0.6.0", + "version": "0.6.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 8229d067..f2f1e8a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sanic_restplus", - "version": "0.5.6", + "version": "0.6.1", "description": "Fully featured framework for fast, easy and documented API development with Sanic", "repository": "ashleysommer/sanic-restplus", "keywords": [ diff --git a/requirements/install.pip b/requirements/install.pip index 03374c3f..f0d88ff8 100644 --- a/requirements/install.pip +++ b/requirements/install.pip @@ -1,6 +1,7 @@ aniso8601>=0.82 jsonschema methodtools +setuptools>=40.8 sanic>=21.3.4,<22 sanic-jinja2>=0.10.0 -sanic-plugin-toolkit>=1.0.1 +sanic-plugin-toolkit>=1.1.0.post1 diff --git a/sanic_restplus/__about__.py b/sanic_restplus/__about__.py index 5363ad27..4ccbe7fd 100644 --- a/sanic_restplus/__about__.py +++ b/sanic_restplus/__about__.py @@ -1,4 +1,4 @@ # -*- coding: latin-1 -*- # -__version__ = '0.6.0' +__version__ = '0.6.1' __description__ = 'Fully featured framework for fast, easy and documented API development with Sanic' diff --git a/sanic_restplus/api.py b/sanic_restplus/api.py index 0bc9b39c..9cdcbbf3 100644 --- a/sanic_restplus/api.py +++ b/sanic_restplus/api.py @@ -14,7 +14,7 @@ from functools import wraps, partial, lru_cache, update_wrapper from types import MethodType - +from distutils.version import LooseVersion from jinja2 import PackageLoader from sanic_routing.exceptions import RouteExists #, url_hash from sanic.response import text, BaseHTTPResponse @@ -26,7 +26,7 @@ from sanic.handlers import ErrorHandler from sanic.exceptions import SanicException, InvalidUsage, NotFound from sanic import exceptions, Sanic, Blueprint -from sanic.models.futures import FutureRoute as FutureRouteActual +from sanic import __version__ as sanic_version from sanic.base import BaseSanic try: from sanic.compat import Header @@ -52,7 +52,8 @@ py_36 = (3, 6) async_req_version = py_36 - +SANIC_VERSION = LooseVersion(sanic_version) +SANIC_21_6_0 = LooseVersion("21.6.0") RE_RULES = re.compile('(<.*>)') # List headers that should never be handled by Flask-RESTPlus @@ -357,13 +358,13 @@ def _register_doc(self, api_renderer): route_kwargs.setdefault('stream', False) route_kwargs.setdefault('name', None) route_kwargs.setdefault('version', None) - if hasattr(FutureRouteActual, 'version_prefix'): - route_kwargs.setdefault('version_prefix', None) route_kwargs.setdefault('ignore_body', False) route_kwargs.setdefault('websocket', False) route_kwargs.setdefault('subprotocols', None) route_kwargs.setdefault('unquote', False) route_kwargs.setdefault('static', False) + if SANIC_21_6_0 <= SANIC_VERSION: + route_kwargs.setdefault('version_prefix', None) if self._add_specs and self._doc: doc_endpoint_name = '{}_doc'.format(str(self._uid)) @@ -445,14 +446,13 @@ def _register_view(self, resource, namespace, *urls, **kwargs): kwargs.setdefault('stream', False) kwargs.setdefault('name', None) kwargs.setdefault('version', None) - if hasattr(FutureRouteActual, 'version_prefix'): - kwargs.setdefault('version_prefix', None) - kwargs.setdefault('ignore_body', False) kwargs.setdefault('websocket', False) kwargs.setdefault('subprotocols', None) kwargs.setdefault('unquote', False) kwargs.setdefault('static', False) + if SANIC_21_6_0 <= SANIC_VERSION: + kwargs.setdefault('version_prefix', None) # Add the url to the application or blueprint r = FutureRoute(resource_func, rule, (), {'methods': methods, 'with_context': True, **kwargs}) realm._register_route_helper(r, realm, restplus, context, plugin_name, plugin_url_prefix)