diff --git a/.gitignore b/.gitignore index 1f5bd69675..51f1480de2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ npm-debug.log *.pem run.bat +api-docs.json diff --git a/package.json b/package.json index 13cf6dcaa1..e06b1dff41 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "scripts": { "config": "node ./init.js", "start": "node ./built/index.js", + "swagger": "node ./swagger.js", "build": "gulp build", "rebuild": "gulp rebuild", "clean": "gulp clean", @@ -120,6 +121,7 @@ "sortablejs": "1.5.0-rc1", "subdomain": "1.2.0", "summaly": "1.2.7", + "swagger-jsdoc": "^1.8.4", "syuilo-password-strength": "0.0.1", "syuilo-transformify": "0.1.2", "tcp-port-used": "0.1.2", diff --git a/src/api/endpoints/auth/session/generate.js b/src/api/endpoints/auth/session/generate.js index bb49cf090d..07ff8a8195 100644 --- a/src/api/endpoints/auth/session/generate.js +++ b/src/api/endpoints/auth/session/generate.js @@ -7,6 +7,36 @@ import * as uuid from 'uuid'; import App from '../../../models/app'; import AuthSess from '../../../models/auth-session'; +/** + * @swagger + * /auth/session/generate: + * post: + * summary: Generate a session + * parameters: + * - + * name: app_secret + * in: formData + * required: true + * type: string + * + * responses: + * 200: + * description: OK + * schema: + * type: object + * properties: + * token: + * type: string + * description: API Token + * url: + * type: string + * description: Callback URL + * 400: + * description: Failed + * schema: + * $ref: "#/definitions/Error" + */ + /** * Generate a session * diff --git a/swagger.js b/swagger.js new file mode 100644 index 0000000000..eb82a72516 --- /dev/null +++ b/swagger.js @@ -0,0 +1,41 @@ +const swaggerJSDoc = require('swagger-jsdoc'); +const fs = require('fs'); + +const apiRoot = './src/api/endpoints'; +const files = [ + 'auth/session/generate.js' +]; + +const errorDefinition = { + 'type': 'object', + 'properties':{ + 'error': { + 'type': 'string', + 'description': 'Error message' + } + } +} + +var options = { + swaggerDefinition: { + swagger: '2.0', + info: { + title: 'Misskey API', + version: 'aoi', + }, + consumes: [ + 'application/x-www-form-urlencoded' + ], + produces: [ + 'application/json' + ] + }, + apis: [] +}; +options.apis = files.map(c => {return `${apiRoot}/${c}`;}); + +var swaggerSpec = swaggerJSDoc(options); +swaggerSpec.definitions.Error = errorDefinition; + +fs.writeFileSync('api-docs.json', JSON.stringify(swaggerSpec)); +