Я пытаюсь использовать модуль Sani c -OpenAPI с sani c для автоматического документирования моих собственных API RESTful. Итак, я установил их, выполнив следующую команду:
pip install sanic sanic-openapi
# sanic version is 19.12.2
# sanic_openapi version is 0.6.1
И я создал этот простой проект, который, кстати, представлен в их официальном репозитории GitHub. И это выглядит так:
from sanic import Sanic, response
from sanic_openapi import swagger_blueprint
app = Sanic("app")
app.blueprint(swagger_blueprint)
@app.route("/")
async def test(request):
return response.json({"hello": "world"})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000, debug=True)
Это работает нормально! Но когда я пытаюсь получить доступ к http://localhost: 8000 / swagger , возникает следующая ошибка:
Traceback (most recent call last):
File "/media/anwar/E/Chatbot/NLU_engine/py3.7/lib/python3.7/site-packages/sanic/app.py", line 974, in handle_request
response = handler(request, *args, **kwargs)
File "/media/anwar/E/Chatbot/NLU_engine/py3.7/lib/python3.7/site-packages/sanic_openapi/swagger.py", line 263, in spec
return json(swagger_blueprint._spec)
File "/media/anwar/E/Chatbot/NLU_engine/py3.7/lib/python3.7/site-packages/sanic/response.py", line 234, in json
dumps(body, **kwargs),
TypeError: <sanic_openapi.spec.Spec object at 0x7effe3d2f910> is not JSON serializable
[2020-07-12 11:34:09 +0200] - (sanic.access)[INFO][127.0.0.1:37880]: GET http://localhost:8000/swagger/swagger.json 500 2649
[2020-07-12 11:34:09 +0200] [11014] [ERROR] Exception occurred while handling uri: 'http://localhost:8000/swagger/swagger.json'
Traceback (most recent call last):
File "/media/anwar/E/Chatbot/NLU_engine/py3.7/lib/python3.7/site-packages/sanic/app.py", line 974, in handle_request
response = handler(request, *args, **kwargs)
File "/media/anwar/E/Chatbot/NLU_engine/py3.7/lib/python3.7/site-packages/sanic_openapi/swagger.py", line 263, in spec
return json(swagger_blueprint._spec)
File "/media/anwar/E/Chatbot/NLU_engine/py3.7/lib/python3.7/site-packages/sanic/response.py", line 234, in json
dumps(body, **kwargs),
TypeError: <sanic_openapi.spec.Spec object at 0x7effe3d2f910> is not JSON serializable