From 9fdbc87faadd2f59b3f6ad5bc84afcdead1ba2ed Mon Sep 17 00:00:00 2001 From: kolaente Date: Fri, 18 Dec 2020 11:47:53 +0100 Subject: [PATCH] Add swagger docs --- .../microsoft-todo/microsoft_todo.go | 29 +++++ pkg/swagger/docs.go | 115 ++++++++++++++++++ pkg/swagger/swagger.json | 115 ++++++++++++++++++ pkg/swagger/swagger.yaml | 71 +++++++++++ 4 files changed, 330 insertions(+) diff --git a/pkg/modules/migration/microsoft-todo/microsoft_todo.go b/pkg/modules/migration/microsoft-todo/microsoft_todo.go index 09c120fad..693ff829e 100644 --- a/pkg/modules/migration/microsoft-todo/microsoft_todo.go +++ b/pkg/modules/migration/microsoft-todo/microsoft_todo.go @@ -119,6 +119,15 @@ func (dtt *dateTimeTimeZone) toTime() (t time.Time, err error) { return time.ParseInLocation(time.RFC3339Nano, dtt.DateTime+"Z", loc) } +// AuthURL returns the url users need to authenticate against +// @Summary Get the auth url from Microsoft Todo +// @Description Returns the auth url where the user needs to get its auth code. This code can then be used to migrate everything from Microsoft Todo to Vikunja. +// @tags migration +// @Produce json +// @Security JWTKeyAuth +// @Success 200 {object} handler.AuthURL "The auth url." +// @Failure 500 {object} models.Message "Internal server error" +// @Router /migration/microsoft-todo/auth [get] func (m *Migration) AuthURL() string { return "https://login.microsoftonline.com/common/oauth2/v2.0/authorize" + "?client_id=" + config.MigrationMicrosoftTodoClientID.GetString() + @@ -128,6 +137,15 @@ func (m *Migration) AuthURL() string { "&scope=" + apiScopes } +// Name is used to get the name of the Microsoft Todo migration - we're using the docs here to annotate the status route. +// @Summary Get migration status +// @Description Returns if the current user already did the migation or not. This is useful to show a confirmation message in the frontend if the user is trying to do the same migration again. +// @tags migration +// @Produce json +// @Security JWTKeyAuth +// @Success 200 {object} migration.Status "The migration status" +// @Failure 500 {object} models.Message "Internal server error" +// @Router /migration/microsoft-todo/status [get] func (m *Migration) Name() string { return "microsoft-todo" } @@ -318,6 +336,17 @@ func convertMicrosoftTodoData(todoData []*list) (vikunjsStructure []*models.Name return } +// Migrate gets all tasks from Microsoft Todo for a user and puts them into vikunja +// @Summary Migrate all lists, tasks etc. from Microsoft Todo +// @Description Migrates all tasklinsts, tasks, notes and reminders from Microsoft Todo to Vikunja. +// @tags migration +// @Accept json +// @Produce json +// @Security JWTKeyAuth +// @Param migrationCode body microsofttodo.Migration true "The auth token previously obtained from the auth url. See the docs for /migration/microsoft-todo/auth." +// @Success 200 {object} models.Message "A message telling you everything was migrated successfully." +// @Failure 500 {object} models.Message "Internal server error" +// @Router /migration/microsoft-todo/migrate [post] func (m *Migration) Migrate(user *user.User) (err error) { log.Debugf("[Microsoft Todo Migration] Start Microsoft Todo migration for user %d", user.ID) diff --git a/pkg/swagger/docs.go b/pkg/swagger/docs.go index c28f8c9af..2625060d2 100644 --- a/pkg/swagger/docs.go +++ b/pkg/swagger/docs.go @@ -2502,6 +2502,113 @@ var doc = `{ } } }, + "/migration/microsoft-todo/auth": { + "get": { + "security": [ + { + "JWTKeyAuth": [] + } + ], + "description": "Returns the auth url where the user needs to get its auth code. This code can then be used to migrate everything from Microsoft Todo to Vikunja.", + "produces": [ + "application/json" + ], + "tags": [ + "migration" + ], + "summary": "Get the auth url from Microsoft Todo", + "responses": { + "200": { + "description": "The auth url.", + "schema": { + "$ref": "#/definitions/handler.AuthURL" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "$ref": "#/definitions/models.Message" + } + } + } + } + }, + "/migration/microsoft-todo/migrate": { + "post": { + "security": [ + { + "JWTKeyAuth": [] + } + ], + "description": "Migrates all tasklinsts, tasks, notes and reminders from Microsoft Todo to Vikunja.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "migration" + ], + "summary": "Migrate all lists, tasks etc. from Microsoft Todo", + "parameters": [ + { + "description": "The auth token previously obtained from the auth url. See the docs for /migration/microsoft-todo/auth.", + "name": "migrationCode", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/microsofttodo.Migration" + } + } + ], + "responses": { + "200": { + "description": "A message telling you everything was migrated successfully.", + "schema": { + "$ref": "#/definitions/models.Message" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "$ref": "#/definitions/models.Message" + } + } + } + } + }, + "/migration/microsoft-todo/status": { + "get": { + "security": [ + { + "JWTKeyAuth": [] + } + ], + "description": "Returns if the current user already did the migation or not. This is useful to show a confirmation message in the frontend if the user is trying to do the same migration again.", + "produces": [ + "application/json" + ], + "tags": [ + "migration" + ], + "summary": "Get migration status", + "responses": { + "200": { + "description": "The migration status", + "schema": { + "$ref": "#/definitions/migration.Status" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "$ref": "#/definitions/models.Message" + } + } + } + } + }, "/migration/todoist/auth": { "get": { "security": [ @@ -6657,6 +6764,14 @@ var doc = `{ } } }, + "microsofttodo.Migration": { + "type": "object", + "properties": { + "code": { + "type": "string" + } + } + }, "migration.Status": { "type": "object", "properties": { diff --git a/pkg/swagger/swagger.json b/pkg/swagger/swagger.json index 49bd76d01..d307e6daf 100644 --- a/pkg/swagger/swagger.json +++ b/pkg/swagger/swagger.json @@ -2485,6 +2485,113 @@ } } }, + "/migration/microsoft-todo/auth": { + "get": { + "security": [ + { + "JWTKeyAuth": [] + } + ], + "description": "Returns the auth url where the user needs to get its auth code. This code can then be used to migrate everything from Microsoft Todo to Vikunja.", + "produces": [ + "application/json" + ], + "tags": [ + "migration" + ], + "summary": "Get the auth url from Microsoft Todo", + "responses": { + "200": { + "description": "The auth url.", + "schema": { + "$ref": "#/definitions/handler.AuthURL" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "$ref": "#/definitions/models.Message" + } + } + } + } + }, + "/migration/microsoft-todo/migrate": { + "post": { + "security": [ + { + "JWTKeyAuth": [] + } + ], + "description": "Migrates all tasklinsts, tasks, notes and reminders from Microsoft Todo to Vikunja.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "migration" + ], + "summary": "Migrate all lists, tasks etc. from Microsoft Todo", + "parameters": [ + { + "description": "The auth token previously obtained from the auth url. See the docs for /migration/microsoft-todo/auth.", + "name": "migrationCode", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/microsofttodo.Migration" + } + } + ], + "responses": { + "200": { + "description": "A message telling you everything was migrated successfully.", + "schema": { + "$ref": "#/definitions/models.Message" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "$ref": "#/definitions/models.Message" + } + } + } + } + }, + "/migration/microsoft-todo/status": { + "get": { + "security": [ + { + "JWTKeyAuth": [] + } + ], + "description": "Returns if the current user already did the migation or not. This is useful to show a confirmation message in the frontend if the user is trying to do the same migration again.", + "produces": [ + "application/json" + ], + "tags": [ + "migration" + ], + "summary": "Get migration status", + "responses": { + "200": { + "description": "The migration status", + "schema": { + "$ref": "#/definitions/migration.Status" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "$ref": "#/definitions/models.Message" + } + } + } + } + }, "/migration/todoist/auth": { "get": { "security": [ @@ -6640,6 +6747,14 @@ } } }, + "microsofttodo.Migration": { + "type": "object", + "properties": { + "code": { + "type": "string" + } + } + }, "migration.Status": { "type": "object", "properties": { diff --git a/pkg/swagger/swagger.yaml b/pkg/swagger/swagger.yaml index 860a8b373..a834f1318 100644 --- a/pkg/swagger/swagger.yaml +++ b/pkg/swagger/swagger.yaml @@ -35,6 +35,11 @@ definitions: url: type: string type: object + microsofttodo.Migration: + properties: + code: + type: string + type: object migration.Status: properties: id: @@ -2671,6 +2676,72 @@ paths: summary: Login tags: - user + /migration/microsoft-todo/auth: + get: + description: Returns the auth url where the user needs to get its auth code. This code can then be used to migrate everything from Microsoft Todo to Vikunja. + produces: + - application/json + responses: + "200": + description: The auth url. + schema: + $ref: '#/definitions/handler.AuthURL' + "500": + description: Internal server error + schema: + $ref: '#/definitions/models.Message' + security: + - JWTKeyAuth: [] + summary: Get the auth url from Microsoft Todo + tags: + - migration + /migration/microsoft-todo/migrate: + post: + consumes: + - application/json + description: Migrates all tasklinsts, tasks, notes and reminders from Microsoft Todo to Vikunja. + parameters: + - description: The auth token previously obtained from the auth url. See the docs for /migration/microsoft-todo/auth. + in: body + name: migrationCode + required: true + schema: + $ref: '#/definitions/microsofttodo.Migration' + produces: + - application/json + responses: + "200": + description: A message telling you everything was migrated successfully. + schema: + $ref: '#/definitions/models.Message' + "500": + description: Internal server error + schema: + $ref: '#/definitions/models.Message' + security: + - JWTKeyAuth: [] + summary: Migrate all lists, tasks etc. from Microsoft Todo + tags: + - migration + /migration/microsoft-todo/status: + get: + description: Returns if the current user already did the migation or not. This is useful to show a confirmation message in the frontend if the user is trying to do the same migration again. + produces: + - application/json + responses: + "200": + description: The migration status + schema: + $ref: '#/definitions/migration.Status' + "500": + description: Internal server error + schema: + $ref: '#/definitions/models.Message' + security: + - JWTKeyAuth: [] + summary: Get migration status + tags: + - migration /migration/todoist/auth: get: description: Returns the auth url where the user needs to get its auth code. This code can then be used to migrate everything from todoist to Vikunja.