Support multiple content types for a single endpoint #822
Replies: 12 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? |
Beta Was this translation helpful? Give feedback.
-
Maybe make both parameters optional, and then raise an exception if both are set, or if neither is set? |
Beta Was this translation helpful? Give feedback.
-
@dbanty it turns out that this could be solved by explicitly setting |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
@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(),
) |
Beta Was this translation helpful? Give feedback.
-
I assume this is a limitation in |
Beta Was this translation helpful? Give feedback.
This comment has been hidden.
This comment has been hidden.
-
SPECTACULAR_SETTINGS = {
"PARSER_WHITELIST": ["rest_framework.parsers.JSONParser"],
} |
Beta Was this translation helpful? Give feedback.
-
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? |
Beta Was this translation helpful? Give feedback.
-
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:
|
Beta Was this translation helpful? Give feedback.
-
Support added in 0.17! |
Beta Was this translation helpful? Give feedback.
-
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.
Beta Was this translation helpful? Give feedback.
All reactions