使用falcon-swagger-ui

时间:2018-01-09 14:22:47

标签: python rest swagger falconframework

我正在尝试基于falcon-swagger-ui包提供swagger API docoumentation:https://github.com/rdidyk/falcon-swagger-ui 并使用repo中的示例:

# example.py
import falcon
from falcon_swagger_ui import StaticSinkAdapter
from falcon_swagger_ui import register_swaggerui_app

SWAGGERUI_URL = '/swagger'  
SCHEMA_URL = '/swagger.json'

app = falcon.API()
app.add_sink(
    StaticSinkAdapter('/home/greg/falcon-swagger-example/schema.json'), SCHEMA_URL
)

register_swaggerui_app(app, SWAGGERUI_URL, SCHEMA_URL, config={
    'supportedSubmitMethods': ['get'],
})

我的架构json文件已存在。如果我然后运行gunicorn example:app并转到http://127.0.0.1:8000/swagger,我会收到以下错误:

[2017-11-30 13:51:59 +0000] [23935] [ERROR] Error handling request /swagger.json
Traceback (most recent call last):
  File "/home/greg/falcon-swagger-example/.env/local/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 135, in handle
    self.handle_request(listener, req, client, addr)
  File "/home/greg/falcon-swagger-example/.env/local/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 176, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/home/greg/falcon-swagger-example/.env/local/lib/python2.7/site-packages/falcon/api.py", line 242, in __call__
    responder(req, resp, **params)
TypeError: __call__() takes exactly 4 arguments (3 given)

任何想法我做错了什么? 对于使用Falcon API提供swagger API文档,是否有更好的包装?

1 个答案:

答案 0 :(得分:0)

自原始帖子发布以来,falcon-swagger-ui进行了一些更新。

现在,如果您在回购中使用示例:

https://github.com/rdidyk/falcon-swagger-ui/blob/master/example.py#L9-L17

并将您的招摇模式放置在static / v1 / swagger.json中,然后当您前往http://127.0.0.1:8000/swagger

时将正确显示招摇