doula4096 2017-02-15 13:36
浏览 272

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

I am trying to create a spec file for the go implementation of petstore example . I tried a go generate in the directory which had doc.go but it did nothing. On further reading, I realised that there should be

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

in doc.go . When I added that it creates a spec file but it doesn't contain the entire specification. This is the .json file that is create on 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
that is using plain go code to define an API

This should demonstrate all the possible comment annotations
that 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
go: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": {}
}

There are no routes/parameters/models mentioned in the spec file. Is this how this is supposed to be? This is an official example from the goswagger repo so I doubt the code is wrong. What should I change to make it work?

  • 写回答

1条回答 默认 最新

  • dsfsad089111 2017-03-30 04:25
    关注

    The code you want to document needs to be reachable from your main package. That means from the main package its usage needs to be detectable. So if you have a working server that isn't hooked up through some means of reflection it will generate the right specification.

    评论

报告相同问题?

悬赏问题

  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答