Skip to content

Commit

Permalink
Pass view args to view function as positional arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
greyli committed Feb 13, 2021
1 parent 982f024 commit 15c66f3
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions apiflask/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys

from flask import Flask
from flask.globals import _request_ctx_stack
from apispec import APISpec
from apispec.ext.marshmallow import MarshmallowPlugin
from flask import Blueprint, render_template
Expand Down Expand Up @@ -72,6 +73,24 @@ def http_error(error):
return self.error_handler_callback(error.status_code,
error.messages)

def dispatch_request(self):
"""Overwrite the default dispatch method to pass view arguments as positional
arguments.
"""
req = _request_ctx_stack.top.request
if req.routing_exception is not None:
self.raise_routing_exception(req)
rule = req.url_rule
# if we provide automatic options for this URL and the
# request came with the OPTIONS method, reply automatically
if (
getattr(rule, "provide_automatic_options", False)
and req.method == "OPTIONS"
):
return self.make_default_options_response()
# otherwise dispatch to the handler for that endpoint
return self.view_functions[rule.endpoint](*req.view_args.values())

@property
def title(self):
return self.config['OPENAPI_TITLE']
Expand Down

0 comments on commit 15c66f3

Please sign in to comment.