everyone. I have API: /api/movies/"movie_id" and it returns me is movie found or not. It works well, but when I in swagger in sends:
127.0.0.1 - - [27/Jan/2020 17:19:34] "GET /api/movies/%7Bmovie_id%7D HTTP/1.1" 4
04 -
Swagger doesn't send correct arguments to my GET function.
Update:
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')
}
init .py:
api.add_resource(routes.IDMovies, r'/api/movies/<string:movie_id>')
The parameter definition contains some incorrect values. You need to use "paramType": "path"
and "dataType": "string"
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.