From 14d526e033460ab5ea0d5701b2f55a74b3c69a81 Mon Sep 17 00:00:00 2001 From: DeniskaRediska Date: Mon, 10 Oct 2022 16:24:11 +0300 Subject: [PATCH] MSP-1070 update swagger --- controller/secure.go | 11 ++++ docs/docs.go | 149 +++++++++++++++++++++++++++++++------------ docs/swagger.yaml | 105 +++++++++++++++++++++--------- main.go | 2 +- 4 files changed, 196 insertions(+), 71 deletions(-) diff --git a/controller/secure.go b/controller/secure.go index 310b57d..ff46639 100644 --- a/controller/secure.go +++ b/controller/secure.go @@ -21,6 +21,17 @@ func NewSecure(service SecureService) Secure { } } +// Authenticate +// @Tags secure +// @Summary Метод аутентификации токена +// @Description Проверяет токен и возвращает идентификатор администратора +// @Accept json +// @Produce json +// @Param X-AUTH-ADMIN header string true "Токен администратора" +// @Param body body domain.SecureAuthRequest true "Тело запроса" +// @Success 200 {object} domain.SecureAuthResponse +// @Failure 500 {object} domain.GrpcError +// @Router /secure/authenticate [POST] func (s Secure) Authenticate(ctx context.Context, req domain.SecureAuthRequest) (*domain.SecureAuthResponse, error) { adminId, err := s.service.GetUserId(ctx, req.Token) switch { diff --git a/docs/docs.go b/docs/docs.go index ddfb85e..7f93bde 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -39,7 +39,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/domain.AuthRequest" + "$ref": "#/definitions/domain.LoginRequest" } } ], @@ -47,7 +47,7 @@ var doc = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.Auth" + "$ref": "#/definitions/domain.LoginResponse" } }, "400": { @@ -91,7 +91,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/domain.SudirAuthRequest" + "$ref": "#/definitions/domain.LoginSudirRequest" } } ], @@ -99,7 +99,7 @@ var doc = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.Auth" + "$ref": "#/definitions/domain.LoginResponse" } }, "401": { @@ -164,6 +164,53 @@ var doc = `{ } } }, + "/secure/authenticate": { + "post": { + "description": "Проверяет токен и возвращает идентификатор администратора", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "secure" + ], + "summary": "Метод аутентификации токена", + "parameters": [ + { + "type": "string", + "description": "Токен администратора", + "name": "X-AUTH-ADMIN", + "in": "header", + "required": true + }, + { + "description": "Тело запроса", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/domain.SecureAuthRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/domain.SecureAuthResponse" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/domain.GrpcError" + } + } + } + } + }, "/user/create_user": { "post": { "description": "Создать пользователя", @@ -521,35 +568,6 @@ var doc = `{ } } }, - "domain.Auth": { - "type": "object", - "properties": { - "expired": { - "type": "string" - }, - "headerName": { - "type": "string" - }, - "token": { - "type": "string" - } - } - }, - "domain.AuthRequest": { - "type": "object", - "required": [ - "email", - "password" - ], - "properties": { - "email": { - "type": "string" - }, - "password": { - "type": "string" - } - } - }, "domain.CreateUserRequest": { "type": "object", "required": [ @@ -613,7 +631,36 @@ var doc = `{ } } }, - "domain.SudirAuthRequest": { + "domain.LoginRequest": { + "type": "object", + "required": [ + "email", + "password" + ], + "properties": { + "email": { + "type": "string" + }, + "password": { + "type": "string" + } + } + }, + "domain.LoginResponse": { + "type": "object", + "properties": { + "expired": { + "type": "string" + }, + "headerName": { + "type": "string" + }, + "token": { + "type": "string" + } + } + }, + "domain.LoginSudirRequest": { "type": "object", "required": [ "authCode" @@ -624,6 +671,28 @@ var doc = `{ } } }, + "domain.SecureAuthRequest": { + "type": "object", + "properties": { + "token": { + "type": "string" + } + } + }, + "domain.SecureAuthResponse": { + "type": "object", + "properties": { + "adminId": { + "type": "integer" + }, + "authenticated": { + "type": "boolean" + }, + "errorReason": { + "type": "string" + } + } + }, "domain.UpdateUserRequest": { "type": "object", "required": [ @@ -653,31 +722,31 @@ var doc = `{ "domain.User": { "type": "object", "properties": { - "created_at": { + "createdAt": { "type": "string" }, "email": { "type": "string" }, - "first_name": { + "firstName": { "type": "string" }, "id": { "type": "integer" }, - "last_name": { + "lastName": { "type": "string" }, "password": { "type": "string" }, - "role_id": { + "roleId": { "type": "integer" }, - "sudir_user_id": { + "sudirUserId": { "type": "string" }, - "updated_at": { + "updatedAt": { "type": "string" } } diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 0541301..e99f8b0 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -20,25 +20,6 @@ definitions: required: - email type: object - domain.Auth: - properties: - expired: - type: string - headerName: - type: string - token: - type: string - type: object - domain.AuthRequest: - properties: - email: - type: string - password: - type: string - required: - - email - - password - type: object domain.CreateUserRequest: properties: email: @@ -80,13 +61,46 @@ definitions: required: - ids type: object - domain.SudirAuthRequest: + domain.LoginRequest: + properties: + email: + type: string + password: + type: string + required: + - email + - password + type: object + domain.LoginResponse: + properties: + expired: + type: string + headerName: + type: string + token: + type: string + type: object + domain.LoginSudirRequest: properties: authCode: type: string required: - authCode type: object + domain.SecureAuthRequest: + properties: + token: + type: string + type: object + domain.SecureAuthResponse: + properties: + adminId: + type: integer + authenticated: + type: boolean + errorReason: + type: string + type: object domain.UpdateUserRequest: properties: email: @@ -106,23 +120,23 @@ definitions: type: object domain.User: properties: - created_at: + createdAt: type: string email: type: string - first_name: + firstName: type: string id: type: integer - last_name: + lastName: type: string password: type: string - role_id: + roleId: type: integer - sudir_user_id: + sudirUserId: type: string - updated_at: + updatedAt: type: string type: object domain.UsersRequest: @@ -165,14 +179,14 @@ paths: name: body required: true schema: - $ref: '#/definitions/domain.AuthRequest' + $ref: '#/definitions/domain.LoginRequest' produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/domain.Auth' + $ref: '#/definitions/domain.LoginResponse' "400": description: Bad Request schema: @@ -199,14 +213,14 @@ paths: name: body required: true schema: - $ref: '#/definitions/domain.SudirAuthRequest' + $ref: '#/definitions/domain.LoginSudirRequest' produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/domain.Auth' + $ref: '#/definitions/domain.LoginResponse' "401": description: Некорректный код для авторизации schema: @@ -249,6 +263,37 @@ paths: summary: Выход из авторизованной сессии tags: - auth + /secure/authenticate: + post: + consumes: + - application/json + description: Проверяет токен и возвращает идентификатор администратора + parameters: + - description: Токен администратора + in: header + name: X-AUTH-ADMIN + required: true + type: string + - description: Тело запроса + in: body + name: body + required: true + schema: + $ref: '#/definitions/domain.SecureAuthRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/domain.SecureAuthResponse' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/domain.GrpcError' + summary: Метод аутентификации токена + tags: + - secure /user/create_user: post: consumes: diff --git a/main.go b/main.go index d846c72..df4e263 100644 --- a/main.go +++ b/main.go @@ -19,7 +19,7 @@ var version = "1.0.0" // @host localhost:9000 // @BasePath /api/admin -//go:generate swag init --parseDependency +//go:generate swag init //go:generate rm -f docs/swagger.json func main() {