jmcarp / jmcarp/flask-apispec

can't create app more than once

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

Description

hello and thanks for the great library! i'm giving it a shot while restful/restplus/restetc figure out how to integrate Marshmallow :-)

in running tests, i've noticed that tests fail immediately when the app is re-created. i've narrowed it down to failing just in the case:

```python3
app = create_app()
app = create_app()
```

the failing code is this:
```
def convert(self, target, endpoint=None, blueprint=None, **kwargs):
endpoint = endpoint or target.__name__.lower()
if blueprint:
endpoint = '{}.{}'.format(blueprint, endpoint)
> rules = self.app.url_map._rules_by_endpoint[endpoint]
E KeyError: 'AssetResource'
```

i see #56 , but I have removed the blueprints and still have this issue occur. instead of blueprints, i am following the example:

```python3
from .asset import AssetResource
app.add_url_rule('/asset/', AssetResource.as_view('AssetResource'))
docs.register(AssetResource, endpoint='AssetResource')
```

to bypass this issue, i added a try/catch block around the code manually in `apidoc.py`:

```python3
def convert(self, target, endpoint=None, blueprint=None, **kwargs):
endpoint = endpoint or target.__name__.lower()
if blueprint:
endpoint = '{}.{}'.format(blueprint, endpoint)
try:
rules = self.app.url_map._rules_by_endpoint[endpoint]
return [self.get_path(rule, target, **kwargs) for rule in rules]
except KeyError:
return []
```

this change actually makes it work correctly - tests can run and pass normally, swagger works normally. but this does not seem ideal. any ideas? :smile:

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.