Skip to content

Commit 012c31c

Browse files
if the array is of model type, the package name of the model needs to be added to the parameter definition
1 parent 30e3e50 commit 012c31c

File tree

9 files changed

+23
-5
lines changed

9 files changed

+23
-5
lines changed

modules/openapi-generator/src/main/resources/go-server/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ type {{classname}}Router interface { {{#operations}}{{#operation}}
2424
// while the service implementation can ignored with the .openapi-generator-ignore file
2525
// and updated with the logic required for the API.
2626
type {{classname}}Servicer interface { {{#operations}}{{#operation}}
27-
{{operationId}}(context.Context{{#allParams}}, {{#isModel}}{{#hasDifferentModelDir}}models.{{/hasDifferentModelDir}}{{/isModel}}{{dataType}}{{/allParams}}) (ImplResponse, error){{/operation}}{{/operations}}
27+
{{operationId}}(context.Context{{#allParams}}, {{#isArray}}[]{{^isPrimitiveType}}{{#hasDifferentModelDir}}models.{{/hasDifferentModelDir}}{{/isPrimitiveType}}{{baseType}}{{/isArray}}{{^isArray}}{{#isModel}}{{#hasDifferentModelDir}}models.{{/hasDifferentModelDir}}{{/isModel}}{{dataType}}{{/isArray}}{{/allParams}}) (ImplResponse, error){{/operation}}{{/operations}}
2828
}{{/apis}}{{/apiInfo}}

modules/openapi-generator/src/main/resources/go-server/controller-api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re
153153
{{paramName}} := r.Header.Get("{{baseName}}")
154154
{{/isHeaderParam}}
155155
{{#isBodyParam}}
156-
{{paramName}} := &{{#isModel}}{{#hasDifferentModelDir}}models.{{/hasDifferentModelDir}}{{/isModel}}{{dataType}}{}
156+
{{paramName}} := &{{#isArray}}[]{{^isPrimitiveType}}{{#hasDifferentModelDir}}models.{{/hasDifferentModelDir}}{{/isPrimitiveType}}{{baseType}}{{/isArray}}{{^isArray}}{{#isModel}}{{#hasDifferentModelDir}}models.{{/hasDifferentModelDir}}{{/isModel}}{{dataType}}{{/isArray}}{}
157157
if err := json.NewDecoder(r.Body).Decode(&{{paramName}}); err != nil {
158158
w.WriteHeader(http.StatusBadRequest)
159159
return

samples/server/petstore/go-chi-server/go/api.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ import (
1313
"context"
1414
"net/http"
1515
"os"
16+
17+
18+
19+
20+
21+
1622
)
1723

1824

samples/server/petstore/go-chi-server/go/api_pet.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
"strings"
1616

1717
"github.com/go-chi/chi/v5"
18+
19+
1820
)
1921

2022
// A PetApiController binds http requests to an api service and writes the service results to the http response

samples/server/petstore/go-chi-server/go/api_pet_service.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ package petstoreserver
1111

1212
import (
1313
"context"
14-
"net/http"
1514
"errors"
15+
"net/http"
1616
"os"
17+
18+
1719
)
1820

1921
// PetApiService is a service that implents the logic for the PetApiServicer

samples/server/petstore/go-chi-server/go/api_store.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
"strings"
1616

1717
"github.com/go-chi/chi/v5"
18+
19+
1820
)
1921

2022
// A StoreApiController binds http requests to an api service and writes the service results to the http response

samples/server/petstore/go-chi-server/go/api_store_service.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ package petstoreserver
1111

1212
import (
1313
"context"
14-
"net/http"
1514
"errors"
15+
"net/http"
16+
17+
1618
)
1719

1820
// StoreApiService is a service that implents the logic for the StoreApiServicer

samples/server/petstore/go-chi-server/go/api_user.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
"strings"
1616

1717
"github.com/go-chi/chi/v5"
18+
19+
1820
)
1921

2022
// A UserApiController binds http requests to an api service and writes the service results to the http response

samples/server/petstore/go-chi-server/go/api_user_service.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ package petstoreserver
1111

1212
import (
1313
"context"
14-
"net/http"
1514
"errors"
15+
"net/http"
16+
17+
1618
)
1719

1820
// UserApiService is a service that implents the logic for the UserApiServicer

0 commit comments

Comments
 (0)