DRY validation of query params for djangorestframework view

Viewed 235

I want to create a view in django-rest-framework. This view would accept several custom query parameters, so it wouldn’t be based on any existing view. I want the query parameters to be available in the OpenAPI 3 schema for the purpose of type-checking in the TypeScript client. My questions are:

  1. How can I perform the validation of these parameters declaratively? Is using Serializer a good way to perform validation of a query string?
  2. How can I generate the corresponding part of the OpenAPI 3 schema in a DRY way? I see that the existing drf views don’t use a DRY pattern here (they just return a static directory for schema). Also, the method that generates schema for Serializers is underscore-prefixed, so it might not be a good idea to use it directly (although I don’t know the rationale for this).

So what are my options here?

0 Answers
Related