Created by: grokify
PR checklist
-
Read the contribution guidelines. -
Ran the shell script under ./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.shand./bin/security/{LANG}-petstore.shif updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\. -
Filed the PR against the correct branch: master,3.1.x,4.0.x. Default:master. -
Copied the technical committee to review the pull request if your PR is targeting a particular programming language.
@antihax @bvwells
Description of the PR
When building a Go client with a required formData parameter of file type, a undefined: localVarFile error is countered when compiling the client.
This happens because localVarFile is currently only defined when a file is optional. This fix does the following:
- defines
localVarFilewhen a file is required - sets
localVarFileto the variable name as defined in the function call
Known Limitations
This approach can only handle a single file, but this is also a limitation of the current Go generator can as APIClient.prepareRequest() takes a single pair of localVarFileName and localVarFileBytes parameters. A future enhancement could support multiple files, either with the same multipart/form-data name or different ones.
Tests
mvn package was successfully run in the samples/client/petstore/go directory.
Additional Petstore tests were not added for this use case yet because an endpoint with a required formData file is not present in the Petstore spec. Adding this endpoint path to the Petstore spec will be a future project.
This has been tested locally with the following Swagger spec with a successful required file upload.
https://github.com/grokify/go-ringcentral/blob/master/codegen/swagger_spec.yaml