添加swagger API接口文档

This commit is contained in:
yxh
2020-07-17 09:59:38 +08:00
parent 2fbd8ffc65
commit 31dbd9dee7
22 changed files with 1206 additions and 17 deletions
+321
View File
@@ -0,0 +1,321 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag
package swagger
import (
"bytes"
"encoding/json"
"strings"
"github.com/alecthomas/template"
"github.com/swaggo/swag"
)
var doc = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "{{.Description}}",
"title": "{{.Title}}",
"contact": {},
"license": {},
"version": "{{.Version}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/system/dept/addDept": {
"post": {
"security": [
{
"Bearer": []
}
],
"description": "获取JSON",
"consumes": [
"application/json"
],
"tags": [
"部门"
],
"summary": "添加部门",
"parameters": [
{
"description": "data",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/sys_dept.AddParams"
}
}
],
"responses": {
"200": {
"description": "{\"code\": 0, \"message\": \"添加成功\"}",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/system/dept/delDept/{id}": {
"delete": {
"description": "删除数据",
"tags": [
"部门"
],
"summary": "删除部门",
"parameters": [
{
"type": "integer",
"description": "id",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "{\"code\": 0, \"message\": \"删除成功\"}",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/system/dept/editDept": {
"post": {
"security": [
{
"Bearer": []
}
],
"description": "获取JSON",
"consumes": [
"application/json"
],
"tags": [
"部门"
],
"summary": "修改部门",
"parameters": [
{
"description": "data",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/sys_dept.EditParams"
}
}
],
"responses": {
"200": {
"description": "{\"code\": 0, \"message\": \"修改成功\"}",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
},
"/system/dept/list": {
"get": {
"security": [
{
"": []
}
],
"description": "分页列表",
"tags": [
"部门"
],
"summary": "分页部门列表数据",
"parameters": [
{
"type": "string",
"description": "deptName",
"name": "deptName",
"in": "query"
},
{
"type": "string",
"description": "status",
"name": "status",
"in": "query"
}
],
"responses": {
"0": {
"description": "{\"code\": 200, \"data\": [...]}",
"schema": {
"$ref": "#/definitions/response.Response"
}
}
}
}
}
},
"definitions": {
"response.Response": {
"type": "object",
"properties": {
"code": {
"description": "代码",
"type": "integer",
"example": 200
},
"data": {
"description": "数据集",
"type": "object"
},
"msg": {
"description": "消息",
"type": "string"
}
}
},
"sys_dept.AddParams": {
"type": "object",
"properties": {
"ancestors": {
"type": "string"
},
"createBy": {
"type": "string"
},
"createTime": {
"type": "string"
},
"delFlag": {
"type": "string"
},
"deptName": {
"type": "string"
},
"email": {
"type": "string"
},
"leader": {
"type": "string"
},
"orderNum": {
"type": "integer"
},
"parentId": {
"type": "integer"
},
"phone": {
"type": "string"
},
"status": {
"type": "string"
},
"updateBy": {
"type": "string"
},
"updateTime": {
"type": "string"
}
}
},
"sys_dept.EditParams": {
"type": "object",
"properties": {
"ancestors": {
"type": "string"
},
"createBy": {
"type": "string"
},
"createTime": {
"type": "string"
},
"delFlag": {
"type": "string"
},
"deptId": {
"type": "integer"
},
"deptName": {
"type": "string"
},
"email": {
"type": "string"
},
"leader": {
"type": "string"
},
"orderNum": {
"type": "integer"
},
"parentId": {
"type": "integer"
},
"phone": {
"type": "string"
},
"status": {
"type": "string"
},
"updateBy": {
"type": "string"
},
"updateTime": {
"type": "string"
}
}
}
}
}`
type swaggerInfo struct {
Version string
Host string
BasePath string
Schemes []string
Title string
Description string
}
// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = swaggerInfo{
Version: "1.0",
Host: "localhost",
BasePath: "/system",
Schemes: []string{},
Title: "gfast API文档",
Description: "gfast 在线API文档",
}
type s struct{}
func (s *s) ReadDoc() string {
sInfo := SwaggerInfo
sInfo.Description = strings.Replace(sInfo.Description, "\n", "\\n", -1)
t, err := template.New("swagger_info").Funcs(template.FuncMap{
"marshal": func(v interface{}) string {
a, _ := json.Marshal(v)
return string(a)
},
}).Parse(doc)
if err != nil {
return doc
}
var tpl bytes.Buffer
if err := t.Execute(&tpl, sInfo); err != nil {
return doc
}
return tpl.String()
}
func init() {
swag.Register(swag.Name, &s{})
}