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
Changes from 1 commit
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
13 changes: 11 additions & 2 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 @@ -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":

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one needs to be fixed as well, because I'll not work with falcon==3.0, neither.

Suggested change
if method_handler.__dict__.get("__module__") == "falcon.responders":
if method_handler.__module__ == "falcon.responders":

Copy link

@Javlopez Javlopez Dec 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @aslantar I'm using this awesome plugin, but I really would like to use it with falcon3, can I send these changes again in another PR - branch?, I've tested and seems it is working fine with falcon3, what do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @aslantar, I've been busy lately so I missed your review.
Thanks @Javlopez, please help me fix this problem, I don't have enough time to continue to maintain this PR

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Javlopez, sure. I'd love to see the changes integrated.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @aslantar the PR is here #34 please take a look

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Javlopez why do you need a separate PR with the same changes, instead of assisting @vuonglv1612 to get this one done?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello, sorry I didn't see this before, well just I found a way to send eveything in one PR, but you are right I can send my changes to @vuonglv1612 repo, for me is ok, I gonna send them today later

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @aslantar I've opened a PR for in the fork vuonglv1612#1 just with the missing changes, @vuonglv1612 can you take a look please?

Best Regards

continue
if method_name.lower() not in valid_methods:
continue
mapping[resource]["methods"][method_name.lower()] = method_handler

routes_to_check.extend(route.children)
Expand Down