我按照这个 github 页面https://github.com/yvasiyarov/swagger上的说明使用示例项目和生成的 api 文档。但是当我运行最后一个命令来运行并显示 API 页面时,当我去那里时,我总是得到 404 not found
web.go 文件本质上是https://github.com/yvasiyarov/swagger/blob/master/web.go-example。它基本上是 repo 中 web.go-example 的副本......我不明白为什么它会返回 404。
另外,您对类似的更好的 api 文档生成器有什么建议吗?我不想要像https://github.com/go-swagger/go-swagger这样的代码生成器。我想根据我现有的代码生成 api
这是生成的 docs.go
package main
//This file is generated automatically. Do not try to edit it manually.
var resourceListingJson = `{
"apiVersion": "1.0.0",
"swaggerVersion": "1.2",
"basePath": "http://127.0.0.1:3000/",
"apis": [
{
"path": "/testapi",
"description": "Test API"
}
],
"info": {
"title": "Swagger Example API",
"description": "Swagger Example API",
"contact": "varyous@gmail.com",
"termsOfServiceUrl": "http://yvasiyarov.com/",
"license": "BSD",
"licenseUrl": "http://yvasiyarov.com/"
}
}`
var apiDescriptionsJson = map[string]string{"testapi":`{
"apiVersion": "1.0.0",
"swaggerVersion": "1.2",
"basePath": "http://127.0.0.1:3000/",
"resourcePath": "/testapi",
"produces": [
"application/json"
],
"apis": [
{
"path": "/testapi/get-string-by-int/{some_id}",
"description": "get string by ID",
"operations": [
{
"httpMethod": "GET",
"nickname": "GetStringByInt",
"type": "string",
"items": {},
"summary": "get string by ID",
"parameters": [
{
"paramType": "path",
"name": "some_id",
"description": "Some ID",
"dataType": "int",
"type": "int",
"format": "",
"allowMultiple": false,
"required": true,
"minimum": 0,
"maximum": 0
}
],
"responseMessages": [
{
"code": 200,
"message": "",
"responseType": "object",
"responseModel": "string"
},
{
"code": 400,
"message": "We need ID!!",
"responseType": "object",
"responseModel": "git.corp.adobe.com.personal.test1.APIError"
},
{
"code": 404,
"message": "Can not find ID",
"responseType": "object",
"responseModel": "git.corp.adobe.com.personal.test1.APIError"
}
],
"produces": [
"application/json"
]
}
]
},
{
"path": "/testapi/get-struct-by-int/{some_id}",
"description": "get struct by ID",
"operations": [
{
"httpMethod": "GET",
"nickname": "GetStructByInt",
"type": "git.corp.adobe.com.personal.test1.StructureWithEmbededStructure",
"items": {},
"summary": "get struct by ID",
"parameters": [
{
"paramType": "path",
"name": "some_id",
"description": "Some ID",
"dataType": "int",
"type": "int",
"format": "",
"allowMultiple": false,
"required": true,
"minimum": 0,
"maximum": 0
},
{
"paramType": "query",
"name": "offset",
"description": "Offset",
"dataType": "int",
"type": "int",
"format": "",
"allowMultiple": false,
"required": true,
"minimum": 0,
"maximum": 0
},
{
"paramType": "query",
"name": "limit",
"description": "Offset",
"dataType": "int",
"type": "int",
"format": "",
"allowMultiple": false,
"required": true,
"minimum": 0,
"maximum": 0
}
],
"responseMessages": [
{
"code": 200,
"message": "",
"responseType": "object",
"responseModel": "git.corp.adobe.com.personal.test1.StructureWithEmbededStructure"
},
{
"code": 400,
"message": "We need ID!!",
"responseType": "object",
"responseModel": "git.corp.adobe.com.personal.test1.APIError"
},
{
"code": 404,
"message": "Can not find ID",
"responseType": "object",
"responseModel": "git.corp.adobe.com.personal.test1.APIError"
}
],
"produces": [
"application/json"
]
}
]
},
{
"path": "/testapi/get-struct2-by-int/{some_id}",
"description": "get struct2 by ID",
"operations": [
{
"httpMethod": "GET",
"nickname": "GetStruct2ByInt",
"type": "git.corp.adobe.com.personal.test1.StructureWithEmbededPointer",
"items": {},
"summary": "get struct2 by ID",
"parameters": [
{
"paramType": "path",
"name": "some_id",
"description": "Some ID",
"dataType": "int",
"type": "int",
"format": "",
"allowMultiple": false,
"required": true,
"minimum": 0,
"maximum": 0
},
{
"paramType": "query",
"name": "offset",
"description": "Offset",
"dataType": "int",
"type": "int",
"format": "",
"allowMultiple": false,
"required": true,
"minimum": 0,
"maximum": 0
},
{
"paramType": "query",
"name": "limit",
"description": "Offset",
"dataType": "int",
"type": "int",
"format": "",
"allowMultiple": false,
"required": true,
"minimum": 0,
"maximum": 0
}
],
"responseMessages": [
{
"code": 200,
"message": "",
"responseType": "object",
"responseModel": "git.corp.adobe.com.personal.test1.StructureWithEmbededPointer"
},
{
"code": 400,
"message": "We need ID!!",
"responseType": "object",
"responseModel": "git.corp.adobe.com.personal.test1.APIError"
},
{
"code": 404,
"message": "Can not find ID",
"responseType": "object",
"responseModel": "git.corp.adobe.com.personal.test1.APIError"
}
],
"produces": [
"application/json"
]
}
]
},
{
"path": "/testapi/get-simple-array-by-string/{some_id}",
"description": "get simple array by ID",
"operations": [
{
"httpMethod": "GET",
"nickname": "GetSimpleArrayByString",
"type": "array",
"items": {
"type": "string"
},
"summary": "get simple array by ID",
"parameters": [
{
"paramType": "path",
"name": "some_id",
"description": "Some ID",
"dataType": "string",
"type": "string",
"format": "",
"allowMultiple": false,
"required": true,
"minimum": 0,
"maximum": 0
},
{
"paramType": "query",
"name": "offset",
"description": "Offset",
"dataType": "int",
"type": "int",
"format": "",
"allowMultiple": false,
"required": true,
"minimum": 0,
"maximum": 0
},
{
"paramType": "query",
"name": "limit",
"description": "Offset",
"dataType": "int",
"type": "int",
"format": "",
"allowMultiple": false,
"required": true,
"minimum": 0,
"maximum": 0
}
],
"responseMessages": [
{
"code": 200,
"message": "",
"responseType": "array",
"responseModel": "string"
},
{
"code": 400,
"message": "We need ID!!",
"responseType": "object",
"responseModel": "git.corp.adobe.com.personal.test1.APIError"
},
{
"code": 404,
"message": "Can not find ID",
"responseType": "object",
"responseModel": "git.corp.adobe.com.personal.test1.APIError"
}
],
"produces": [
"application/json"
]
}
]
},
{
"path": "/testapi/get-struct-array-by-string/{some_id}",
"description": "get struct array by ID",
"operations": [
{
"httpMethod": "GET",
"nickname": "GetStructArrayByString",
"type": "array",
"items": {
"$ref": "git.corp.adobe.com.personal.test1.SimpleStructureWithAnnotations"
},
"summary": "get struct array by ID",
"parameters": [
{
"paramType": "path",
"name": "some_id",
"description": "Some ID",
"dataType": "string",
"type": "string",
"format": "",
"allowMultiple": false,
"required": true,
"minimum": 0,
"maximum": 0
},
{
"paramType": "query",
"name": "offset",
"description": "Offset",
"dataType": "int",
"type": "int",
"format": "",
"allowMultiple": false,
"required": true,
"minimum": 0,
"maximum": 0
},
{
"paramType": "query",
"name": "limit",
"description": "Offset",
"dataType": "int",
"type": "int",
"format": "",
"allowMultiple": false,
"required": true,
"minimum": 0,
"maximum": 0
}
],
"responseMessages": [
{
"code": 200,
"message": "",
"responseType": "array",
"responseModel": "git.corp.adobe.com.personal.test1.SimpleStructureWithAnnotations"
},
{
"code": 400,
"message": "We need ID!!",
"responseType": "object",
"responseModel": "git.corp.adobe.com.personal.test1.APIError"
},
{
"code": 404,
"message": "Can not find ID",
"responseType": "object",
"responseModel": "git.corp.adobe.com.personal.test1.APIError"
}
],
"produces": [
"application/json"
]
}
]
},
{
"path": "/testapi/get-interface",
"description": "get interface",
"operations": [
{
"httpMethod": "GET",
"nickname": "GetInterface",
"type": "git.corp.adobe.com.personal.test1.InterfaceType",
"items": {},
"summary": "get interface",
"responseMessages": [
{
"code": 200,
"message": "",
"responseType": "object",
"responseModel": "git.corp.adobe.com.personal.test1.InterfaceType"
},
{
"code": 400,
"message": "We need ID!!",
"responseType": "object",
"responseModel": "git.corp.adobe.com.personal.test1.APIError"
},
{
"code": 404,
"message": "Can not find ID",
"responseType": "object",
"responseModel": "git.corp.adobe.com.personal.test1.APIError"
}
],
"produces": [
"application/json"
]
}
]
},
{
"path": "/testapi/get-simple-aliased",
"description": "get simple aliases",
"operations": [
{
"httpMethod": "GET",
"nickname": "GetSimpleAliased",
"type": "string",
"items": {},
"summary": "get simple aliases",
"responseMessages": [
{
"code": 200,
"message": "",
"responseType": "object",
"responseModel": "string"
},
{
"code": 400,
"message": "We need ID!!",
"responseType": "object",
"responseModel": "git.corp.adobe.com.personal.test1.APIError"
},
{
"code": 404,
"message": "Can not find ID",
"responseType": "object",
"responseModel": "git.corp.adobe.com.personal.test1.APIError"
}
],
"produces": [
"application/json"
]
}
]
},
{
"path": "/testapi/get-array-of-interfaces",
"description": "get array of interfaces",
"operations": [
{
"httpMethod": "GET",
"nickname": "GetArrayOfInterfaces",
"type": "array",
"items": {
"$ref": "git.corp.adobe.com.personal.test1.InterfaceType"
},
"summary": "get array of interfaces",
"responseMessages": [
{
"code": 200,
"message": "",
"responseType": "array",
"responseModel": "git.corp.adobe.com.personal.test1.InterfaceType"
},
{
"code": 400,
"message": "We need ID!!",
"responseType": "object",
"responseModel": "git.corp.adobe.com.personal.test1.APIError"
},
{
"code": 404,
"message": "Can not find ID",
"responseType": "object",
"responseModel": "git.corp.adobe.com.personal.test1.APIError"
}
],
"produces": [
"application/json"
]
}
]
},
{
"path": "/testapi/get-struct3",
"description": "get struct3",
"operations": [
{
"httpMethod": "GET",
"nickname": "GetStruct3",
"type": "git.corp.adobe.com.personal.test1.StructureWithSlice",
"items": {},
"summary": "get struct3",
"responseMessages": [
{
"code": 200,
"message": "",
"responseType": "object",
"responseModel": "git.corp.adobe.com.personal.test1.StructureWithSlice"
},
{
"code": 400,
"message": "We need ID!!",
"responseType": "object",
"responseModel": "git.corp.adobe.com.personal.test1.APIError"
},
{
"code": 404,
"message": "Can not find ID",
"responseType": "object",
"responseModel": "git.corp.adobe.com.personal.test1.APIError"
}
],
"produces": [
"application/json"
]
}
]
}
],
"models": {
"git.corp.adobe.com.personal.test1.APIError": {
"id": "git.corp.adobe.com.personal.test1.APIError",
"properties": {
"ErrorCode": {
"type": "int",
"description": "",
"items": {},
"format": ""
},
"ErrorMessage": {
"type": "string",
"description": "",
"items": {},
"format": ""
}
}
},
"git.corp.adobe.com.personal.test1.InterfaceType": {
"id": "git.corp.adobe.com.personal.test1.InterfaceType",
"properties": null
},
"git.corp.adobe.com.personal.test1.SimpleStructureWithAnnotations": {
"id": "git.corp.adobe.com.personal.test1.SimpleStructureWithAnnotations",
"required": [
"Name"
],
"properties": {
"Name": {
"type": "string",
"description": "",
"items": {},
"format": ""
},
"id": {
"type": "int",
"description": "",
"items": {},
"format": ""
}
}
},
"git.corp.adobe.com.personal.test1.StructureWithEmbededPointer": {
"id": "git.corp.adobe.com.personal.test1.StructureWithEmbededPointer",
"properties": {
"Id": {
"type": "int",
"description": "",
"items": {},
"format": ""
},
"Name": {
"type": "array",
"description": "",
"items": {
"type": "byte"
},
"format": ""
}
}
},
"git.corp.adobe.com.personal.test1.StructureWithEmbededStructure": {
"id": "git.corp.adobe.com.personal.test1.StructureWithEmbededStructure",
"properties": {
"Id": {
"type": "int",
"description": "",
"items": {},
"format": ""
},
"Name": {
"type": "array",
"description": "",
"items": {
"type": "byte"
},
"format": ""
}
}
},
"git.corp.adobe.com.personal.test1.StructureWithSlice": {
"id": "git.corp.adobe.com.personal.test1.StructureWithSlice",
"properties": {
"Id": {
"type": "int",
"description": "",
"items": {},
"format": ""
},
"Name": {
"type": "array",
"description": "",
"items": {
"type": "byte"
},
"format": ""
}
}
}
}
}`,}