Skip to content

Commit

Permalink
[Go] Add multiple file upload support (OpenAPITools#16956)
Browse files Browse the repository at this point in the history
* add go echo api client github workflow

* add support for multi file upload in go client

* update go samples
  • Loading branch information
wing328 authored Nov 1, 2023
1 parent c2a4163 commit 8d76ab9
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 21 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/samples-go-client-echo-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Go Client (Echo API)

on:
pull_request:
paths:
- samples/client/echo_api/go/**
- .github/workflows/samples-go-client-echo-api.yaml
jobs:
build:
name: Test Go client
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sample:
# clients
- samples/client/echo_api/go
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: "stable"
- name: Setup node.js
uses: actions/setup-node@v4
- name: Run echo server
run: |
git clone https://github.com/wing328/http-echo-server -b openapi-generator-test-server
(cd http-echo-server && npm install && npm start &)
- run: go version
- name: Run test
working-directory: ${{ matrix.sample }}
run: go test -mod=mod -v
22 changes: 21 additions & 1 deletion modules/openapi-generator/src/main/resources/go/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,32 @@ func (a *{{{classname}}}Service) {{nickname}}Execute(r {{#structPrefix}}{{&class
{{/headerParams}}
{{#formParams}}
{{#isFile}}
{{#isArray}}
var {{paramName}}LocalVarFormFileName string
var {{paramName}}LocalVarFileName string
var {{paramName}}LocalVarFileBytes []byte

{{paramName}}LocalVarFormFileName = "{{baseName}}"
{{paramName}}LocalVarFormFileName = "{{{baseName}}}"
{{paramName}}LocalVarFile := r.{{paramName}}

if {{paramName}}LocalVarFile != nil {
// loop through the array to prepare multiple files upload
for _, {{paramName}}LocalVarFileValue := range {{paramName}}LocalVarFile {
fbs, _ := io.ReadAll({{paramName}}LocalVarFileValue)

{{paramName}}LocalVarFileBytes = fbs
{{paramName}}LocalVarFileName = {{paramName}}LocalVarFileValue.Name()
{{paramName}}LocalVarFileValue.Close()
formFiles = append(formFiles, formFile{fileBytes: {{paramName}}LocalVarFileBytes, fileName: {{paramName}}LocalVarFileName, formFileName: {{paramName}}LocalVarFormFileName})
}
}
{{/isArray}}
{{^isArray}}
var {{paramName}}LocalVarFormFileName string
var {{paramName}}LocalVarFileName string
var {{paramName}}LocalVarFileBytes []byte

{{paramName}}LocalVarFormFileName = "{{{baseName}}}"
{{paramName}}LocalVarFile := r.{{paramName}}

if {{paramName}}LocalVarFile != nil {
Expand All @@ -272,6 +291,7 @@ func (a *{{{classname}}}Service) {{nickname}}Execute(r {{#structPrefix}}{{&class
{{paramName}}LocalVarFile.Close()
formFiles = append(formFiles, formFile{fileBytes: {{paramName}}LocalVarFileBytes, fileName: {{paramName}}LocalVarFileName, formFileName: {{paramName}}LocalVarFormFileName})
}
{{/isArray}}
{{/isFile}}
{{^isFile}}
{{#required}}
Expand Down
17 changes: 9 additions & 8 deletions samples/client/echo_api/go/api_body.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions samples/client/petstore/go/go-petstore/api_fake.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions samples/client/petstore/go/go-petstore/api_pet.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions samples/openapi3/client/petstore/go/go-petstore/api_fake.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions samples/openapi3/client/petstore/go/go-petstore/api_pet.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8d76ab9

Please sign in to comment.