Skip to content
Snippets Groups Projects

api: Use drf serializers to sanitize query params

Merged Renaud Boyer requested to merge rboyer/swh-web:snapshot-serializer into master

We should use drf serializers to validate & handle API calls' query parameters in order to:

  • avoid 500 errors with missing parameters or invalid inputs (especially when int-ing them)
  • simplify validation (choices, min/max values, required, etc.)

This MR adds a query_params_serializer parameter, an optional drf serializer class, to the api_route decorator which, if provided, validates request.query_params data and then passes the validated_data to the decorated view.

This mechanism is applied to the snapshot API endpoint and should be applied to other endpoints in subsequent MRs.

fixes SWH-WEBAPP-6AT

Edited by Renaud Boyer

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
Please register or sign in to reply
Loading