我正在尝试使用Swagger为用Golang编写的RESTAPI创建文档。我一直遵循这个指南https://goswagger.io/generate/spec.html 来做这一点,并已经能够根据我在主文件中的注释创建json文件,但我不知道如何创建转换为实际swagger规范的.yaml文件。我遵循了页面上的说明,并在我的主文件中包含了//go:GenerateswaggerGeneratespec。有人知道如何创建.yaml文件吗?
2条回答 默认 最新
- doubo4336 2016-06-01 03:12关注
The generated spec would be json not yaml at this stage, not saying it can't be made to do yaml but currently it only generates json.
you can annotate your main package with:
//go:generate swagger generate spec -o swagger.json
then you can generate the spec with:
go generate
when you are in folder of the main package. If your main package is not your project root but something like$project_root/cmd/my-server
then you can rungo generate ./cmd/my-server
from the project root.本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报