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.91k stars 6.58k forks source link

[BUG][GO] generated go code not not formatted properly #4031

Open Fjolnir-Dvorak opened 5 years ago

Fjolnir-Dvorak commented 5 years ago

Bug Report Checklist

Description

The generated code does not follow the go coding standards (go fmt)

openapi-generator version

commit c136b83bdb5e56ddb297de7f0d5bb9af447a9e54 (latest commit on master on 2019-10-02T15:27:00)

Steps to reproduce
cd ./samples/client/petstore/go
cd ./go-petstore
go fmt ./*
cd ../go-petstore-withXml
go fmt ./*
cd ../../../../server/petstore/go-gin-api-server
go fmt ./*
Suggest a fix

Correct all mustache templates and add a test for the build servers which runs "go fmt" and checks if there are any changed files. If yes, the test should fail.

wing328 commented 5 years ago

You can use file post-processing to format the code using your favorite code formatter.

Run ./bin/go-petstore.sh and you will see the following output:

[main] INFO  o.o.c.languages.AbstractGoCodegen - Environment variable GO_POST_PROCESS_FILE not defined so Go code may not be properly formatted. To define it, try `export GO_POST_PROCESS_FILE="/usr/local/bin/gofmt -w"` (Linux/Mac)
[main] INFO  o.o.c.languages.AbstractGoCodegen - NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).