我正在尝试为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 的官方示例,所以我怀疑代码是错误的。我应该改变什么才能让它工作?