Multipart Request Body Support
jankuca opened this issue · 5 comments
(I have commented on a closed issue about this over two weeks ago but it got no attention: #8 – so I'm rather opening a new discussion here.)
The OpenAPI format can describe multipart/form-data
request body content types but Spot does not support this. It is very common to have form-data endpoints and it is almost a must for file upload endpoints.
It would be great to be able to describe such endpoints in Spot. I'm not completely sure about the right syntax though.
What I'm having in mind is:
- having specially parsed built-in type for binary data (just like we have for Integers and similar non-TS-native types)
- a config for the request body, possibly as
@request({ type: 'multipart' })
or more explicit{ contentType: 'multipart/form-data' }
Based on the Swagger/OpenApi format, multipart bodies are described as the following:
requestBody:
content:
multipart/form-data: # Media type
schema: # Request payload
type: object
properties: # Request parts
id: # Part 1 (string value)
type: string
format: uuid
address: # Part2 (object)
type: object
properties:
street:
type: string
city:
type: string
profileImage: # Part 3 (an image)
type: string
format: binary
It should be possible to specify parts of different content types (such as JSON, binary, string).
Hi @jankuca I think your suggestion makes sense. What do you think of:
@request({
contentType: 'multipart/form-data' // defaults to application/json
})
req(...) {}
@response({
status: 200,
contentType: 'multipart/form-data' // defaults to application/json
})
multiResp(...) {}
We can allow multiple @request
s and responses with the same status to cater for content negotiation as requested in #1074
Yes, you are basically quoting my proposal:
or more explicit
{ contentType: 'multipart/form-data' }
Being able to specify different bodies based on the contentType
would also be a great addition (although not completely required for my case).
Yes, you are basically quoting my proposal:
or more explicit
{ contentType: 'multipart/form-data' }
Being able to specify different bodies based on the
contentType
would also be a great addition (although not completely required for my case).
Yup, sorry the intention was only to be explicit with the config param naming.
Multi-part form data is also a necessary use case in our implementation using Spot -- commenting to bring awareness back to this feature request!
I've run into needing to document file upload endpoints that use this content type. (like in #8)