首页 > 解决方案 > 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>')

标签: pythonflaskswagger

解决方案


参数定义包含一些不正确的值。您需要使用"paramType": "path""dataType": "string"


推荐阅读