multipart/form-data request is splitting up data field by field
See original GitHub issueHello,
I’m using openapi-generator maven plugin to generate the client side java classes and interfaces for a third-party API. Generator version: 5.3.1 and FEIGN library to generate the client side.
API:
requestBody: content: multipart/form-data: schema: $ref: '.domain#/components/schemas/Document' encoding: metadata: contentType: application/json style: form
Domain:
Document: type: object properties: metadata: $ref: '#/components/schemas/Metadata' document: type: string description: Array of bytes representing the content of the document format: binary
When I’m sending the request the metadata is split field by field instead of having it sent over as JSON.
` Content-Disposition: form-data; name=“validUntilRevoked” Content-Type: text/plain; charset=UTF-8
true Content-Disposition: form-data; name=“value” Content-Type: text/plain; charset=UTF-8
lorem ipsum Content-Disposition: form-data; name=“extRef” Content-Type: text/plain; charset=UTF-8
abc Content-Disposition: form-data; name=“issueDate” Content-Type: text/plain; charset=UTF-8 1992-10-12`
I’m expecting to be sent over in this format: `Content-Disposition: form-data; name=“metadata” Content-Type: text/plain; charset=UTF-8
{“evidenceType”:“<string>”,“ext_ref”:“<string>”,“issueDate”:“<string>”,“validUntilRevoked”:“<boolean>”} ` Do you have any idea if this is a bug on the openapi generatoror in the feign client?
Any suggestions will be appreciated.
Thanks!
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
If it is not already supported, I feel like it should in any case:
https://datatracker.ietf.org/doc/html/rfc7578#section-4.4
I found the way to solve it, modifying the encoder of Feign client and adding JsonFormWriter as first writer.
apiClient.getFeignBuilder().encoder(new SpringFormEncoder() {{
var processor = (MultipartFormContentProcessor) getContentProcessor(ContentType.MULTIPART);
processor.addFirstWriter(jsonFormWriter);
processor.addFirstWriter(new SpringSingleMultipartFileWriter());
processor.addFirstWriter(new SpringManyMultipartFilesWriter());
}});