python-restx / flask-restx

Fork of Flask-RESTPlus: Fully featured framework for fast, easy and documented API development with Flask
https://flask-restx.readthedocs.io/en/latest/
Other
2.16k stars 335 forks source link

Marshal With is expecting the params in reponse #618

Open fras2560 opened 2 months ago

fras2560 commented 2 months ago

I am writing an endpoint where two params are part of the url

Code

schedule_api = Namespace(
    "schedule",
    description="API for all the League's Schedule queries"
)
schedule_payload = schedule_api.model('Schedule', {
    'away_team': fields.String(
        description="The name of the away team",
    ),
    'away_team_id': fields.Integer(
        description="The id of the away team",
    ),
    'date': fields.Date(
        description="The date of the game",
    ),
    'field': fields.String(
        description="The field of the game",
    ),
    'home_team': fields.String(
        description="The name of the home team",
    ),
    'home_team_id': fields.Integer(
        description="The id of the home team",
    ),
    'league_id': fields.Integer(
        description="The id of the league",
    ),
    'score': fields.String(
        description="The score of the game if played",
    ),
    'status': fields.String(
        description="The status of the game",
    ),
    'time': fields.String(
        description="The time of the game (Format: HH-MM)",
        example="12:01"
    ),
})
pagination = get_pagination(schedule_api)
schedule_pagination = schedule_api.inherit("SchedulePagination", pagination, {
    'items': fields.List(fields.Nested(schedule_payload))
})
@schedule_api.route("/<int:year>/<int:league_id>", endpoint="rest.schedule")
@schedule_api.doc(
    params={"year": "The schedule year", "league_id": "The id of the league"}
)
class ScheduleAPIX(Resource):

    @schedule_api.marshal_with(schedule_pagination, envelope='resource')
    def get(self, year, league_id):
        page = request.args.get('page', 1, type=int)
        data = pull_schedule(year, league_id, page=page)
        # running into issue where say this was needed in response
        # just added them for now
        data['year'] = year
        data['league_id'] = league_id
        return data

Repro Steps (if applicable)

  1. ...
  2. ...
  3. Broken!

Expected Behavior

Should be able to not include league_id and year in the response

Actual Behavior

[A description of the unexpected, buggy behavior.](root:errors_handler.py:86 Could not build url for endpoint 'rest.schedule' with values ['has_next', 'has_prev', 'items', 'pages', 'total']. Did you forget to specify values ['league_id', 'year']?)

Error Messages/Stack Trace

[A description of the unexpected, buggy behavior.](root:errors_handler.py:86 Could not build url for endpoint 'rest.schedule' with values ['has_next', 'has_prev', 'items', 'pages', 'total']. Did you forget to specify values ['league_id', 'year']?)

Environment

Additional Context

image image

This is your last chance to provide any pertinent details, don't let this opportunity pass you by!