【问题标题】:Empty Swagger specification is created in Go API在 Go API 中创建了 Empty Swagger 规范
【发布时间】:2020-10-24 18:58:31
【问题描述】:

我正在尝试使用从我的 API 处理程序生成 swagger 规范。

我已经从go get安装了go-swagger:

go get -u github.com/go-swagger/go-swagger/cmd/swagger

请看下面的项目结构:

main.go 使用products.go 中的处理程序定义。 (API 工作并经过测试)

product.go 中的 Swagger 规范:

// Package classification of Product API.
//
// Documenting for Product API
//
//
//
// Schemes: http, https
// BasePath: /
// Version: 0.0.1
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// swagger:meta

main.go 路径运行以下命令:

GO111MODULE=off swagger generate spec -o ./swagger.yaml --scan-models

回复:

info: {}
paths: {}
swagger: "2.0"

预期响应:

basePath: /
consumes:
- application/json
info:
  description: Documenting for Product API
  title: 
  version: 0.0.1
paths: {}
producrs:
- application/json
schemes:
- http
swagger: "2.0"

【问题讨论】:

    标签: go swagger go-swagger


    【解决方案1】:

    我假设你正在关注 Nic 的 MSA Go tutorial

    如果您还没有弄清楚问题,您忘记为内容添加空格。 (第一行和最后一行之间的行)

    您的文档注释应如下所示

    // Documentation for Product API
    //
    //  Schemes: http
    //  BasePath: /
    //  Version: 1.0.0
    //
    //  Consumes:
    //  - application/json
    //
    //  Produces:
    //  - application/json
    //
    // swagger:meta
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-21
      • 1970-01-01
      • 2021-05-26
      • 2021-02-09
      • 1970-01-01
      • 2017-12-11
      • 1970-01-01
      • 2016-12-17
      相关资源
      最近更新 更多