我正在尝试为go implementation of petstore example创建一个spec文件。我在go generate
的目录中尝试了doc.go
,但没有做任何事情。在进一步阅读时,我意识到应该有
//go:generate swagger generate spec -o swagger.json
doc.go
中的。当我添加它创建一个spec文件但它不包含整个规范。这是在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": {}
}
spec文件中没有提到的路径/参数/模型。这是怎么回事?这是goswagger repo的官方示例,所以我怀疑代码是错误的。我应该改变什么才能使它发挥作用?
答案 0 :(得分:0)
您要记录的代码需要从主包中访问。这意味着从主包中它的使用需要是可检测的。 因此,如果您的工作服务器没有通过某种反射方式连接起来,那么它将生成正确的规范。