swagger init

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

@ -10,72 +10,139 @@ const docTemplate = `{
"info": {
"description": "{{escape .Description}}",
"title": "{{.Title}}",
"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"
},
"contact": {},
"version": "{{.Version}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/hello": {
"get": {
"description": "向你说Hello",
"/user/update_user_info": {
"post": {
"description": "修改用户信息 userID faceURL等",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"测试"
"用户信息"
],
"summary": "测试SayHello",
"summary": "修改用户信息",
"operationId": "UpdateUserInfo",
"parameters": [
{
"type": "string",
"description": "人名",
"name": "who",
"in": "query",
"description": "im token",
"name": "token",
"in": "header",
"required": true
},
{
"description": "请求",
"name": "req",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/base_info.UpdateSelfUserInfoReq"
}
}
],
"responses": {
"200": {
"description": "{\"msg\": \"hello Razeen\"}",
"0": {
"description": "",
"schema": {
"type": "string"
"$ref": "#/definitions/base_info.UpdateUserInfoResp"
}
},
"400": {
"description": "{\"msg\": \"who are you\"}",
"description": "errCode为400 一般为参数输入错误, token未带上等",
"schema": {
"type": "string"
"$ref": "#/definitions/base_info.UpdateUserInfoResp"
}
},
"500": {
"description": "errCode为500 一般为服务器内部错误",
"schema": {
"$ref": "#/definitions/base_info.UpdateUserInfoResp"
}
}
}
}
}
},
"securityDefinitions": {
"BasicAuth": {
"type": "basic"
"definitions": {
"base_info.UpdateSelfUserInfoReq": {
"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
var SwaggerInfo = &swag.Spec{
Version: "1.0",
Host: "localhost:8080",
BasePath: "/api/v1",
Version: "",
Host: "",
BasePath: "",
Schemes: []string{},
Title: "Swagger Example API",
Description: "This is a sample server celler server.",
Title: "",
Description: "",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
}

@ -1,62 +1,124 @@
{
"swagger": "2.0",
"info": {
"description": "This is a sample server celler server.",
"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"
"contact": {}
},
"host": "localhost:8080",
"basePath": "/api/v1",
"paths": {
"/hello": {
"get": {
"description": "向你说Hello",
"/user/update_user_info": {
"post": {
"description": "修改用户信息 userID faceURL等",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"测试"
"用户信息"
],
"summary": "测试SayHello",
"summary": "修改用户信息",
"operationId": "UpdateUserInfo",
"parameters": [
{
"type": "string",
"description": "人名",
"name": "who",
"in": "query",
"description": "im token",
"name": "token",
"in": "header",
"required": true
},
{
"description": "请求",
"name": "req",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/base_info.UpdateSelfUserInfoReq"
}
}
],
"responses": {
"200": {
"description": "{\"msg\": \"hello Razeen\"}",
"0": {
"description": "",
"schema": {
"type": "string"
"$ref": "#/definitions/base_info.UpdateUserInfoResp"
}
},
"400": {
"description": "{\"msg\": \"who are you\"}",
"description": "errCode为400 一般为参数输入错误, token未带上等",
"schema": {
"type": "string"
"$ref": "#/definitions/base_info.UpdateUserInfoResp"
}
},
"500": {
"description": "errCode为500 一般为服务器内部错误",
"schema": {
"$ref": "#/definitions/base_info.UpdateUserInfoResp"
}
}
}
}
}
},
"securityDefinitions": {
"BasicAuth": {
"type": "basic"
"definitions": {
"base_info.UpdateSelfUserInfoReq": {
"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
host: localhost:8080
definitions:
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:
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"
contact: {}
paths:
/hello:
get:
/user/update_user_info:
post:
consumes:
- application/json
description: 向你说Hello
description: 修改用户信息 userID faceURL等
operationId: UpdateUserInfo
parameters:
- description: 人名
in: query
name: who
- description: im token
in: header
name: token
required: true
type: string
- description: 请求
in: body
name: req
required: true
schema:
$ref: '#/definitions/base_info.UpdateSelfUserInfoReq'
produces:
- application/json
responses:
"200":
description: '{"msg": "hello Razeen"}'
"0":
description: ""
schema:
type: string
$ref: '#/definitions/base_info.UpdateUserInfoResp'
"400":
description: '{"msg": "who are you"}'
description: errCode为400 一般为参数输入错误, token未带上等
schema:
$ref: '#/definitions/base_info.UpdateUserInfoResp'
"500":
description: errCode为500 一般为服务器内部错误
schema:
type: string
summary: 测试SayHello
$ref: '#/definitions/base_info.UpdateUserInfoResp'
summary: 修改用户信息
tags:
- 测试
securityDefinitions:
BasicAuth:
type: basic
- 用户信息
swagger: "2.0"

@ -196,13 +196,17 @@ func GetUsersInfo(c *gin.Context) {
}
// @Summary 修改用户信息
// @Description 修改用户信息
// @Tags 修改用户信息
// @Description 修改用户信息 userID faceURL等
// @Tags 用户信息
// @ID UpdateUserInfo
// @Accept json
// @Param who query string true "人名"
// @Success 200 {string} string "{"msg": "hello Razeen"}"
// @Failure 400 {string} string "{"msg": "who are you"}"
// @Router /update_user_info [post]
// @Param token header string true "im token"
// @Param req body api.UpdateSelfUserInfoReq true "请求"
// @Produce json
// @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) {
params := api.UpdateSelfUserInfoReq{}
if err := c.BindJSON(&params); err != nil {

Loading…
Cancel
Save