Open feech opened 2 years ago
@wing328 - by any chance you can fix this issue? much appreciated!
@feech - I just saw your fix - is it possible you push a PR for this? thanks!
For those facing the same issue, I am using following post processing script as a workaround:
#!/usr/bin/bash
set -e
if grep -q "api_default.go" <<< "$1"; then
API_DEFAULT_GO=$1
cat < "${API_DEFAULT_GO}" | grep -v "github.com/go-chi/chi/v5" > "${API_DEFAULT_GO}.tmp"
mv "${API_DEFAULT_GO}.tmp" "${API_DEFAULT_GO}"
fi
And here is how I run the CLI via docker:
docker run --rm --user $UID:$GROUPS -v $PWD:/local -e GO_POST_PROCESS_FILE="bash /local/openapi-generator-postprocess.sh" openapitools/openapi-generator-cli generate -i /local/openapi.yaml -g go-server -o /local/target -p=onlyInterfaces=true,outputAsLibrary=true,router=chi,featureCORS=true,sourceFolder=codegen --strict-spec true --enable-post-process-file
bug is still present in 6.2.1
bug is still present in 6.2.1
I noticed that the imports gets called when I actually start to add content such as parameters to the openapi.yaml. For me it was more like little annoyance at the start. Random snippet
delete:
operationId: deleteUser
parameters:
- name: id
in: path
// DeleteUser -
func (c *DefaultApiController) DeleteUser(w http.ResponseWriter, r *http.Request) {
idParam, err := parseInt64Parameter(chi.URLParam(r, "id"), true)
Bug Report Checklist
Description
if api does not include path-parameters files "api_***.go" includes unused imports: "encoding/json" and "github.com/go-chi/chi/v5" or "github.com/gorilla/mux" (depends on selected routed)
if you remove these unused imports generated project can be compiled
openapi-generator version
5.3.0
OpenAPI declaration file content or url
https://app.swaggerhub.com/apis/acceleratedlife/alife/1.0.0
Generation Details
java -jar ./openapi-generator-cli-5.3.0.jar generate -i acceleratedLife-1.0.0-resolved.json -g go-server -o path\
Steps to reproduce
once code generated need to populate package-name in main.go and run 'go build'
compiler will show the errors:
Related issues/PRs
Suggest a fix
change a template: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/go-server/controller-api.mustache