From e81e569328e454baba03355df473182d73b88428 Mon Sep 17 00:00:00 2001 From: Le Van Vuong Date: Sun, 13 Jun 2021 12:46:19 +0700 Subject: [PATCH 1/3] Fixed invalid methods error in falcon 3 --- falcon_apispec/falcon_plugin.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/falcon_apispec/falcon_plugin.py b/falcon_apispec/falcon_plugin.py index 9583a93..91ae954 100644 --- a/falcon_apispec/falcon_plugin.py +++ b/falcon_apispec/falcon_plugin.py @@ -2,6 +2,7 @@ import re from apispec import BasePlugin, yaml_utils from apispec.exceptions import APISpecError +from apispec.core import VALID_METHODS class FalconPlugin(BasePlugin): @@ -11,8 +12,14 @@ def __init__(self, app): super(FalconPlugin, self).__init__() self._app = app - @staticmethod - def _generate_resource_uri_mapping(app): + def init_spec(self, spec): + self._spec = spec + + def _get_valid_methods(self): + return set(VALID_METHODS[self._spec.openapi_version.major]) + + def _generate_resource_uri_mapping(self, app): + valid_methods = self._get_valid_methods() routes_to_check = copy.copy(app._router._roots) mapping = {} @@ -28,6 +35,8 @@ def _generate_resource_uri_mapping(app): for method_name, method_handler in route.method_map.items(): if method_handler.__dict__.get("__module__") == "falcon.responders": continue + if method_name.lower() not in valid_methods: + continue mapping[resource]["methods"][method_name.lower()] = method_handler routes_to_check.extend(route.children) From e45d1bc169c3ce20119d3294373f8c18e7860941 Mon Sep 17 00:00:00 2001 From: Javier Date: Thu, 30 Dec 2021 12:46:31 -0600 Subject: [PATCH 2/3] Apply changes to support falcon3 --- falcon_apispec/falcon_plugin.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/falcon_apispec/falcon_plugin.py b/falcon_apispec/falcon_plugin.py index 9583a93..3511680 100644 --- a/falcon_apispec/falcon_plugin.py +++ b/falcon_apispec/falcon_plugin.py @@ -2,7 +2,7 @@ import re from apispec import BasePlugin, yaml_utils from apispec.exceptions import APISpecError - +from apispec.core import VALID_METHODS class FalconPlugin(BasePlugin): """APISpec plugin for Falcon""" @@ -11,8 +11,14 @@ def __init__(self, app): super(FalconPlugin, self).__init__() self._app = app - @staticmethod - def _generate_resource_uri_mapping(app): + def init_spec(self, spec): + self._spec = spec + + def _get_valid_methods(self): + return set(VALID_METHODS[self._spec.openapi_version.major]) + + def _generate_resource_uri_mapping(self, app): + valid_methods = self._get_valid_methods() routes_to_check = copy.copy(app._router._roots) mapping = {} @@ -26,7 +32,9 @@ def _generate_resource_uri_mapping(app): if route.method_map: for method_name, method_handler in route.method_map.items(): - if method_handler.__dict__.get("__module__") == "falcon.responders": + if method_handler.__module__ == "falcon.responders": + continue + if method_name.lower() not in valid_methods: continue mapping[resource]["methods"][method_name.lower()] = method_handler From 869998eedcb5802ae8fdc8ab2ce94a33faa13551 Mon Sep 17 00:00:00 2001 From: Javier Lopez Lopez Date: Thu, 30 Dec 2021 12:56:15 -0600 Subject: [PATCH 3/3] Update version.py --- falcon_apispec/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/falcon_apispec/version.py b/falcon_apispec/version.py index 6a9beea..3d26edf 100644 --- a/falcon_apispec/version.py +++ b/falcon_apispec/version.py @@ -1 +1 @@ -__version__ = "0.4.0" +__version__ = "0.4.1"