Skip to content

[Go] Fix for 'Invalid code for files array in multipart/form-data request'…#8103

Merged
wing328 merged 3 commits intoOpenAPITools:masterfrom
aliakseiz:bug/files-array
Dec 10, 2020
Merged

[Go] Fix for 'Invalid code for files array in multipart/form-data request'…#8103
wing328 merged 3 commits intoOpenAPITools:masterfrom
aliakseiz:bug/files-array

Conversation

@aliakseiz
Copy link
Copy Markdown
Contributor

Fixes invalid code generation, when multipart/form-data requestBody contains array of files (#8093).

In addition to existing ReadFormFileToTempFile function a new one introduced ReadFormFilesToTempFiles returning a slice of *os.File.

To avoid code duplication, common part related to FileHeader reading and storing in temporary file moved to new readFileHeaderToTempFile function.

controller-api.mustache updated to invoke corresponding function, depending on either single or multiple files are in a request.

Condition verifying the os package import extended in GoServerCodegen.java with a slice of files type.

Replaced a temporary directory path "tmp" with "" in ioutil.TempFile call to make TempFile() using the default os.TempDir directory.

Testing

Existing automated tests passed. No new tests added.

Built project locally, manually tested generated code with different specifications (single file, array of files, various file formats).

Technical committee

@antihax @grokify @kemokemo @bkabrda

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.
  • If contributing template-only or documentation-only changes which will change sample output, build the project beforehand.
  • Run the shell script ./bin/generate-samples.shto update all Petstore samples related to your fix. 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
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@wing328
Copy link
Copy Markdown
Member

wing328 commented Dec 5, 2020

Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors.

Let me know if you need help fixing it.

Ref: https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-can-i-update-commits-that-are-not-linked-to-my-github-account

@wing328
Copy link
Copy Markdown
Member

wing328 commented Dec 5, 2020

Please also run ./bin/utils/ensure-up-to-date to update the samples so that CI can verify the change.

@aliakseiz aliakseiz changed the title Fix for 'Invalid code for files array in multipart/form-data request'… [Go] Fix for 'Invalid code for files array in multipart/form-data request'… Dec 5, 2020
@aliakseiz
Copy link
Copy Markdown
Contributor Author

It looks that circleci build failed due to network connection issue:

[info] 	[SUCCESSFUL ] ch.qos.logback#logback-core;1.2.3!logback-core.jar (866ms)
[warn] 	[FAILED     ] net.sourceforge.htmlunit#htmlunit;2.27!htmlunit.jar: Connection reset (867ms)
[warn] 	[FAILED     ] com.typesafe.play#play-docs_2.12;2.6.18!play-docs_2.12.jar: Connection reset (606ms)
...

@wing328 can you please rerun the build?

@wing328
Copy link
Copy Markdown
Member

wing328 commented Dec 7, 2020

@aliakseiz thanks for the PR. What about using tabs instead of 4-spaces in the Go mustache templates?

@aliakseiz
Copy link
Copy Markdown
Contributor Author

No problem, @wing328 .
Fixed.

Copy link
Copy Markdown
Member

@wing328 wing328 left a comment

Choose a reason for hiding this comment

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

LGTM

@wing328 wing328 merged commit 9e56104 into OpenAPITools:master Dec 10, 2020
@wing328 wing328 added this to the 5.0.0 milestone Dec 10, 2020
}

// readFileHeaderToTempFile reads multipart.FileHeader and writes it to a temporary file
func readFileHeaderToTempFile(fileHeader *multipart.FileHeader) (*os.File, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

multipart is not defined as an import here. We should add "mime/multipart" in the import list

@worming004 worming004 mentioned this pull request Feb 11, 2021
2 tasks
@aliakseiz aliakseiz deleted the bug/files-array branch March 27, 2021 14:47
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