2

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

我已经从以下位置安装了 go-swagger go get

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

请参阅下面的项目结构:

去

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

招摇规格在 product.go

// 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"
4

1 回答 1

0

我假设您正在关注 Nic 的MSA Go 教程

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

您的文档注释应如下所示

// Documentation for Product API
//
//  Schemes: http
//  BasePath: /
//  Version: 1.0.0
//
//  Consumes:
//  - application/json
//
//  Produces:
//  - application/json
//
// swagger:meta
于 2021-07-04T07:30:20.827 回答