From e62b008c71a216139fdc934174dc5f7376ca5c04 Mon Sep 17 00:00:00 2001 From: Tosuke Date: Wed, 4 Jan 2017 12:59:20 +0900 Subject: [PATCH] [WIP]Generate swagger file --- .gitignore | 1 + package.json | 2 ++ src/api/endpoints/auth/session/generate.js | 30 ++++++++++++++++ swagger.js | 41 ++++++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 swagger.js diff --git a/.gitignore b/.gitignore index 1f5bd6967..51f1480de 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 13cf6dcaa..e06b1dff4 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 bb49cf090..07ff8a819 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 000000000..eb82a7251 --- /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)); +