My goal is to upload a file together with metadata (documentIds) using a multipart request. I am creating the client with the Java OpenAPI generator and the library resttemplate for the following API spec:
path:
/files:
post:
...
requestBody:
content:
multipart/form-data:
encoding:
file:
contentType: multipart/form-data
style: form
documentIds:
contentType: application/json
style: form
schema:
$ref: '#/components/schemas/UploadFileRequest'
...
components:
schemas:
UploadFileRequest:
type: object
properties:
documentIds:
type: array
items:
type: string
file:
type: string
format: binary
The following method is created as a result of the generation:
public void postFile(List<String> documentIds, Resource file) {...}
The problem I am facing is that the content-type for documentIds is automatically set to text/plain
which is not accepted on the server side. I couldn’t find any option to define the content-type header for a part. I have tried to define it in the API specification using encoding
(see above) and also with the extension x-content-type
. Both options didn’t change anything on client side. Am I missing something or is this “feature” just not supported by the library?