diff --git a/src/node/handler/RestAPI.ts b/src/node/handler/RestAPI.ts index 9a0481e08..b0aaa4276 100644 --- a/src/node/handler/RestAPI.ts +++ b/src/node/handler/RestAPI.ts @@ -3,24 +3,26 @@ import {MapArrayType} from "../types/MapType"; import {IncomingForm} from "formidable"; import {ErrorCaused} from "../types/ErrorCaused"; import createHTTPError from "http-errors"; + const apiHandler = require('./APIHandler') import {serve, setup} from 'swagger-ui-express' import express from "express"; + const settings = require('../utils/Settings') type RestAPIMapping = { - apiVersion: string; - functionName: string, - summary?: string, - operationId?: string, - requestBody?: any, - responses?: any, - tags?: string[], + apiVersion: string; + functionName: string, + summary?: string, + operationId?: string, + requestBody?: any, + responses?: any, + tags?: string[], } -const mapping = new Map> +const mapping = new Map> const GET = "GET" @@ -140,9 +142,11 @@ const defaultResponses = { const prepareResponses = (data: { type: string, properties: Record, + properties?: Record, }>, -})=>{ +}) => { return { ...defaultResponses, 200: { @@ -154,14 +158,7 @@ const prepareResponses = (data: { type: "object", properties: { ...defaultResponses["200"].content["application/json"].schema.properties, - data: { - type: "object", - properties: { - groupID: { - type: "string" - } - } - } + data: data } } } @@ -171,8 +168,7 @@ const prepareResponses = (data: { } - -const prepareDefinition = (mapping: Map>)=>{ +const prepareDefinition = (mapping: Map>, address: string) => { const authenticationMethod = settings.authenticationMethod @@ -224,7 +220,7 @@ const prepareDefinition = (mapping: Map>) "requestBody"?: any, "responses": any, "parameters"?: any, - "tags": Array, + "tags": Array, }>>, "security": any[] } = { @@ -251,7 +247,7 @@ const prepareDefinition = (mapping: Map>) }, "servers": [ { - "url": "http://localhost:9001/api/2" + "url": `${address}/api/2` } ], "paths": {}, @@ -265,17 +261,17 @@ const prepareDefinition = (mapping: Map>) } ] } else if (authenticationMethod === "sso") { - definitions.components.securitySchemes.sso = { + definitions.components.securitySchemes.sso = { type: "oauth2", - flows: { + flows: { authorizationCode: { - authorizationUrl: settings.sso.issuer+"/oidc/auth", - tokenUrl: settings.sso.issuer+"/oidc/token", - scopes: { + authorizationUrl: settings.sso.issuer + "/oidc/auth", + tokenUrl: settings.sso.issuer + "/oidc/token", + scopes: { openid: "openid", - profile: "profile", - email: "email", - admin: "admin" + profile: "profile", + email: "email", + admin: "admin" } } }, @@ -289,7 +285,6 @@ const prepareDefinition = (mapping: Map>) } - for (const [method, value] of mapping) { for (const [path, mapping] of Object.entries(value)) { const {apiVersion, functionName, summary, operationId, requestBody, responses, tags} = mapping @@ -325,12 +320,14 @@ export const expressCreateServer = async (hookName: string, {app}: ArgsExpressTy mapping.set(PATCH, {}) // Version 1 - mapping.get(POST)!["/groups"] = {apiVersion: '1', + mapping.get(POST)!["/groups"] = { + apiVersion: '1', functionName: 'createGroup', summary: 'Creates a new group', operationId: 'createGroup', tags: ['group'], responses: prepareResponses({type: "object", properties: {groupID: {type: "string"}}}) } - mapping.get(POST)!["/groups/createIfNotExistsFor"] = {apiVersion: '1', functionName: 'createGroupIfNotExistsFor', + mapping.get(POST)!["/groups/createIfNotExistsFor"] = { + apiVersion: '1', functionName: 'createGroupIfNotExistsFor', requestBody: { content: { "application/json": { @@ -347,8 +344,10 @@ export const expressCreateServer = async (hookName: string, {app}: ArgsExpressTy } }, responses: prepareResponses({type: "object", properties: {groupID: {type: "string"}}}), - summary: "Creates a new group if it doesn't exist", operationId: 'createGroupIfNotExistsFor', tags: ['group']}; - mapping.get(GET)!["/groups/pads"] = {apiVersion: '1', functionName: 'listPads', + summary: "Creates a new group if it doesn't exist", operationId: 'createGroupIfNotExistsFor', tags: ['group'] + }; + mapping.get(GET)!["/groups/pads"] = { + apiVersion: '1', functionName: 'listPads', summary: "Lists all pads in a group", tags: ['group'], operationId: 'listPads', responses: prepareResponses({type: "object", properties: {padIDs: {type: "string"}}}), requestBody: [ @@ -361,83 +360,1046 @@ export const expressCreateServer = async (hookName: string, {app}: ArgsExpressTy } ] } - mapping.get(DELETE)!["/groups"] = {apiVersion: '1', functionName: 'deleteGroup'} - mapping.get(POST)!["/authors"] = {apiVersion: '1', functionName: 'createAuthor'} - mapping.get(POST)!["/authors/createIfNotExistsFor"] = {apiVersion: '1', functionName: 'createAuthorIfNotExistsFor'} - mapping.get(GET)!["/authors/pads"] = {apiVersion: '1', functionName: 'listPadsOfAuthor'} - mapping.get(POST)!["/sessions"] = {apiVersion: '1', functionName: 'createSession'} - mapping.get(DELETE)!["/sessions"] = {apiVersion: '1', functionName: 'deleteSession'} - mapping.get(GET)!["/sessions/info"] = {apiVersion: '1', functionName: 'getSessionInfo'} - mapping.get(GET)!["/sessions/group"] = {apiVersion: '1', functionName: 'listSessionsOfGroup'} - mapping.get(GET)!["/sessions/author"] = {apiVersion: '1', functionName: 'listSessionsOfAuthor'} - mapping.get(GET)!["/pads/text"] = {apiVersion: '1', functionName: 'getText'} - mapping.get(GET)!["/pads/html"] = {apiVersion: '1', functionName: 'getHTML'} - mapping.get(GET)!["/pads/revisions"] = {apiVersion: '1', functionName: 'getRevisionsCount'} - mapping.get(GET)!["/pads/lastEdited"] = {apiVersion: '1', functionName: 'getLastEdited'} - mapping.get(DELETE)!["/pads"] = {apiVersion: '1', functionName: 'deletePad'} - mapping.get(GET)!["/pads/readonly"] = {apiVersion: '1', functionName: 'getReadOnlyID'} - mapping.get(POST)!["/pads/publicStatus"] = {apiVersion: '1', functionName: 'setPublicStatus'} - mapping.get(GET)!["/pads/publicStatus"] = {apiVersion: '1', functionName: 'getPublicStatus'} - mapping.get(GET)!["/pads/authors"] = {apiVersion: '1', functionName: 'listAuthorsOfPad'} - mapping.get(GET)!["/pads/usersCount"] = {apiVersion: '1', functionName: 'padUsersCount'} + mapping.get(DELETE)!["/groups"] = { + apiVersion: '1', functionName: 'deleteGroup', responses: prepareResponses({type: "object", properties: {}}), requestBody: { + content: { + "application/json": { + schema: { + type: "object", + properties: { + groupID: { + type: "string" + } + }, + required: ["groupID"] + } + } + } + }, summary: "Deletes a group", operationId: 'deleteGroup', tags: ['group'] + } + + mapping.get(POST)!["/authors"] = { + apiVersion: '1', functionName: 'createAuthor', requestBody: { + content: { + "application/json": { + schema: { + type: "object", + properties: { + name: { + type: "string" + } + }, + required: ["name"] + } + } + } + }, tags: ["author"] + } + + + mapping.get(POST)!["/authors/createIfNotExistsFor"] = { + apiVersion: '1', functionName: 'createAuthorIfNotExistsFor', + responses: prepareResponses({type: "object", properties: {authorID: {type: "string"}}}), + requestBody: { + content: { + "application/json": { + schema: { + type: "object", + properties: { + authorMapper: { + type: "string" + }, + name: { + type: "string" + } + }, + required: ["authorMapper", "name"] + } + } + } + }, + tags: ["author"], + } + + + mapping.get(GET)!["/authors/pads"] = { + apiVersion: '1', functionName: 'listPadsOfAuthor', + requestBody: [ + { + "name": "authorID", + "in": "query", + "schema": { + "type": "string" + } + } + ], + responses: prepareResponses({type: "object", properties: {padIDs: {type: "array", items: {type: "string"}}}}), + tags: ["author"] + } + mapping.get(POST)!["/sessions"] = { + apiVersion: '1', functionName: 'createSession', + requestBody: { + content: { + "application/json": { + schema: { + type: "object", + properties: { + groupID: { + type: "string" + }, + authorID: { + type: "string" + }, + validUntil: { + type: "string" + } + }, + required: ["groupID", "authorID", "validUntil"] + } + } + } + }, + responses: prepareResponses({type: "object", properties: {sessionID: {type: "string"}}}), + tags: ['session'] + } + + mapping.get(DELETE)!["/sessions"] = { + apiVersion: '1', functionName: 'deleteSession', + requestBody: { + content: { + "application/json": { + schema: { + type: "object", + properties: { + sessionID: { + type: "string" + } + }, + required: ["sessionID"] + } + } + } + }, + responses: prepareResponses({type: "object", properties: {}}), + tags: ['session'] + } + + + mapping.get(GET)!["/sessions/info"] = { + apiVersion: '1', functionName: 'getSessionInfo', + requestBody: [ + { + "name": "sessionID", + "in": "query", + "schema": { + "type": "string" + } + } + ], + responses: prepareResponses({ + "type": "object", + "properties": { + id: { + type: "string" + }, + "groupID": { + "type": "string" + }, + "authorID": { + "type": "string" + }, + "validUntil": { + "type": "string" + } + } + }), + tags: ['session'] + } + + + mapping.get(GET)!["/sessions/group"] = { + apiVersion: '1', functionName: 'listSessionsOfGroup', summary: 'Lists all sessions in a group', + operationId: 'listSessionsOfGroup', tags: ['session'], + responses: prepareResponses({ + type: "object", "properties": { + "sessions": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "authorID": { + "type": "string" + }, + "groupID": { + "type": "string" + }, + "validUntil": { + "type": "integer" + } + } + } + } + } + }), + requestBody: [ + { + "name": "groupID", + "in": "query", + "schema": { + "type": "string" + } + } + ] + } + mapping.get(GET)!["/sessions/author"] = { + apiVersion: '1', functionName: 'listSessionsOfAuthor', + summary: 'Lists all sessions of an author', operationId: 'listSessionsOfAuthor', tags: ['session'], + responses: prepareResponses({ + type: "object", "properties": { + "sessions": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "authorID": { + "type": "string" + }, + "groupID": { + "type": "string" + }, + "validUntil": { + "type": "integer" + } + } + } + } + } + }), + requestBody: [ + { + "name": "authorID", + "in": "query", + "schema": { + "type": "string" + } + } + ] + } + + + mapping.get(GET)!["/pads/text"] = { + apiVersion: '1', functionName: 'getText', + responses: prepareResponses({type: "object", properties: {text: {type: "string"}}}), + requestBody: [ + { + "name": "padID", + "in": "query", + "schema": { + "type": "string" + } + } + ], + tags: ['pad'] + } + + + mapping.get(GET)!["/pads/html"] = { + apiVersion: '1', functionName: 'getHTML', + responses: prepareResponses({type: "object", properties: {html: {type: "string"}}}), + requestBody: [ + { + "name": "padID", + "in": "query", + "schema": { + "type": "string" + } + } + ], + summary: 'Get the HTML of a pad', + tags: ['pad'] + } + mapping.get(GET)!["/pads/revisions"] = { + apiVersion: '1', functionName: 'getRevisionsCount', + responses: prepareResponses({type: "object", properties: {revisions: {type: "integer"}}}), + requestBody: [ + { + "name": "padID", + "in": "query", + "schema": { + "type": "string" + } + } + ], + summary: 'Get the number of revisions of a pad', + tags: ['pad'] + } + + mapping.get(GET)!["/pads/lastEdited"] = { + apiVersion: '1', functionName: 'getLastEdited', + responses: prepareResponses({type: "object", properties: {lastEdited: {type: "integer"}}}), + requestBody: [ + { + "name": "padID", + "in": "query", + "schema": { + "type": "string" + } + } + ], + summary: 'Get the timestamp of the last revision of a pad', + tags: ['pad'] + } + + + mapping.get(DELETE)!["/pads"] = { + apiVersion: '1', functionName: 'deletePad', + responses: prepareResponses({type: "object", properties: {}}), + requestBody: { + content: { + "application/json": { + schema: { + type: "object", + properties: { + padID: { + type: "string" + } + }, + required: ["padID"] + } + } + } + }, + summary: 'Deletes a pad', + tags: ['pad'] + } + mapping.get(GET)!["/pads/readonly"] = { + apiVersion: '1', functionName: 'getReadOnlyID', + responses: prepareResponses({type: "object", properties: {readOnlyID: {type: "string"}}}), + requestBody: [ + { + "name": "padID", + "in": "query", + "schema": { + "type": "string" + } + } + ], + summary: 'Get the read only id of a pad', + tags: ['pad'] + } + + mapping.get(POST)!["/pads/publicStatus"] = { + apiVersion: '1', functionName: 'setPublicStatus', + responses: prepareResponses({type: "object", properties: {}}), + requestBody: { + content: { + "application/json": { + schema: { + type: "object", + properties: { + padID: { + type: "string" + }, + publicStatus: { + type: "boolean" + } + }, + required: ["padID", "publicStatus"] + } + } + } + }, + summary: 'Set the public status of a pad', + tags: ['pad'] + + } + mapping.get(GET)!["/pads/publicStatus"] = { + apiVersion: '1', functionName: 'getPublicStatus', + responses: prepareResponses({type: "object", properties: {publicStatus: {type: "boolean"}}}), + requestBody: [ + { + "name": "padID", + "in": "query", + "schema": { + "type": "string" + } + } + ], + summary: 'Get the public status of a pad', + tags: ['pad'] + } + mapping.get(GET)!["/pads/authors"] = { + apiVersion: '1', functionName: 'listAuthorsOfPad', + responses: prepareResponses({type: "object", properties: {authorIDs: {type: "array", items: {type: "string"}}}}), + requestBody: [ + { + "name": "padID", + "in": "query", + "schema": { + "type": "string" + } + } + ], + summary: 'Get the authors of a pad', + tags: ['pad'] + } + mapping.get(GET)!["/pads/usersCount"] = { + apiVersion: '1', functionName: 'padUsersCount', + responses: prepareResponses({type: "object", properties: {padUsersCount: {type: "integer"}}}), + requestBody: [ + { + "name": "padID", + "in": "query", + "schema": { + "type": "string" + } + } + ], + summary: 'Get the number of users currently editing a pad', + tags: ['pad'] + } // Version 1.1 - mapping.get(GET)!["/authors/name"] = {apiVersion: '1.1', functionName: 'getAuthorName'} - mapping.get(GET)!["/pads/users"] = {apiVersion: '1.1', functionName: 'padUsers'} - mapping.get(POST)!["/pads/sendClientsMessage"] = {apiVersion: '1.1', functionName: 'sendClientsMessage'} - mapping.get(GET)!["/groups"] = {apiVersion: '1.1', functionName: 'listAllGroups'} + mapping.get(GET)!["/authors/name"] = { + apiVersion: '1.1', functionName: 'getAuthorName', + responses: prepareResponses({type: "object", properties: {authorName: {type: "string"}}}), + requestBody: [ + { + "name": "authorID", + "in": "query", + "schema": { + "type": "string" + } + } + ], + summary: 'Get the name of an author', + tags: ['author'] + } + mapping.get(GET)!["/pads/users"] = { + apiVersion: '1.1', functionName: 'padUsers', + responses: prepareResponses({ + type: "object", properties: { + padUsers: { + type: "array", "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "colorId": { + "type": "string" + }, + "name": { + "type": "string" + }, + "timestamp": { + "type": "integer" + } + } + } + } + } + }), + requestBody: [ + { + "name": "padID", + "in": "query", + "schema": { + "type": "string" + } + } + ], + summary: 'Get the users currently editing a pad', + tags: ['pad'] + } + + + mapping.get(POST)!["/pads/clientsMessage"] = { + apiVersion: '1.1', functionName: 'sendClientsMessage', + responses: prepareResponses({type: "object", properties: {}}), + requestBody: { + content: { + "application/json": { + schema: { + type: "object", + properties: { + padID: { + type: "string" + }, + msg: { + type: "string" + } + }, + required: ["padID", "msg"] + } + } + } + }, + summary: 'Send a message to all clients of a pad', + tags: ['pad'] + } + + + mapping.get(GET)!["/groups"] = { + apiVersion: '1.1', functionName: 'listAllGroups', + responses: prepareResponses({type: "object", properties: {groupIDs: {type: "array", items: {type: "string"}}}}), + summary: 'Lists all groups', + tags: ['group'] + } // Version 1.2 - mapping.get(GET)!["/checkToken"] = {apiVersion: '1.2', functionName: 'checkToken'} + mapping.get(GET)!["/checkToken"] = { + apiVersion: '1.2', functionName: 'checkToken', + responses: prepareResponses({type: "object", properties: {}}), + requestBody: [ + { + "name": "token", + "in": "query", + "schema": { + "type": "string" + } + } + ], + summary: 'Check if a token is valid', + tags: ['token'] + + } // Version 1.2.1 - mapping.get(GET)!["/pads"] = {apiVersion: '1.2.1', functionName: 'listAllPads'} + mapping.get(GET)!["/pads"] = { + apiVersion: '1.2.1', functionName: 'listAllPads', + summary: 'Lists all pads', + tags: ['pad'], + requestBody: [ + { + "name": "groupID", + "in": "query", + "schema": { + "type": "string" + } + } + ], + responses: prepareResponses({type: "object", properties: {padIDs: {type: "array", items: {type: "string"}}}}) + } // Version 1.2.7 - mapping.get(POST)!["/pads/diff"] = {apiVersion: '1.2.7', functionName: 'createDiffHTML'} - mapping.get(GET)!["/pads/chatHistory"] = {apiVersion: '1.2.7', functionName: 'getChatHistory'} - mapping.get(GET)!["/pads/chatHead"] = {apiVersion: '1.2.7', functionName: 'getChatHead'} + mapping.get(POST)!["/pads/diff"] = { + apiVersion: '1.2.7', functionName: 'createDiffHTML', + requestBody: { + content: { + "application/json": { + schema: { + type: "object", + properties: { + padID: { + type: "string" + }, + startRev: { + type: "integer" + }, + endRev: { + type: "integer" + } + }, + required: ["padID", "startRev", "endRev"] + } + } + } + }, + responses: prepareResponses({type: "object", properties: {}}), + summary: 'Creates a diff of a pad', + tags: ['pad'] + } + mapping.get(GET)!["/pads/chatHistory"] = { + apiVersion: '1.2.7', functionName: 'getChatHistory', + responses: prepareResponses({ + type: "object", properties: { + messages: { + type: "array", items: { + type: "object", properties: { + "text": { + "type": "string" + }, + "userId": { + "type": "string" + }, + "userName": { + "type": "string" + }, + "time": { + "type": "integer" + } + } + } + } + } + }), + requestBody: [ + { + "name": "padID", + "in": "query", + "schema": { + "type": "string" + } + } + ], + summary: 'Get the chat history of a pad', + tags: ['pad'] + } + mapping.get(GET)!["/pads/chatHead"] = {apiVersion: '1.2.7', functionName: 'getChatHead', + responses: prepareResponses({type: "object", properties: { + chatHead: { + type: "object", + properties: { + "text": { + "type": "string" + }, + "userId": { + "type": "string" + }, + "userName": { + "type": "string" + }, + "time": { + "type": "integer" + } + } + } + + }}), + requestBody: [ + { + "name": "padID", + "in": "query", + "schema": { + "type": "string" + } + } + ], + summary: 'Get the chat head of a pad', + tags: ['pad'] + + } // Version 1.2.8 - mapping.get(GET)!["/pads/attributePool"] = {apiVersion: '1.2.8', functionName: 'getAttributePool'} - mapping.get(GET)!["/pads/revisionChangeset"] = {apiVersion: '1.2.8', functionName: 'getRevisionChangeset'} + mapping.get(GET)!["/pads/attributePool"] = {apiVersion: '1.2.8', functionName: 'getAttributePool', + responses: prepareResponses({type: "object", properties: {}}), + requestBody: [ + { + "name": "padID", + "in": "query", + "schema": { + "type": "string" + } + } + ], + summary: 'Get the attribute pool of a pad', + tags: ['pad'] + } + mapping.get(GET)!["/pads/revisionChangeset"] = {apiVersion: '1.2.8', functionName: 'getRevisionChangeset', + responses: prepareResponses({type: "object", properties: {}}), + requestBody: [ + { + "name": "padID", + "in": "query", + "schema": { + "type": "string" + } + }, + { + "name": "rev", + "in": "query", + "schema": { + "type": "integer" + } + } + ], + summary: 'Get the changeset of a revision of a pad', + tags: ['pad'] + } // Version 1.2.9 - mapping.get(POST)!["/pads/copypad"] = {apiVersion: '1.2.9', functionName: 'copyPad'} - mapping.get(POST)!["/pads/movepad"] = {apiVersion: '1.2.9', functionName: 'movePad'} + mapping.get(POST)!["/pads/copypad"] = {apiVersion: '1.2.9', functionName: 'copyPad', + requestBody: { + content: { + "application/json": { + schema: { + type: "object", + properties: { + sourceID: { + type: "string" + }, + destinationID: { + type: "string" + }, + force: { + type: "boolean" + } + }, + required: ["sourceID", "destinationID"] + } + } + } + }, + responses: prepareResponses({type: "object", properties: {}}), + summary: 'Copies a pad', + tags: ['pad'] + } + + + mapping.get(POST)!["/pads/movePad"] = {apiVersion: '1.2.9', functionName: 'movePad', + requestBody: { + content: { + "application/json": { + schema: { + type: "object", + properties: { + sourceID: { + type: "string" + }, + destinationID: { + type: "string" + }, + force: { + type: "boolean" + } + }, + required: ["sourceID", "destinationID"] + } + } + } + }, + responses: prepareResponses({type: "object", properties: {}}), + summary: 'Moves a pad', + tags: ['pad'] + } // Version 1.2.10 - mapping.get(POST)!["/pads/padId"] = {apiVersion: '1.2.10', functionName: 'getPadID'} + mapping.get(POST)!["/pads/padId"] = {apiVersion: '1.2.10', functionName: 'getPadID', + requestBody: { + content: { + "application/json": { + schema: { + type: "object", + properties: { + roID: { + type: "string" + } + }, + required: ["roID"] + } + } + } + }, + responses: prepareResponses({type: "object", properties: {}}), + summary: 'Get the pad id of a pad', + tags: ['pad'] + } // Version 1.2.11 - mapping.get(GET)!["/savedRevisions"] = {apiVersion: '1.2.11', functionName: 'listSavedRevisions'} - mapping.get(POST)!["/savedRevisions"] = {apiVersion: '1.2.11', functionName: 'saveRevision'} - mapping.get(GET)!["/savedRevisions/revisionsCount"] = {apiVersion: '1.2.11', functionName: 'getSavedRevisionsCount'} + mapping.get(GET)!["/savedRevisions"] = {apiVersion: '1.2.11', functionName: 'listSavedRevisions', + responses: prepareResponses({type: "object", properties: {savedRevisions: {type: "array", items: {type: "object"}}}}), + requestBody: [ + { + "name": "padID", + "in": "query", + "schema": { + "type": "string" + } + } + ], + summary: 'Lists all saved revisions of a pad', + tags: ['pad'] + } + + + mapping.get(POST)!["/savedRevisions"] = {apiVersion: '1.2.11', functionName: 'saveRevision', + requestBody: { + content: { + "application/json": { + schema: { + type: "object", + properties: { + padID: { + type: "string" + }, + rev: { + type: "integer" + } + }, + required: ["padID", "rev"] + } + } + } + }, + responses: prepareResponses({type: "object", properties: {}}), + summary: 'Saves a revision of a pad', + tags: ['pad'] + } + + mapping.get(GET)!["/savedRevisions/revisionsCount"] = {apiVersion: '1.2.11', functionName: 'getSavedRevisionsCount', + responses: prepareResponses({type: "object", properties: {revisionsCount: {type: "integer"}}}), + requestBody: [ + { + "name": "padID", + "in": "query", + "schema": { + "type": "string" + } + } + ], + summary: 'Get the number of saved revisions of a pad', + tags: ['pad'] + } // Version 1.2.12 - mapping.get(PATCH)!["/chats/messages"] = {apiVersion: '1.2.12', functionName: 'appendChatMessage'} + mapping.get(PATCH)!["/chats/messages"] = {apiVersion: '1.2.12', functionName: 'appendChatMessage', + requestBody: { + content: { + "application/json": { + schema: { + type: "object", + properties: { + padID: { + type: "string" + }, + text: { + type: "string" + }, + authorID: { + type: "string" + }, + time: { + type: "string" + } + }, + required: ["padID", "text"] + } + } + } + }, + responses: prepareResponses({type: "object", properties: {}}), + summary: 'Appends a chat message to a pad', + tags: ['pad'] + } // Version 1.2.13 // Version 1.2.14 - mapping.get(GET)!["/stats"] = {apiVersion: '1.2.14', functionName: 'getStats'} + mapping.get(GET)!["/stats"] = {apiVersion: '1.2.14', functionName: 'getStats', + responses: prepareResponses({type: "object", properties: {stats: {type: "object"}}}), + summary: 'Get stats', + tags: ['stats'] + } // Version 1.2.15 // Version 1.3.0 - mapping.get(PATCH)!["/pads/text"] = {apiVersion: '1.3.0', functionName: 'appendText'} - mapping.get(POST)!["/pads/copyWithoutHistory"] = {apiVersion: '1.3.0', functionName: 'copyPadWithoutHistory'} - mapping.get(POST)!["/pads/group"] = {apiVersion: '1.3.0', functionName: 'createGroupPad'} - mapping.get(POST)!["/pads"] = {apiVersion: '1.3.0', functionName: 'createPad'} - mapping.get(PATCH)!["/savedRevisions"] = {apiVersion: '1.3.0', functionName: 'restoreRevision'} - mapping.get(POST)!["/pads/html"] = {apiVersion: '1.3.0', functionName: 'setHTML'} - mapping.get(POST)!["/pads/text"] = {apiVersion: '1.3.0', functionName: 'setText'} + mapping.get(PATCH)!["/pads/text"] = {apiVersion: '1.3.0', functionName: 'appendText', + requestBody: { + content: { + "application/json": { + schema: { + type: "object", + properties: { + padID: { + type: "string" + }, + text: { + type: "string" + }, + authorID: { + type: "string" + }, + }, + required: ["padID", "text", "authorID"] + } + } + } + }, + responses: prepareResponses({type: "object", properties: {}}), + summary: 'Appends text to a pad', + tags: ['pad'] + } + mapping.get(POST)!["/pads/copyWithoutHistory"] = {apiVersion: '1.3.0', functionName: 'copyPadWithoutHistory', + requestBody: { + content: { + "application/json": { + schema: { + type: "object", + properties: { + sourceID: { + type: "string" + }, + destinationID: { + type: "string" + }, + force : { + type: "string" + }, + authorID: { + type: "string" + } + }, + required: ["sourceID", "destinationID","force", "authorID"] + } + } + } + }, + responses: prepareResponses({type: "object", properties: {}}), + summary: 'Copies a pad without its history', + tags: ['pad'] + } + mapping.get(POST)!["/pads/group"] = {apiVersion: '1.3.0', functionName: 'createGroupPad', + requestBody: { + content: { + "application/json": { + schema: { + type: "object", + properties: { + groupID: { + type: "string" + }, + padName: { + type: "string" + }, + text: { + type: "string" + }, + authorID: { + type: "string" + } + }, + required: ["groupID", "padName"] + } + } + } + }, + responses: prepareResponses({type: "object", properties: {}}), + summary: 'Creates a new pad in a group', + tags: ['pad'] + + } + mapping.get(POST)!["/pads"] = {apiVersion: '1.3.0', functionName: 'createPad', + requestBody: { + content: { + "application/json": { + schema: { + type: "object", + properties: { + padID: { + type: "string" + }, + text: { + type: "string" + }, + authorId: { + type: "string" + } + }, + required: ["padName"] + } + } + } + }, + responses: prepareResponses({type: "object", properties: {}}), + summary: 'Creates a new pad', + tags: ['pad'] + } + mapping.get(PATCH)!["/savedRevisions"] = { + apiVersion: '1.3.0', functionName: 'restoreRevision', + requestBody: { + content: { + "application/json": { + schema: { + type: "object", + properties: { + padID: { + type: "string" + }, + rev: { + type: "integer" + }, + authorId: { + type: "string" + } + }, + required: ["padID", "rev", "authorId"] + } + } + } + }, + responses: prepareResponses({type: "object", properties: {}}), + summary: 'Restores a revision of a pad', + tags: ['pad'] + } + + + mapping.get(POST)!["/pads/html"] = {apiVersion: '1.3.0', functionName: 'setHTML', + requestBody: { + content: { + "application/json": { + schema: { + type: "object", + properties: { + padID: { + type: "string" + }, + html: { + type: "string" + }, + authorId: { + type: "string" + } + }, + required: ["padID", "html", "authorId"] + } + } + } + }, + responses: prepareResponses({type: "object", properties: {}}), + summary: 'Sets the HTML of a pad', + tags: ['pad'] + } + + mapping.get(POST)!["/pads/text"] = {apiVersion: '1.3.0', functionName: 'setText', + requestBody: { + content: { + "application/json": { + schema: { + type: "object", + properties: { + padID: { + type: "string" + }, + text: { + type: "string" + }, + authorId: { + type: "string" + } + }, + required: ["padID", "text", "authorId"] + } + } + } + }, + responses: prepareResponses({type: "object", properties: {}}), + summary: 'Sets the text of a pad', + tags: ['pad'] + } app.use('/api-docs', serve); - app.get('/api-docs', setup(undefined,{ + app.get('/api-docs', setup(undefined, { swaggerOptions: { url: '/api-docs.json', }, @@ -445,8 +1407,9 @@ export const expressCreateServer = async (hookName: string, {app}: ArgsExpressTy app.use(express.json()); - app.get('/api-docs.json', (req, res)=>{ - const generatedDefinition = prepareDefinition(mapping) + app.get('/api-docs.json', (req, res) => { + const fullUrl = req.protocol + '://' + req.get('host'); + const generatedDefinition = prepareDefinition(mapping, fullUrl) res.json(generatedDefinition) }) app.use('/api/2', async (req, res, next) => { @@ -457,7 +1420,7 @@ export const expressCreateServer = async (hookName: string, {app}: ArgsExpressTy // read form data if method was POST let formData: MapArrayType = {}; - if (method.toLowerCase() === 'post') { + if (method.toLowerCase() === 'post' || method.toLowerCase() === "delete") { if (!req.headers['content-type'] || req.headers['content-type']!.startsWith('application/json')) { // parse json formData = req.body; diff --git a/src/node/security/OAuth2Provider.ts b/src/node/security/OAuth2Provider.ts index e21211350..76e7ed4b8 100644 --- a/src/node/security/OAuth2Provider.ts +++ b/src/node/security/OAuth2Provider.ts @@ -153,7 +153,7 @@ export const expressCreateServer = async (hookName: string, args: ArgsExpressTyp }); - args.app.post('/interaction/:uid', async (req: Http2ServerRequest, res: Http2ServerResponse, next:Function) => { + args.app.post('/interaction/:uid', async (req, res, next) => { const formid = new IncomingForm(); try { // @ts-ignore @@ -226,7 +226,7 @@ export const expressCreateServer = async (hookName: string, args: ArgsExpressTyp }) - args.app.get('/interaction/:uid', async (req: Request, res: Response, next: Function) => { + args.app.get('/interaction/:uid', async (req, res, next) => { try { const { uid, prompt, params, session,