1

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

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

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

{
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],
  "schemes": [
    "http",
    "https"
  ],
  "swagger": "2.0",
  "info": {
    "description": "the purpose of this application is to provide an application\nthat is using plain go code to define an API\n\nThis should demonstrate all the possible comment annotations\nthat 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 responsibility\ngo: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 repo 的官方示例,所以我怀疑代码是错误的。我应该改变什么才能让它工作?

4

1 回答 1

0

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

于 2017-03-30T04:25:52.823 回答