Goswagger没有创建适当的json规范文件



我正在尝试为宠物商店示例的go实现创建一个规范文件。我在目录中尝试了一个doc.go go generate,但它什么也没做。在进一步阅读时,我意识到应该有

//go:generate swagger generate spec -o swagger.json

doc.go.当我添加它创建一个规范文件时,它不包含整个规范。这是在 go generate 上创建的 .json 文件

{
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],
  "schemes": [
    "http",
    "https"
  ],
  "swagger": "2.0",
  "info": {
    "description": "the purpose of this application is to provide an applicationnthat is using plain go code to define an APInnThis should demonstrate all the possible comment annotationsnthat are available to turn go code into a fully compliant swagger 2.0 spec",
    "title": "Petstore API.",
    "termsOfService": "there are no TOS at this moment, use at your own risk we take no responsibilityngo:generate swagger generate spec -o swagger.json",
    "contact": {
      "name": "John Doe",
      "url": "http://john.doe.com",
      "email": "john.doe@example.com"
    },
    "license": {
      "name": "MIT",
      "url": "http://opensource.org/licenses/MIT"
    },
    "version": "0.0.1"
  },
  "host": "localhost",
  "basePath": "/v2",
  "paths": {}
}

规范文件中没有提到路线/参数/模型。这是应该的吗?这是来自goswagger存储库的官方示例,所以我怀疑代码是错误的。我应该更改什么才能使其正常工作?

要记录的代码需要可从主包访问。这意味着从主包中需要检测到它的使用情况。因此,如果你有一个工作服务器,它没有通过某种反射方式连接,它将生成正确的规范。

最新更新