openapi: remove swagger-node-express

This commit is contained in:
Viljami Kuosmanen 2020-03-29 16:39:45 +02:00 committed by muxator
parent 25e081ac89
commit f9d24f5a39
4 changed files with 204 additions and 460 deletions

View file

@ -4,7 +4,6 @@ const { promisify } = require('util');
const apiHandler = require('../../handler/APIHandler');
const settings = require('../../utils/Settings');
const { API } = require('./swagger');
const log4js = require('log4js');
const apiLogger = log4js.getLogger('API');
@ -12,12 +11,214 @@ const apiLogger = log4js.getLogger('API');
// https://github.com/OAI/OpenAPI-Specification/tree/master/schemas/v3.0
const OPENAPI_VERSION = '3.0.2'; // Swagger/OAS version
// We'll add some more info to the API methods
// operations
const API = {
// Group
group: {
create: {
func: 'createGroup',
description: 'creates a new group',
response: { groupID: { type: 'string' } },
},
createIfNotExistsFor: {
func: 'createGroupIfNotExistsFor',
description: 'this functions helps you to map your application group ids to Etherpad group ids',
response: { groupID: { type: 'string' } },
},
delete: {
func: 'deleteGroup',
description: 'deletes a group',
},
listPads: {
func: 'listPads',
description: 'returns all pads of this group',
response: { padIDs: { type: 'List', items: { type: 'string' } } },
},
createPad: {
func: 'createGroupPad',
description: 'creates a new pad in this group',
},
listSessions: {
func: 'listSessionsOfGroup',
description: '',
response: { sessions: { type: 'List', items: { type: 'SessionInfo' } } },
},
list: {
func: 'listAllGroups',
description: '',
response: { groupIDs: { type: 'List', items: { type: 'string' } } },
},
},
// Author
author: {
create: {
func: 'createAuthor',
description: 'creates a new author',
response: { authorID: { type: 'string' } },
},
createIfNotExistsFor: {
func: 'createAuthorIfNotExistsFor',
description: 'this functions helps you to map your application author ids to Etherpad author ids',
response: { authorID: { type: 'string' } },
},
listPads: {
func: 'listPadsOfAuthor',
description: 'returns an array of all pads this author contributed to',
response: { padIDs: { type: 'List', items: { type: 'string' } } },
},
listSessions: {
func: 'listSessionsOfAuthor',
description: 'returns all sessions of an author',
response: { sessions: { type: 'List', items: { type: 'SessionInfo' } } },
},
// We need an operation that return a UserInfo so it can be picked up by the codegen :(
getName: {
func: 'getAuthorName',
description: 'Returns the Author Name of the author',
response: { info: { type: 'UserInfo' } },
},
},
// Session
session: {
create: {
func: 'createSession',
description: 'creates a new session. validUntil is an unix timestamp in seconds',
response: { sessionID: { type: 'string' } },
},
delete: {
func: 'deleteSession',
description: 'deletes a session',
},
// We need an operation that returns a SessionInfo so it can be picked up by the codegen :(
info: {
func: 'getSessionInfo',
description: 'returns informations about a session',
response: { info: { type: 'SessionInfo' } },
},
},
// Pad
pad: {
listAll: {
func: 'listAllPads',
description: 'list all the pads',
response: { padIDs: { type: 'List', items: { type: 'string' } } },
},
createDiffHTML: {
func: 'createDiffHTML',
description: '',
response: {},
},
create: {
func: 'createPad',
description:
'creates a new (non-group) pad. Note that if you need to create a group Pad, you should call createGroupPad',
},
getText: {
func: 'getText',
description: 'returns the text of a pad',
response: { text: { type: 'string' } },
},
setText: {
func: 'setText',
description: 'sets the text of a pad',
},
getHTML: {
func: 'getHTML',
description: 'returns the text of a pad formatted as HTML',
response: { html: { type: 'string' } },
},
setHTML: {
func: 'setHTML',
description: 'sets the text of a pad with HTML',
},
getRevisionsCount: {
func: 'getRevisionsCount',
description: 'returns the number of revisions of this pad',
response: { revisions: { type: 'integer' } },
},
getLastEdited: {
func: 'getLastEdited',
description: 'returns the timestamp of the last revision of the pad',
response: { lastEdited: { type: 'integer' } },
},
delete: {
func: 'deletePad',
description: 'deletes a pad',
},
getReadOnlyID: {
func: 'getReadOnlyID',
description: 'returns the read only link of a pad',
response: { readOnlyID: { type: 'string' } },
},
setPublicStatus: {
func: 'setPublicStatus',
description: 'sets a boolean for the public status of a pad',
},
getPublicStatus: {
func: 'getPublicStatus',
description: 'return true of false',
response: { publicStatus: { type: 'boolean' } },
},
setPassword: {
func: 'setPassword',
description: 'returns ok or a error message',
},
isPasswordProtected: {
func: 'isPasswordProtected',
description: 'returns true or false',
response: { passwordProtection: { type: 'boolean' } },
},
authors: {
func: 'listAuthorsOfPad',
description: 'returns an array of authors who contributed to this pad',
response: { authorIDs: { type: 'List', items: { type: 'string' } } },
},
usersCount: {
func: 'padUsersCount',
description: 'returns the number of user that are currently editing this pad',
response: { padUsersCount: { type: 'integer' } },
},
users: {
func: 'padUsers',
description: 'returns the list of users that are currently editing this pad',
response: { padUsers: { type: 'List', items: { type: 'UserInfo' } } },
},
sendClientsMessage: {
func: 'sendClientsMessage',
description: 'sends a custom message of type msg to the pad',
},
checkToken: {
func: 'checkToken',
description: 'returns ok when the current api token is valid',
},
getChatHistory: {
func: 'getChatHistory',
description: 'returns the chat history',
response: { messages: { type: 'List', items: { type: 'Message' } } },
},
// We need an operation that returns a Message so it can be picked up by the codegen :(
getChatHead: {
func: 'getChatHead',
description: 'returns the chatHead (chat-message) of the pad',
response: { chatHead: { type: 'Message' } },
},
appendChatMessage: {
func: 'appendChatMessage',
description: 'appends a chat message',
},
},
};
// enum for two different styles of API paths used for etherpad
const APIPathStyle = {
FLAT: 'api', // flat paths e.g. /api/createGroup
REST: 'rest', // restful paths e.g. /rest/group/create
};
exports.APIPathStyle = APIPathStyle;
// helper to get api root
const getApiRootForVersion = (version, style = APIPathStyle.FLAT) => `/${style}/${version}`;
@ -205,6 +406,7 @@ exports.expressCreateServer = (_, args) => {
const api = new OpenAPIBackend({
apiRoot,
definition,
validate: false,
strict: true,
});