jmcarp / jmcarp/flask-apispec

Registering Functions from Blueprints

Open
#156 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
652
Forks
151
PR merge metrics
No merged PRs in 30d

Description

Forgive me if I'm not understanding something, I'm not too familiar with Flask–

I'm working on a large Flask API that I'd like to document using `flask-apispec`. To organize the different sections of the API, we use Flask's Blueprint mechanism and pull all of these into a single `app` in a main file.

It seems that in your documentation you need to call `docs.register(view_function)` on every `view_function` defined in your app; which in our case would require a disastrous amount of imports and would be really painful to maintain. I came up with the following bit of code:

```python
for (fpath, view_function) in app.view_functions.items():
blueprint_name = fpath.split('.')[0]
# only bound methods have a __self__ attribute, so we can check whether
# a view_function is a defined route or something included from a package
# or from Flask by using hasattr.
if not hasattr(view_function, '__self__'):
docs.register(view_function, blueprint=blueprint_name)
```

Is this good practice, or is there a better way to do this within `flask-apispec`?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the flask-apispec registration documentation and the Flask app.view_functions behavior described in the issue. Determine whether blueprint routes can be registered without importing each view, and define the supported approach and its completion criteria; the issue does not name a target file or test.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python
Domain
api, backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.