Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multipart Request Body Support #1150

Open
jankuca opened this issue Nov 25, 2020 · 5 comments
Open

Multipart Request Body Support #1150

jankuca opened this issue Nov 25, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@jankuca
Copy link
Contributor

jankuca commented Nov 25, 2020

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

@lfportal
Copy link
Contributor

lfportal commented Dec 9, 2020

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 #1074

@lfportal lfportal added the enhancement New feature or request label Dec 9, 2020
@jankuca
Copy link
Contributor Author

jankuca commented Dec 9, 2020

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

@lfportal
Copy link
Contributor

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.

@amoghsharma1996
Copy link

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

@warmbowski
Copy link

warmbowski commented Apr 12, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants