python - Flask/Swagger - Swagger 没有发送正确的参数
问题描述
每个人。我有 API:/api/movies/"movie_id" 它返回我是否找到电影。它运作良好,但是当我大摇大摆地发送时:
127.0.0.1 - - [27/Jan/2020 17:19:34] "GET /api/movies/%7Bmovie_id%7D HTTP/1.1" 4
04 -
Swagger 没有向我的 GET 函数发送正确的参数。
更新:
class IDMovies(Resource):
@swagger.operation(
notes='Get info about a movie by id',
nickname="getmovie",
responseClass=ResponseIDMoviesSuccess,
parameters=[
{
"name": "movie_id",
"description": "ID of a movie to return",
"required": True,
"allowMultiple": False,
"paramType": "string",
"dataType": "JSON"
}],
responseMessages=[
{
"message": "Successful operation",
"code": 200
},
{
"message": "Not found movie",
"code": 404
}
])
def get(self, movie_id):
movie = Movies.query.filter_by(imdbid=movie_id).first()
if movie != None:
movie = movie.__repr__()
return {'movie': movie, 'status': 200, 'error': False}
else:
return {'error_msg': "Not found movie", 'status': 404, 'error': True}, 404
@swagger.model
@swagger.nested(movie=MovieItem.__name__)
class ResponseIDMoviesSuccess:
def __init__(self, movie, status, error):
pass
resource_fields = {
'movie': fields.Nested(MovieItem.resource_fields),
'status': fields.Integer(attribute='status'),
'error': fields.Boolean(attribute='error')
}
初始化.py:
api.add_resource(routes.IDMovies, r'/api/movies/<string:movie_id>')
解决方案
参数定义包含一些不正确的值。您需要使用"paramType": "path"
和"dataType": "string"
。
推荐阅读
- r - R中多元回归的功率分析结果很奇怪
- leaflet - 像图层一样打开/关闭功能 - Leaflet Vectorgrid
- r - 如何在 R 中求解具有时间相关参数的 ODE 系统?
- reactjs - 修复漏洞 - “immer 中的关键原型污染”已修补 >=9.0.6
- java - Liquibase 无法找到用于 4.0 及更高版本的集成测试的更改日志文件
- c++ - 如何在浏览器上的 emscripten 构建代码上执行 WASM 文件
- javascript - Axios Promise.allSettled() 问题
- android - Amazon IAP Android onProductDataResponse 总是失败
- javascript - 如何使用套接字 io 断开客户端?
- android - 标记未在 Android 中的地图上显示