-
-
Notifications
You must be signed in to change notification settings - Fork 216
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Support multiple content types for a single endpoint #453
Comments
Interesting, I don’t think we’ve ever added (at least intentionally) support for multiple content types in one endpoint. How do you think this would be most ergonomic in the generated client? Only one content type can actually be sent so the function definition should indicate that somehow. Should there be a separate function per content type? Or maybe function overloading? |
Maybe make both parameters optional, and then raise an exception if both are set, or if neither is set? |
@dbanty it turns out that this could be solved by explicitly setting |
Glad you found a solution @dpursehouse! Would still love to add support for this some day, I'm sure there are others who would benefit from it. |
Do you know if this breaks the DRF Web browsable API? (e.g https://www.django-rest-framework.org/ | Web Browsable API: https://restframework.herokuapp.com/) I assumed that the |
@dbanty It seems like this portion might be a bug in its own right. When I wanted to send t_partial_update.sync(
metal.id,
client=client,
json_body=T(type="RED"),
form_data=T(),
multipart_data=T(),
) I opened up Wireshark on localhost interface to confirm and all of the I had to move it to the t_partial_update.sync(
metal.id,
client=client,
json_body=T(),
form_data=T(type="RED"),
multipart_data=T(),
) |
I assume this is a limitation in |
This comment has been minimized.
This comment has been minimized.
SPECTACULAR_SETTINGS = {
"PARSER_WHITELIST": ["rest_framework.parsers.JSONParser"],
} |
We have an API endpoint where we support uploading a file either as
Would love to have a feature where the codegen client would be able to support functions for both the In my case, having entirely separate functions for each request would be preferred, as it feels like the interface is strongly typed and most clear. It would mean we'd need to generate names that may look a little long:
This would also mean that we no longer have a 1:1 relationship between the api files and the actual paths in the OpenAPI spec. I'm not sure if there is anything that relies on such an assumption? Would be happy to contribute this feature, but did want to see if it the approach of separate functions makes sense, and is something that the community would be interested in having? |
EDIT: While the below suggestion provides a potential fix, I see this as more of an issue with I have also run facefirst into this issue multiple times. I have a schema that is being generated by
Unfortunately, openapi-generator only uses the first of these definitions, so I am stuck with this auto-generated client function:
Doh! It's trying to convert an image into JSON - clearly not what I am looking for. I have had to avoid using my auto-generated client any time I perform image uploads for this reason and manually submit data via However, most of the content request bodies in my schema have multiple entries in the "content" section, and I only want to specify that formData be uploaded for the image not the myriad of other models I have for which JSON works just fine. The most elegant way I can think to do this without breaking basic functionality is this algorithm:
|
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
With an openapi yaml schema that has this content:
The generated client has this method:
The diff from the client generated by version 0.9.2 is that it now takes a
multipart_data
parameter which is now used to populate thefiles
field on the returned dict.However the
json
field was removed and thejson_body
parameter is thus unused. This breaks clients that are passing thejson_body
field.Adding it back fixes it, i.e.
The text was updated successfully, but these errors were encountered: