OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Go Server] Using integer array as in path parameter produces uncompilable code
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Using integer array in path parameter produces uncompileable code. The compiler throws "Cannot use 'idsParam' (type string) as the type []int32" for the following function. THe problem is, that the idsParam is a string array and the service function HelloworldIdsGet requires a int array.
func (c *DefaultApiController) HelloworldIdsGet(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
idsParam := params["ids"]
result, err := c.service.HelloworldIdsGet(r.Context(), idsParam)
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
}
openapi-generator version
We are using the latest version 6.0.1
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: Hello World
version: 0.0.1
paths:
/helloworld/{ids}:
get:
parameters:
- name: ids
in: path
required: true
schema:
type: array
items:
type: integer
responses:
"200":
description: OK
Generation Details
docker run --rm \
-v "${PWD}:/local" \
openapitools/openapi-generator-cli:v6.0.1 \
generate \
-g go-server \
-i /local/openapi.yaml \
-o /local
Steps to reproduce
using the yaml definition above with the generation command above produces the uncompilable code.
Suggest a fix
The string array from parameter have to convert to integer array before calling the service function.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided OpenAPI YAML and run the documented go-server Docker generation command to inspect the generated controller and service call. Verify how the path array parameter is represented, then confirm that generated code converts integer values correctly and compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, openapi
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100