swagger init

pull/236/head
wangchuxiao 3 years ago
parent 79b1a801b5
commit a6c63e7968

@ -10,72 +10,139 @@ const docTemplate = `{
"info": { "info": {
"description": "{{escape .Description}}", "description": "{{escape .Description}}",
"title": "{{.Title}}", "title": "{{.Title}}",
"termsOfService": "http://swagger.io/terms/", "contact": {},
"contact": {
"name": "API Support",
"url": "http://www.swagger.io/support",
"email": "support@swagger.io"
},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
},
"version": "{{.Version}}" "version": "{{.Version}}"
}, },
"host": "{{.Host}}", "host": "{{.Host}}",
"basePath": "{{.BasePath}}", "basePath": "{{.BasePath}}",
"paths": { "paths": {
"/hello": { "/user/update_user_info": {
"get": { "post": {
"description": "向你说Hello", "description": "修改用户信息 userID faceURL等",
"consumes": [ "consumes": [
"application/json" "application/json"
], ],
"produces": [
"application/json"
],
"tags": [ "tags": [
"测试" "用户信息"
], ],
"summary": "测试SayHello", "summary": "修改用户信息",
"operationId": "UpdateUserInfo",
"parameters": [ "parameters": [
{ {
"type": "string", "type": "string",
"description": "人名", "description": "im token",
"name": "who", "name": "token",
"in": "query", "in": "header",
"required": true "required": true
},
{
"description": "请求",
"name": "req",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/base_info.UpdateSelfUserInfoReq"
}
} }
], ],
"responses": { "responses": {
"200": { "0": {
"description": "{\"msg\": \"hello Razeen\"}", "description": "",
"schema": { "schema": {
"type": "string" "$ref": "#/definitions/base_info.UpdateUserInfoResp"
} }
}, },
"400": { "400": {
"description": "{\"msg\": \"who are you\"}", "description": "errCode为400 一般为参数输入错误, token未带上等",
"schema": { "schema": {
"type": "string" "$ref": "#/definitions/base_info.UpdateUserInfoResp"
}
},
"500": {
"description": "errCode为500 一般为服务器内部错误",
"schema": {
"$ref": "#/definitions/base_info.UpdateUserInfoResp"
} }
} }
} }
} }
} }
}, },
"securityDefinitions": { "definitions": {
"BasicAuth": { "base_info.UpdateSelfUserInfoReq": {
"type": "basic" "type": "object",
"required": [
"operationID",
"userID"
],
"properties": {
"birth": {
"type": "integer"
},
"email": {
"type": "string",
"maxLength": 64
},
"ex": {
"type": "string",
"maxLength": 1024
},
"faceURL": {
"type": "string",
"maxLength": 1024
},
"gender": {
"type": "integer",
"enum": [
0,
1,
2
]
},
"nickname": {
"type": "string",
"maxLength": 64,
"minLength": 1
},
"operationID": {
"type": "string"
},
"phoneNumber": {
"type": "string",
"maxLength": 32
},
"userID": {
"type": "string",
"maxLength": 64,
"minLength": 1
}
}
},
"base_info.UpdateUserInfoResp": {
"type": "object",
"properties": {
"errCode": {
"type": "integer"
},
"errMsg": {
"type": "string"
}
}
} }
} }
}` }`
// SwaggerInfo holds exported Swagger Info so clients can modify it // SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{ var SwaggerInfo = &swag.Spec{
Version: "1.0", Version: "",
Host: "localhost:8080", Host: "",
BasePath: "/api/v1", BasePath: "",
Schemes: []string{}, Schemes: []string{},
Title: "Swagger Example API", Title: "",
Description: "This is a sample server celler server.", Description: "",
InfoInstanceName: "swagger", InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate, SwaggerTemplate: docTemplate,
} }

@ -1,62 +1,124 @@
{ {
"swagger": "2.0", "swagger": "2.0",
"info": { "info": {
"description": "This is a sample server celler server.", "contact": {}
"title": "Swagger Example API",
"termsOfService": "http://swagger.io/terms/",
"contact": {
"name": "API Support",
"url": "http://www.swagger.io/support",
"email": "support@swagger.io"
},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
},
"version": "1.0"
}, },
"host": "localhost:8080",
"basePath": "/api/v1",
"paths": { "paths": {
"/hello": { "/user/update_user_info": {
"get": { "post": {
"description": "向你说Hello", "description": "修改用户信息 userID faceURL等",
"consumes": [ "consumes": [
"application/json" "application/json"
], ],
"produces": [
"application/json"
],
"tags": [ "tags": [
"测试" "用户信息"
], ],
"summary": "测试SayHello", "summary": "修改用户信息",
"operationId": "UpdateUserInfo",
"parameters": [ "parameters": [
{ {
"type": "string", "type": "string",
"description": "人名", "description": "im token",
"name": "who", "name": "token",
"in": "query", "in": "header",
"required": true "required": true
},
{
"description": "请求",
"name": "req",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/base_info.UpdateSelfUserInfoReq"
}
} }
], ],
"responses": { "responses": {
"200": { "0": {
"description": "{\"msg\": \"hello Razeen\"}", "description": "",
"schema": { "schema": {
"type": "string" "$ref": "#/definitions/base_info.UpdateUserInfoResp"
} }
}, },
"400": { "400": {
"description": "{\"msg\": \"who are you\"}", "description": "errCode为400 一般为参数输入错误, token未带上等",
"schema": { "schema": {
"type": "string" "$ref": "#/definitions/base_info.UpdateUserInfoResp"
}
},
"500": {
"description": "errCode为500 一般为服务器内部错误",
"schema": {
"$ref": "#/definitions/base_info.UpdateUserInfoResp"
} }
} }
} }
} }
} }
}, },
"securityDefinitions": { "definitions": {
"BasicAuth": { "base_info.UpdateSelfUserInfoReq": {
"type": "basic" "type": "object",
"required": [
"operationID",
"userID"
],
"properties": {
"birth": {
"type": "integer"
},
"email": {
"type": "string",
"maxLength": 64
},
"ex": {
"type": "string",
"maxLength": 1024
},
"faceURL": {
"type": "string",
"maxLength": 1024
},
"gender": {
"type": "integer",
"enum": [
0,
1,
2
]
},
"nickname": {
"type": "string",
"maxLength": 64,
"minLength": 1
},
"operationID": {
"type": "string"
},
"phoneNumber": {
"type": "string",
"maxLength": 32
},
"userID": {
"type": "string",
"maxLength": 64,
"minLength": 1
}
}
},
"base_info.UpdateUserInfoResp": {
"type": "object",
"properties": {
"errCode": {
"type": "integer"
},
"errMsg": {
"type": "string"
}
}
} }
} }
} }

@ -1,42 +1,84 @@
basePath: /api/v1 definitions:
host: localhost:8080 base_info.UpdateSelfUserInfoReq:
properties:
birth:
type: integer
email:
maxLength: 64
type: string
ex:
maxLength: 1024
type: string
faceURL:
maxLength: 1024
type: string
gender:
enum:
- 0
- 1
- 2
type: integer
nickname:
maxLength: 64
minLength: 1
type: string
operationID:
type: string
phoneNumber:
maxLength: 32
type: string
userID:
maxLength: 64
minLength: 1
type: string
required:
- operationID
- userID
type: object
base_info.UpdateUserInfoResp:
properties:
errCode:
type: integer
errMsg:
type: string
type: object
info: info:
contact: contact: {}
email: support@swagger.io
name: API Support
url: http://www.swagger.io/support
description: This is a sample server celler server.
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
termsOfService: http://swagger.io/terms/
title: Swagger Example API
version: "1.0"
paths: paths:
/hello: /user/update_user_info:
get: post:
consumes: consumes:
- application/json - application/json
description: 向你说Hello description: 修改用户信息 userID faceURL等
operationId: UpdateUserInfo
parameters: parameters:
- description: 人名 - description: im token
in: query in: header
name: who name: token
required: true required: true
type: string type: string
- description: 请求
in: body
name: req
required: true
schema:
$ref: '#/definitions/base_info.UpdateSelfUserInfoReq'
produces:
- application/json
responses: responses:
"200": "0":
description: '{"msg": "hello Razeen"}' description: ""
schema: schema:
type: string $ref: '#/definitions/base_info.UpdateUserInfoResp'
"400": "400":
description: '{"msg": "who are you"}' description: errCode为400 一般为参数输入错误, token未带上等
schema:
$ref: '#/definitions/base_info.UpdateUserInfoResp'
"500":
description: errCode为500 一般为服务器内部错误
schema: schema:
type: string $ref: '#/definitions/base_info.UpdateUserInfoResp'
summary: 测试SayHello summary: 修改用户信息
tags: tags:
- 测试 - 用户信息
securityDefinitions:
BasicAuth:
type: basic
swagger: "2.0" swagger: "2.0"

@ -196,13 +196,17 @@ func GetUsersInfo(c *gin.Context) {
} }
// @Summary 修改用户信息 // @Summary 修改用户信息
// @Description 修改用户信息 // @Description 修改用户信息 userID faceURL等
// @Tags 修改用户信息 // @Tags 用户信息
// @ID UpdateUserInfo
// @Accept json // @Accept json
// @Param who query string true "人名" // @Param token header string true "im token"
// @Success 200 {string} string "{"msg": "hello Razeen"}" // @Param req body api.UpdateSelfUserInfoReq true "请求"
// @Failure 400 {string} string "{"msg": "who are you"}" // @Produce json
// @Router /update_user_info [post] // @Success 0 {object} api.UpdateUserInfoResp
// @Failure 500 {object} api.UpdateUserInfoResp "errCode为500 一般为服务器内部错误"
// @Failure 400 {object} api.UpdateUserInfoResp "errCode为400 一般为参数输入错误, token未带上等"
// @Router /user/update_user_info [post]
func UpdateUserInfo(c *gin.Context) { func UpdateUserInfo(c *gin.Context) {
params := api.UpdateSelfUserInfoReq{} params := api.UpdateSelfUserInfoReq{}
if err := c.BindJSON(&params); err != nil { if err := c.BindJSON(&params); err != nil {

Loading…
Cancel
Save