Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7k
Add distinction between request and response serializers for OpenAPI#7424
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Add distinction between request and response serializers for OpenAPI#7424
Uh oh!
There was an error while loading.Please reload this page.
Conversation
👍 What a coincidence that we came across the same issue only 1.5 hours apart :) |
@akx Hah, yeah. Can't believe it. |
@apirobot Can we add short docs for the new methods?
|
@carltongibson Yeah, sure. I've pushed new commit. |
gaara4896 commentedJul 28, 2020
Can't wait for the release, facing the same issue here too |
Agreed – hoping for a release with this and#7208... |
@carltongibson Can we get this merged? 😄 |
yardensachs commentedNov 10, 2020
Oh wow, we really need this at where I work! |
Naive question, why don't you use a single serializer with |
I don't want to jump off the deep-end of complexity but, I have no problem adding this kind of thing in principle. This patch still needs tests and docs at the least though. |
yardensachs commentedNov 10, 2020
@apirobot Can you add tests and docs? |
elonzh commentedNov 16, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
what about query parameters? relate#7163 |
We're hoping to use this at my work and would prefer to be able to just update to latest Django to do so rather than having an internally patched version, so I intend to add documentation and tests for this change at some point in February so this PR can hopefully be merged in March. |
…ializersDoc & test for Openapi request response serializers
@carltongibson Hi, I added a little bit of documentation of the new functions and a basic test case. I'm glad to add more if desired, just wanted to put something up to start and then ask for feedback on any specific examples of desired test cases to cover or items to cover in documentation or additional areas to document. I'm really confused by this CI build failure though. It's talking about trying to import a module named |
you can pull on master and build should pass now |
…ializersflake8 formatting - Openapi request response serializers
Hey@tomchristie i don't think this is far off, but I didn't get the cycle to swing back to it yet. |
I don't have any objection to this. I'd be interested to see a proper example of this being used in the wild, to get a better idea of how folks are expecting to hook this up in practice. But otherwise, sure let's get this in. |
This code is based off of a PR that has been merged to master in the DRF repo, but has not yet been included in a release. Seeencode/django-rest-framework#7424
khamaileon commentedSep 28, 2021
@apirobot Can you provide a full example of how this works? Even with the documentation provided, the view part is still very obscure to me. |
royhzq commentedNov 3, 2021
Any idea why the current docs have already included the new methods https://www.django-rest-framework.org/api-guide/schemas/#get_request_serializer Either way, looking forward to seeing this released soon 👍 |
It looks like it's on the master branch, which must be what the documentation is generating from, but not in the latest tagged release, which is currently 3.12.4 and dated 2021 May 31st. I think the dating issue must be because Github is showing the version release date, and that release was actually forked a couple months prior and had final testing, so these changes must have just missed that last release. Because this change was merged prior to that tagged release date, but it's close, and I do see these code changes listed in the diff between master branch and that tagged release. |
…ncode#7424)* Add distinction between request and response serializers* Add docs* document new functions in schemas.md* add a test case for different request vs response objects* Correct formatting for flake8Co-authored-by: Shaun Gosse <shaun.gosse@emburse.com>
Description
In my custom implementation of DRF views, instead of using
get_serializer
method, I have two methods:get_request_serializer
andget_response_serializer
.It allows me to use one serializer for handling request data, and another serializer for generating response data.
Additionally, I try to generate OpenAPI. But right now there is no distinction between request and response serializers during schema generation. In both methods,
get_request_body
andget_responses
, we call the same method:def get_serializer(self, path, method)
This PR adds a distinction between request and response serializers. It doesn't change anything under the hood. All it does is it adds two methods:
get_request_serializer
andget_response_serializer
.We can override those methods and point to different serializers.
Can be related to#1563