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

[GO][Client] Multipart/form-data Request Support More Than One File #10843

Merged
merged 6 commits into from
Nov 22, 2021

Conversation

icubbon
Copy link
Contributor

@icubbon icubbon commented Nov 11, 2021

The Go client will iterate over the files for a multipart/form-data request and add each file to a slice of formFiles.
Added a private struct formFile that contains the already defined values of a formFile. A Request now creates an empty slice of formFiles in which files are appended into.
The prepareRequest function will now iterate over the slice of formFiles to add each one to the request.

Addresses #8322

An example snippet of a schema that has the problem being addressed, note the second file in the multipart/form-data request body:

  "/pet/{petId}/uploadImage":
    post:
      tags:
        - pet
      summary: uploads an image
      description: ""
      operationId: uploadFile
      parameters:
        - name: petId
          in: path
          description: ID of pet to update
          required: true
          schema:
            type: integer
            format: int64
      responses:
        "200":
          description: successful operation
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ApiResponse"
      security:
        - petstore_auth:
            - "write:pets"
            - "read:pets"
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                additionalMetadata:
                  description: Additional data to pass to server
                  type: string
                file:
                  description: file to upload
                  type: string
                  format: binary
                secondFile:
                  description: another file to upload
                  type: string
                  format: binary

@antihax @grokify @kemokemo @jirikuncar @ph4r5h4d

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (5.3.0), 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Copy link
Contributor

@jirikuncar jirikuncar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you create a schema with an endpoint that is using multiple form files?

@icubbon
Copy link
Contributor Author

icubbon commented Nov 12, 2021

Can you create a schema with an endpoint that is using multiple form files?

Do you want an the PetStore example updated or do you want to see it as part of this PR description?
Thanks!

@jirikuncar
Copy link
Contributor

Do you want the PetStore example updated?

The best option would be creating new folder (e.g. multiple-data-in-forms) in https://github.com/OpenAPITools/openapi-generator/tree/master/samples/openapi3/client/features with a simple OA3 schema.

@icubbon
Copy link
Contributor Author

icubbon commented Nov 16, 2021

Do you want the PetStore example updated?

The best option would be creating new folder (e.g. multiple-data-in-forms) in https://github.com/OpenAPITools/openapi-generator/tree/master/samples/openapi3/client/features with a simple OA3 schema.

I added a basic single endpoint OA3 schema with the corresponding Go Client go into samples/openapi3/client/features/multiple-data-in-forms. Can you take a look at let me know if that's what you were thinking?
Thanks!

Comment on lines 286 to 289
secondFile:
description: another file to upload
type: string
format: binary
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to add it to this file? It will affect all clients.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and removed it. Looking through active and closed bugs, it looks like other clients have been impacted by this issue to.

that contains two files to be uploaded
@wing328
Copy link
Member

wing328 commented Nov 22, 2021

LGTM but I've not thoroughly tested it locally

@wing328 wing328 merged commit 6779c33 into OpenAPITools:master Nov 22, 2021
@icubbon icubbon deleted the go-multi-formfile-upload branch August 5, 2022 20:42
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.

3 participants