Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed invalid methods error in falcon 3 #32

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions falcon_apispec/falcon_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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 = {}
Expand All @@ -26,7 +33,11 @@ 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
if method_name.lower() not in valid_methods:
continue
mapping[resource]["methods"][method_name.lower()] = method_handler

Expand Down
2 changes: 1 addition & 1 deletion falcon_apispec/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.4.0"
__version__ = "0.4.1"