Skip to content

[core] Add support for multipart/ mediatype and encoding params#5613

Open
zhemant wants to merge 14 commits intoOpenAPITools:masterfrom
zhemant:mpandencoding
Open

[core] Add support for multipart/ mediatype and encoding params#5613
zhemant wants to merge 14 commits intoOpenAPITools:masterfrom
zhemant:mpandencoding

Conversation

@zhemant
Copy link
Copy Markdown
Contributor

@zhemant zhemant commented Mar 17, 2020

The PR will add support for

  • proper parsing of multiple parameters in request body e.g multipart/related.
  • add parsing for encoding parameters from specifications
  • add flags to handle multipart
  • add test yaml for multipart
  • add test for verifying flags and parameters
  • handling body and form params in response
  • add test for verifying flags and parameters in reponse

Multipart Requests: https://swagger.io/docs/specification/describing-request-body/multipart-requests/
Encoding: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#encoding-object

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.3.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@auto-labeler
Copy link
Copy Markdown

auto-labeler Bot commented Mar 17, 2020

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@zhemant
Copy link
Copy Markdown
Contributor Author

zhemant commented Mar 17, 2020

@wing328 I have added the PR again for support of multipart and encoding. I will add tests for these additions

@zhemant
Copy link
Copy Markdown
Contributor Author

zhemant commented Mar 18, 2020

Added test yaml file and test function to verify required flag for body in formparams, multipart related contenttype and its flags, encoding objects for multipart

@zhemant
Copy link
Copy Markdown
Contributor Author

zhemant commented Mar 19, 2020

@wing328 the PR is complete from my side. Please check

@wing328
Copy link
Copy Markdown
Member

wing328 commented Mar 23, 2020

cc @OpenAPITools/generator-core-team

@zhemant
Copy link
Copy Markdown
Contributor Author

zhemant commented Apr 2, 2020

A conflict was generated. I fixed the conflict. Any other comments or suggestions on the PR?

@zhemant
Copy link
Copy Markdown
Contributor Author

zhemant commented Apr 16, 2020

@wing328 there are no comments on the PR, can it be merged, please?

@zhemant
Copy link
Copy Markdown
Contributor Author

zhemant commented Apr 25, 2020

@wing328 any inputs, please?

@wing328
Copy link
Copy Markdown
Member

wing328 commented May 19, 2020

Sorry didn't have time to review yet. Will try to get it done before 5.x release.

@zhemant
Copy link
Copy Markdown
Contributor Author

zhemant commented May 26, 2020

no problem. Take your time. I will solve conflicts once you check it. Whenever I solve conflicts there are new merge requests which again generate conflicts.

@zhemant
Copy link
Copy Markdown
Contributor Author

zhemant commented Jun 30, 2020

@wing328 any updates on this?

@lucjross
Copy link
Copy Markdown

@wing328 i've run into this issue as well. updates?

@zhemant
Copy link
Copy Markdown
Contributor Author

zhemant commented Feb 9, 2021

@wing328 Could we please try to get this merged? I will fix the conflicts if we can merge.

@ryana
Copy link
Copy Markdown

ryana commented May 2, 2023

Seems like wanting to upload different content-types within a multipart upload is table stakes for an API. Is there another way we should be doing this?

If not, what are the changes this gets merged?

@adabuleanu
Copy link
Copy Markdown

Hello. Any updates on how to add encoding to multipart requests or is there a workaround available? Seems this PR is abandoned, but the issue is still present. In my case I want to send an integer on the request.
Here is my openapi spec:

paths:
  /files:
    post:
      operationId: createFile
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: "#/components/schemas/CreateFile"
            encoding:
              retention:
                contentType: application/json

components:
  schemas:
    CreateFile:
      type: object
      required:
        - file
      properties:
        retention:
          type: integer
          description: Retention time in seconds.
          format: int64
          minimum: 0
          default: 1
        file:
          type: string
          description: The document file.
          format: binary

And the failure is:

request body has an error: doesn't match schema #/components/schemas/CreateFile: Error at "/retention": value must be an integer

I am using the python generated client with v7.7.0 openapi generator version.

Also, I can reproduce the same behavior using curl:

# this fails because there is no type defined for retention param
$ curl -X 'POST 'http://localhost:8080/api/v1/files'   -H 'accept: application/json'   -H 'Content-Type: multipart/form-data'   -F 'file=@file.xml;type=text/xml'  -F 'retention=1'
request body has an error: doesn't match schema #/components/schemas/CreateFile: Error at "/retention": value must be an integer

# this passes because the enconding is application/json for the retention param
$ curl -X 'POST 'http://localhost:8080/api/v1/files'   -H 'accept: application/json'   -H 'Content-Type: multipart/form-data'   -F 'file=@file.xml;type=text/xml'  -F 'retention=1;type=application/json'

I want to achieve the same with the python generated client.

@zhemant
Copy link
Copy Markdown
Contributor Author

zhemant commented Sep 19, 2024

From the latest code, I see there is some support for encoding, I am not sure. But if multipart/related is still interesting for response, then I would be happy to create another clean PR with the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants