OpenAPITools / OpenAPITools/openapi-generator
[BUG][GO] imported and not used compilation error
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)?
- What's the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
If a controller have all its operations without Path Param or Body Param, generated code has unused import and compilation will fail.
openapi_gen/api_user.go:13:2: imported and not used: "encoding/json"
openapi_gen/api_user.go:17:2: imported and not used: "github.com/gorilla/mux"
openapi-generator version
docker openapitools/openapi-generator-cli:v4.2.2
OpenAPI declaration file content or url
/one/endpoint:
get:
tags:
- one
summary: summary
description: description
operationId: getInfo
responses:
'204':
description: successful operation
Command line used for generation
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:v4.2.2 generate -i /local/specs.yaml -p sourceFolder=openapi_gen -g go-server -o /local
Steps to reproduce
- Generate code
- build the generated code
Related issues/PRs
Suggest a fix
On my side, I fixed the issue by running goimports after the generation of the code. Maybe we could run something similar directly inside openapi-generator-cli.
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
Reproduce with the Docker v4.2.2 command and the minimal OpenAPI declaration, then build the generated go-server output. Start with openapi_gen/api_user.go and the Go server generator entry point; done means a controller with no path or body parameters builds without unused-import errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100