OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.77k stars 6.57k forks source link

[BUG][GO] imported and not used compilation error #5153

Open adrienzieba opened 4 years ago

adrienzieba commented 4 years ago

Bug Report Checklist

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
  1. Generate code
  2. 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.

talevy-runai commented 1 year ago

Hi, is this issue solved?