Reputation: 702
I'm reverse-engineering an API with an endpoint /submit
, that accepts the type multipart/form-data
content. On the webpage of the service, there is a form to upload plaintext files, so the body of the request should look (and according to devtools it actually looks) like this:
-----------------------------16987925643278910326523687321
Content-Disposition: form-data; name="output"; filename="aaa.txt"
Content-Type: text/plain
some text
-----------------------------16987925643278910326523687321--
My OpenAPI specification of the request body is as follows:
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
output:
type: string
This works almost perfectly, but the code generated from the specification doesn't include the filename="something.txt"
in its requests, which the API for some reason needs.
OK: Content-Disposition: form-data; name="output"; filename="aaa.txt"
Error: Content-Disposition: form-data; name="output"
How can I specify in the OpenAPI specification, that the part must always be provided with the filename?
Upvotes: 1
Views: 2123
Reputation: 702
As correctly pointed out by @Helen, the solution is to add format: binary
after type: string
in the specification:
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
output:
type: string
format: binary # <- THIS
Upvotes: 1