【问题标题】:Goswagger not creating appropriate json spec fileGoswagger 没有创建适当的 json 规范文件
【发布时间】:2017-02-15 13:36:27
【问题描述】:

我正在尝试为 go implementation of petstore example 创建规范文件。我在具有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 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": {}
}

spec 文件中没有提到路由/参数/模型。这是应该的吗?这是来自 goswagger repo 的官方示例,所以我怀疑代码是错误的。我应该改变什么才能让它工作?

【问题讨论】:

    标签: go swagger go-swagger


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-16
      • 2013-10-25
      • 1970-01-01
      • 1970-01-01
      • 2012-09-17
      • 2021-01-27
      • 2021-12-24
      • 2012-04-16
      相关资源
      最近更新 更多