-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Use serializers as a source for APIView schema parameters #7163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think you could implement this using either the existing DRF filters—in your example, |
In this idea, I don't see the benefit of the decorator and Possibly, like maybe, we could introduce an
But I'm not yet convinced of the need for that. (The subclass is hardly a lot of code.) |
Using a serializer means you also get validation on query parameters, which is always useful to reduce code duplication for example; why do a I think having more documentation and public methods on the AutoSchema would make subclassing easier and help point folks to how they can customize their schemas. |
Yes, absolutely. I want to move ≈all the methods to public (i.e. no |
The problem of that approach is that you will have the same parameters in all methods, which may not be desirable. The same for the serializer.
Exactly. |
Maybe that's the way to go. |
@Lucidiot is right here: filter parameters come from filter backends (be they django-filter, the DRF shipped ones, or your own.) You can implement a filter backend to use serializers, to give you validation etc (which is exactly what django-filters does, except with FilterSets and forms under the hood). The relevant AutoSchema method is |
@carlfarrington The
|
Uh oh!
There was an error while loading. Please reload this page.
I want to add filter like parameters to my APIView methods, they should appear in the schema and validate the incoming data, serializers are a perfect fit for this.
In this repo:
https://github.com/domingues/django-rest-framework/blob/0997748e4fbd0f330cfcac580b446d849e50f80e/rest_framework/schemas/openapi.py#L542-L586
we have a
class APIViewSchema(AutoSchema)
that provides (at the moment) two decorators:@APIViewSchema.serializer(serializer: serializers.Serializer)
and@APIViewSchema.query_parameters(parameters: serializers.Serializer)
and use them like this:
I think that would be really useful if we have something like this.
The text was updated successfully, but these errors were encountered: