Generating Swagger spec with golang comments

前端 未结 2 1628
野趣味
野趣味 2021-01-12 00:14

I am trying to create documentation for my REST API written in golang using Swagger. I have been following this guide: https://goswagger.io/generate/spec.html to do so and h

相关标签:
2条回答
  • 2021-01-12 00:42

    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.

    0 讨论(0)
  • 2021-01-12 01:05

    Yes, you can create a YAML file. Following an example.

    swagger generate spec -m -o ../../api/swagger.yaml
    

    Also, feel free to check the Blog Post.

    0 讨论(0)
提交回复
热议问题