How to use Rule.defaults attribute?
- Dominant language
- Python
- Stars
- 652
- Forks
- 151
- PR merge metrics
- No merged PRs in 30d
Description
`argument_to_param` deals with the `defaults` attribute of the `Rule` object: https://github.com/jmcarp/flask-apispec/blob/master/flask_apispec/paths.py#L43.
```python
if rule.defaults and argument in rule.defaults:
param['default'] = rule.defaults[argument]
```
What's a real-life use case for this?
Here's what [the docs](http://werkzeug.pocoo.org/docs/0.14/routing/#werkzeug.routing.Rule) say about this `defaults` attribute:
> An optional dict with defaults for other rules with the same endpoint. This is a bit tricky but useful if you want to have unique URLs:
>
> ```python
> url_map = Map([
> Rule('/all/', defaults={'page': 1}, endpoint='all_entries'),
> Rule('/all/page/', endpoint='all_entries')
> ])
> ```
However, multiple rule for same endpoint is explicitly unsupported by apispec:
https://github.com/marshmallow-code/apispec/blob/dev/apispec/ext/flask.py#L91
> ```python
> # WARNING: Assume 1 rule per view function for now
> rule = current_app.url_map._rules_by_endpoint[endpoint][0]
> return rule
> ```
(Also see https://github.com/marshmallow-code/apispec/issues/181.)
Is there something I'm missing?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.