jmcarp / jmcarp/flask-apispec

Work with `flask-restful` to serve swagger-ui?

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

Description

Find this project while working on a `flask-restful` project. According to the [document](http://flask-apispec.readthedocs.io/en/latest/usage.html):

> Decorators can also be applied to view classes, e.g. Flask’s MethodView or flask-restful’s Resource.

It seems `flask-apisepec` can integrate with `flask-restful`, but I can not find any tutorial. When I try to add `flask-restful` resource:

```
docs = FlaskApiSpec(app)
docs.register(MyResource)
```

the program raises TypeError:

```
Traceback (most recent call last):
File "/home/cizixs/Work/wormhole/wormhole/app.py", line 43, in
docs.register(MyResource)
File "/home/cizixs/.virtualenvs/wormhole/lib/python2.7/site-packages/flask_apispec/extension.py", line 76, in register
raise TypeError()
TypeError
```

The same document says:

> For correct inheritance behavior, view classes should use the ResourceMeta meta-class.

No really understand the meaning, but it seems I should use `ResourceMeta` meta-class, but when I try the following code:

```
class MyResource(Resource):
__metaclass__ = ResourceMeta
...
```

The application throws a different error:

```
Traceback (most recent call last):
......
File "/home/cizixs/.virtualenvs/wormhole/lib/python2.7/site-packages/flask_apispec/views.py", line 21, in __new__
klass = super(ResourceMeta, mcs).__new__(mcs, name, bases, attrs)
TypeError: Error when calling the metaclass bases
metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
```

Can anyone tell me where I did wrong, or what is the correct way to use `flask-apispec` with `flask-restful`?

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.