From a6c63e7968e6bcfe113c2350c4d51948eaf78806 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 24 Jun 2022 20:29:53 +0800 Subject: [PATCH] swagger init --- cmd/open_im_api/docs/docs.go | 129 +++++++++++++++++++++++------- cmd/open_im_api/docs/swagger.json | 124 +++++++++++++++++++++------- cmd/open_im_api/docs/swagger.yaml | 100 ++++++++++++++++------- internal/api/user/user.go | 16 ++-- 4 files changed, 272 insertions(+), 97 deletions(-) diff --git a/cmd/open_im_api/docs/docs.go b/cmd/open_im_api/docs/docs.go index b98043991..cea8c2481 100644 --- a/cmd/open_im_api/docs/docs.go +++ b/cmd/open_im_api/docs/docs.go @@ -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, } diff --git a/cmd/open_im_api/docs/swagger.json b/cmd/open_im_api/docs/swagger.json index 732efb5a6..a15524326 100644 --- a/cmd/open_im_api/docs/swagger.json +++ b/cmd/open_im_api/docs/swagger.json @@ -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" + } + } } } } \ No newline at end of file diff --git a/cmd/open_im_api/docs/swagger.yaml b/cmd/open_im_api/docs/swagger.yaml index 3ce9f7598..9803f031a 100644 --- a/cmd/open_im_api/docs/swagger.yaml +++ b/cmd/open_im_api/docs/swagger.yaml @@ -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" diff --git a/internal/api/user/user.go b/internal/api/user/user.go index 19acb90cb..8ce38b809 100644 --- a/internal/api/user/user.go +++ b/internal/api/user/user.go @@ -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(¶ms); err != nil {