openapi-typescript-codegen icon indicating copy to clipboard operation
openapi-typescript-codegen copied to clipboard

Mark serialized objects in multipart/form-data as application/json [implemented]

Open mstieranka opened this issue 3 years ago • 0 comments

Currently, when an object is sent using the multipart/form-data content type, none of the individual parts have a set content type.

This, however, can be an issue in applications where the server doesn't have a suitable default for form data parts (as is the case in Spring, which considers all parts without a type to be application/octet-stream). When no content type is set and a JSON string representing an object is sent, its content cannot then be deserialized as the server doesn't know that the received content is of the application/json type.

It would therefore be great if this library would tag all parts that have been serialized from an object to a JSON string as application/json. The code that this relates to is shown below:

https://github.com/ferdikoomen/openapi-typescript-codegen/blob/59254d94a9fa24e6f10ac4cf356643685bb4bad1/src/templates/core/functions/getFormData.hbs#L5-L11

It's also important to mention that because of the aforementioned issue with Spring, I have already created a forked version of this library that implements this mechanism, but I have not submitted a PR yet, since I'm not sure if this is desired.

mstieranka avatar May 23 '22 14:05 mstieranka