doushou3814 2016-06-01 00:17 采纳率: 100%
浏览 2646
已采纳

使用golang注释生成Swagger规范

我正在尝试使用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 run go generate ./cmd/my-server from the project root.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?