spot icon indicating copy to clipboard operation
spot copied to clipboard

Multipart Request Body Support

Open jankuca opened this issue 5 years ago • 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).

jankuca avatar Nov 25 '20 22:11 jankuca

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 @requests and responses with the same status to cater for content negotiation as requested in https://github.com/airtasker/spot/issues/1074

lfportal avatar Dec 09 '20 12:12 lfportal

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).

jankuca avatar Dec 09 '20 15:12 jankuca

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.

lfportal avatar Dec 10 '20 00:12 lfportal

Multi-part form data is also a necessary use case in our implementation using Spot -- commenting to bring awareness back to this feature request!

amoghsharma1996 avatar Dec 21 '21 04:12 amoghsharma1996

I've run into needing to document file upload endpoints that use this content type. (like in #8)

warmbowski avatar Apr 12 '22 00:04 warmbowski