From e62b008c71a216139fdc934174dc5f7376ca5c04 Mon Sep 17 00:00:00 2001 From: Tosuke Date: Wed, 4 Jan 2017 12:59:20 +0900 Subject: [PATCH 01/17] [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 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)); + From 972f0e7f41fc133f1ae7ad2d9fdd87e5dd7cbac0 Mon Sep 17 00:00:00 2001 From: Tosuke Date: Wed, 4 Jan 2017 13:56:20 +0900 Subject: [PATCH 02/17] Add host and schemes to swaggerJSON --- swagger.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/swagger.js b/swagger.js index eb82a72516..a7046e3bd5 100644 --- a/swagger.js +++ b/swagger.js @@ -1,5 +1,8 @@ +'use strict' + const swaggerJSDoc = require('swagger-jsdoc'); const fs = require('fs'); +const yaml = require('js-yaml'); const apiRoot = './src/api/endpoints'; const files = [ @@ -23,6 +26,8 @@ var options = { title: 'Misskey API', version: 'aoi', }, + host: 'api.misskey.xyz', + schemes: ['https'], consumes: [ 'application/x-www-form-urlencoded' ], @@ -34,6 +39,12 @@ var options = { }; options.apis = files.map(c => {return `${apiRoot}/${c}`;}); +if(fs.existsSync('.config/config.yml')){ + var config = yaml.safeLoad(fs.readFileSync('./.config/config.yml', 'utf8')); + options.swaggerDefinition.host = config.url; + options.swaggerDefinition.schemes = config.https.enable ? ['https'] : ['http']; +} + var swaggerSpec = swaggerJSDoc(options); swaggerSpec.definitions.Error = errorDefinition; From 4dd5a443e5c6dc9248dd1e771063aa2071f521f5 Mon Sep 17 00:00:00 2001 From: Tosuke Date: Wed, 4 Jan 2017 15:04:54 +0900 Subject: [PATCH 03/17] [WIP][Swagger]Add swagger definition - /auth/session/userkey - User entity --- src/api/endpoints/auth/session/generate.js | 1 + src/api/endpoints/auth/session/userkey.js | 36 ++++++++++ src/api/endpoints/users.js | 76 ++++++++++++++++++++++ swagger.js | 4 +- 4 files changed, 116 insertions(+), 1 deletion(-) diff --git a/src/api/endpoints/auth/session/generate.js b/src/api/endpoints/auth/session/generate.js index 07ff8a8195..1390ae2909 100644 --- a/src/api/endpoints/auth/session/generate.js +++ b/src/api/endpoints/auth/session/generate.js @@ -15,6 +15,7 @@ import AuthSess from '../../../models/auth-session'; * parameters: * - * name: app_secret + * description: App Secret * in: formData * required: true * type: string diff --git a/src/api/endpoints/auth/session/userkey.js b/src/api/endpoints/auth/session/userkey.js index 2626e4ce39..918caa8f39 100644 --- a/src/api/endpoints/auth/session/userkey.js +++ b/src/api/endpoints/auth/session/userkey.js @@ -8,6 +8,42 @@ import AuthSess from '../../../models/auth-session'; import Userkey from '../../../models/userkey'; import serialize from '../../../serializers/user'; +/** + * @swagger + * /auth/session/userkey: + * post: + * summary: Get a userkey + * parameters: + * - + * name: app_secret + * description: App Secret + * in: formData + * required: true + * type: string + * - + * name: token + * description: API Token + * in: formData + * required: true + * type: string + * + * responses: + * 200: + * description: OK + * schema: + * type: object + * properties: + * userkey: + * type: string + * description: User Key + * user: + * $ref: "#/definitions/User" + * 400: + * description: Failed + * schema: + * $ref: "#/definitions/Error" + */ + /** * Generate a session * diff --git a/src/api/endpoints/users.js b/src/api/endpoints/users.js index cd40cdf4e1..bb47b4b64a 100644 --- a/src/api/endpoints/users.js +++ b/src/api/endpoints/users.js @@ -6,6 +6,82 @@ import User from '../models/user'; import serialize from '../serializers/user'; +/** + * @swagger + * definitions: + * User: + * type: object + * required: + * - created_at + * - followers_count + * - following_count + * - id + * - liked_count + * - likes_count + * - name + * - posts_count + * - username + * properties: + * avatar_id: + * type: string + * description: アバターに設定しているドライブのファイルのID + * avatar_url: + * type: string + * description: アバターURL + * banner_id: + * type: string + * description: バナーに設定しているドライブのファイルのID + * banner_url: + * type: string + * description: バナーURL + * bio: + * type: string + * description: プロフィール + * birthday: + * type: string + * description: 誕生日 + * created_at: + * type: string + * format: date + * description: アカウント作成日時 + * drive_capacity: + * type: integer + * description: ドライブの最大容量 + * followers_count: + * type: integer + * description: フォロワー数 + * following_count: + * type: integer + * description: フォロー数 + * id: + * type: string + * description: ユーザーID + * is_followed: + * type: boolean + * description: フォローされているか + * is_following: + * type: boolean + * description: フォローしているか + * liked_count: + * type: integer + * description: 投稿にいいねされた数 + * likes_count: + * type: integer + * description: 投稿にいいねした数 + * location: + * type: string + * description: 場所 + * name: + * type: string + * description: ニックネーム + * posts_count: + * type: integer + * description: 投稿数 + * username: + * type: string + * description: ユーザー名 + */ + /** * Lists all users * diff --git a/swagger.js b/swagger.js index a7046e3bd5..9cb5e85095 100644 --- a/swagger.js +++ b/swagger.js @@ -6,7 +6,9 @@ const yaml = require('js-yaml'); const apiRoot = './src/api/endpoints'; const files = [ - 'auth/session/generate.js' + 'users.js', + 'auth/session/generate.js', + 'auth/session/userkey.js', ]; const errorDefinition = { From 08aeaf6c646f6b2a9028a5392adc366b588af774 Mon Sep 17 00:00:00 2001 From: Tosuke Date: Wed, 4 Jan 2017 15:14:34 +0900 Subject: [PATCH 04/17] FIx bug --- swagger.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swagger.js b/swagger.js index 9cb5e85095..1f430555ae 100644 --- a/swagger.js +++ b/swagger.js @@ -43,7 +43,7 @@ options.apis = files.map(c => {return `${apiRoot}/${c}`;}); if(fs.existsSync('.config/config.yml')){ var config = yaml.safeLoad(fs.readFileSync('./.config/config.yml', 'utf8')); - options.swaggerDefinition.host = config.url; + options.swaggerDefinition.host = `api.${config.url}`; options.swaggerDefinition.schemes = config.https.enable ? ['https'] : ['http']; } From 25b5456a329ff8cb1348fd30bdf52b0933a4b5d4 Mon Sep 17 00:00:00 2001 From: Tosuke Date: Thu, 5 Jan 2017 18:52:15 +0900 Subject: [PATCH 05/17] Add default definition --- swagger.js | 192 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 168 insertions(+), 24 deletions(-) diff --git a/swagger.js b/swagger.js index 1f430555ae..9501c4eb3b 100644 --- a/swagger.js +++ b/swagger.js @@ -11,32 +11,175 @@ const files = [ 'auth/session/userkey.js', ]; -const errorDefinition = { - 'type': 'object', - 'properties':{ - 'error': { - 'type': 'string', - 'description': 'Error message' +const defaultSwagger = { + "swagger": "2.0", + "info": { + "title": "Misskey API", + "version": "aoi" + }, + "host": "api.misskey.local", + "schemes": [ + "http" + ], + "consumes": [ + "application/x-www-form-urlencoded" + ], + "produces": [ + "application/json" + ], + "definitions": { + "Error": { + "type": "object", + "properties": { + "error": { + "type": "string", + "description": "Error message" + } + } + }, + "User": { + "type": "object", + "required": [ + "created_at", + "followers_count", + "following_count", + "id", + "liked_count", + "likes_count", + "name", + "posts_count", + "username" + ], + "properties": { + "avatar_id": { + "type": "string", + "description": "アバターに設定しているドライブのファイルのID" + }, + "avatar_url": { + "type": "string", + "description": "アバターURL" + }, + "banner_id": { + "type": "string", + "description": "バナーに設定しているドライブのファイルのID" + }, + "banner_url": { + "type": "string", + "description": "バナーURL" + }, + "bio": { + "type": "string", + "description": "プロフィール" + }, + "birthday": { + "type": "string", + "description": "誕生日" + }, + "created_at": { + "type": "string", + "format": "date", + "description": "アカウント作成日時" + }, + "drive_capacity": { + "type": "integer", + "description": "ドライブの最大容量" + }, + "followers_count": { + "type": "integer", + "description": "フォロワー数" + }, + "following_count": { + "type": "integer", + "description": "フォロー数" + }, + "id": { + "type": "string", + "description": "ユーザーID" + }, + "is_followed": { + "type": "boolean", + "description": "フォローされているか" + }, + "is_following": { + "type": "boolean", + "description": "フォローしているか" + }, + "liked_count": { + "type": "integer", + "description": "投稿にいいねされた数" + }, + "likes_count": { + "type": "integer", + "description": "投稿にいいねした数" + }, + "location": { + "type": "string", + "description": "場所" + }, + "name": { + "type": "string", + "description": "ニックネーム" + }, + "posts_count": { + "type": "integer", + "description": "投稿数" + }, + "username": { + "type": "string", + "description": "ユーザー名" + } + } + }, + "Application": { + "type": "object", + "properties": { + "created_at": { + "type": "string", + "format": "date", + "description": "アプリケーションの作成日時" + }, + "user_id": { + "type": "string", + "description": "アプリケーションを作成したユーザーのID" + }, + "name": { + "type": "string", + "description": "アプリケーションの名前" + }, + "description": { + "type": "string", + "description": "アプリケーションの説明" + }, + "permission": { + "type": "array", + "items": { + "type": "string" + }, + "description": "アプリケーションの持つ権限一覧" + }, + "callback_url": { + "type": "string", + "description": "コールバックURL" + }, + "id": { + "type": "string", + "description": "アプリケーションID" + }, + "icon_url": { + "type": "string", + "description": "アプリケーションのアイコンのURL" + } + } } - } -} + }, + "responses": {}, + "parameters": {}, + "securityDefinitions": {}, + "tags": [] +}; var options = { - swaggerDefinition: { - swagger: '2.0', - info: { - title: 'Misskey API', - version: 'aoi', - }, - host: 'api.misskey.xyz', - schemes: ['https'], - consumes: [ - 'application/x-www-form-urlencoded' - ], - produces: [ - 'application/json' - ] - }, + swaggerDefinition: defaultSwagger, apis: [] }; options.apis = files.map(c => {return `${apiRoot}/${c}`;}); @@ -48,7 +191,8 @@ if(fs.existsSync('.config/config.yml')){ } var swaggerSpec = swaggerJSDoc(options); -swaggerSpec.definitions.Error = errorDefinition; fs.writeFileSync('api-docs.json', JSON.stringify(swaggerSpec)); +console.log(JSON.stringify(swaggerSpec)); + From 923b9448f680325d36f1ea6b283495f308bcb460 Mon Sep 17 00:00:00 2001 From: Tosuke Date: Thu, 5 Jan 2017 18:52:55 +0900 Subject: [PATCH 06/17] remove 'User' definition --- src/api/endpoints/users.js | 76 -------------------------------------- 1 file changed, 76 deletions(-) diff --git a/src/api/endpoints/users.js b/src/api/endpoints/users.js index bb47b4b64a..cd40cdf4e1 100644 --- a/src/api/endpoints/users.js +++ b/src/api/endpoints/users.js @@ -6,82 +6,6 @@ import User from '../models/user'; import serialize from '../serializers/user'; -/** - * @swagger - * definitions: - * User: - * type: object - * required: - * - created_at - * - followers_count - * - following_count - * - id - * - liked_count - * - likes_count - * - name - * - posts_count - * - username - * properties: - * avatar_id: - * type: string - * description: アバターに設定しているドライブのファイルのID - * avatar_url: - * type: string - * description: アバターURL - * banner_id: - * type: string - * description: バナーに設定しているドライブのファイルのID - * banner_url: - * type: string - * description: バナーURL - * bio: - * type: string - * description: プロフィール - * birthday: - * type: string - * description: 誕生日 - * created_at: - * type: string - * format: date - * description: アカウント作成日時 - * drive_capacity: - * type: integer - * description: ドライブの最大容量 - * followers_count: - * type: integer - * description: フォロワー数 - * following_count: - * type: integer - * description: フォロー数 - * id: - * type: string - * description: ユーザーID - * is_followed: - * type: boolean - * description: フォローされているか - * is_following: - * type: boolean - * description: フォローしているか - * liked_count: - * type: integer - * description: 投稿にいいねされた数 - * likes_count: - * type: integer - * description: 投稿にいいねした数 - * location: - * type: string - * description: 場所 - * name: - * type: string - * description: ニックネーム - * posts_count: - * type: integer - * description: 投稿数 - * username: - * type: string - * description: ユーザー名 - */ - /** * Lists all users * From 41ea59d77c85b1a3f12508156e814878ae53dcba Mon Sep 17 00:00:00 2001 From: Tosuke Date: Thu, 5 Jan 2017 19:01:37 +0900 Subject: [PATCH 07/17] [Swagger]Add /auth/session/show --- src/api/endpoints/auth/session/show.js | 40 ++++++++++++++++++++++++++ swagger.js | 3 +- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/api/endpoints/auth/session/show.js b/src/api/endpoints/auth/session/show.js index 67160c6993..b64e36a5e9 100644 --- a/src/api/endpoints/auth/session/show.js +++ b/src/api/endpoints/auth/session/show.js @@ -6,6 +6,46 @@ import AuthSess from '../../../models/auth-session'; import serialize from '../../../serializers/auth-session'; +/** + * @swagger + * /auth/session/show: + * post: + * summary: Show a session information + * parameters: + * - + * name: token + * description: API Token + * in: formData + * required: true + * type: string + * + * responses: + * 200: + * description: OK + * schema: + * type: object + * properties: + * created_at: + * type: string + * format: date + * description: de + * app_id: + * type: string + * description: Application ID + * token: + * type: string + * description: API Token + * user_id: + * type: string + * description: de + * app: + * $ref: "#/definitions/Application" + * 400: + * description: Failed + * schema: + * $ref: "#/definitions/Error" + */ + /** * Show a session * diff --git a/swagger.js b/swagger.js index 9501c4eb3b..defd31b281 100644 --- a/swagger.js +++ b/swagger.js @@ -8,6 +8,7 @@ const apiRoot = './src/api/endpoints'; const files = [ 'users.js', 'auth/session/generate.js', + 'auth/session/show.js', 'auth/session/userkey.js', ]; @@ -194,5 +195,3 @@ var swaggerSpec = swaggerJSDoc(options); fs.writeFileSync('api-docs.json', JSON.stringify(swaggerSpec)); -console.log(JSON.stringify(swaggerSpec)); - From f0d05d5db31d36db9fb99801ef815fd54a5d169c Mon Sep 17 00:00:00 2001 From: Tosuke Date: Thu, 5 Jan 2017 23:42:27 +0900 Subject: [PATCH 08/17] [Swagger]Fix name --- src/api/endpoints/auth/session/generate.js | 4 ++-- src/api/endpoints/auth/session/show.js | 2 +- src/api/endpoints/auth/session/userkey.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/endpoints/auth/session/generate.js b/src/api/endpoints/auth/session/generate.js index 1390ae2909..626bf2af4a 100644 --- a/src/api/endpoints/auth/session/generate.js +++ b/src/api/endpoints/auth/session/generate.js @@ -28,10 +28,10 @@ import AuthSess from '../../../models/auth-session'; * properties: * token: * type: string - * description: API Token + * description: Session Token * url: * type: string - * description: Callback URL + * description: Authentication form's URL * 400: * description: Failed * schema: diff --git a/src/api/endpoints/auth/session/show.js b/src/api/endpoints/auth/session/show.js index b64e36a5e9..f7fb981e37 100644 --- a/src/api/endpoints/auth/session/show.js +++ b/src/api/endpoints/auth/session/show.js @@ -34,7 +34,7 @@ import serialize from '../../../serializers/auth-session'; * description: Application ID * token: * type: string - * description: API Token + * description: Session Token * user_id: * type: string * description: de diff --git a/src/api/endpoints/auth/session/userkey.js b/src/api/endpoints/auth/session/userkey.js index 918caa8f39..f823d62c71 100644 --- a/src/api/endpoints/auth/session/userkey.js +++ b/src/api/endpoints/auth/session/userkey.js @@ -22,7 +22,7 @@ import serialize from '../../../serializers/user'; * type: string * - * name: token - * description: API Token + * description: Session Token * in: formData * required: true * type: string From 24b82c30e85e774ac10aa4af112146b9bf621052 Mon Sep 17 00:00:00 2001 From: Tosuke Date: Fri, 6 Jan 2017 00:39:56 +0900 Subject: [PATCH 09/17] [Swagger]Fix Error --- src/api/endpoints/auth/session/generate.js | 2 +- src/api/endpoints/auth/session/show.js | 2 +- src/api/endpoints/auth/session/userkey.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/api/endpoints/auth/session/generate.js b/src/api/endpoints/auth/session/generate.js index 626bf2af4a..f67209eee3 100644 --- a/src/api/endpoints/auth/session/generate.js +++ b/src/api/endpoints/auth/session/generate.js @@ -32,7 +32,7 @@ import AuthSess from '../../../models/auth-session'; * url: * type: string * description: Authentication form's URL - * 400: + * default: * description: Failed * schema: * $ref: "#/definitions/Error" diff --git a/src/api/endpoints/auth/session/show.js b/src/api/endpoints/auth/session/show.js index f7fb981e37..c91ac5a12e 100644 --- a/src/api/endpoints/auth/session/show.js +++ b/src/api/endpoints/auth/session/show.js @@ -40,7 +40,7 @@ import serialize from '../../../serializers/auth-session'; * description: de * app: * $ref: "#/definitions/Application" - * 400: + * default: * description: Failed * schema: * $ref: "#/definitions/Error" diff --git a/src/api/endpoints/auth/session/userkey.js b/src/api/endpoints/auth/session/userkey.js index f823d62c71..73fa643c9c 100644 --- a/src/api/endpoints/auth/session/userkey.js +++ b/src/api/endpoints/auth/session/userkey.js @@ -38,7 +38,7 @@ import serialize from '../../../serializers/user'; * description: User Key * user: * $ref: "#/definitions/User" - * 400: + * default: * description: Failed * schema: * $ref: "#/definitions/Error" From 2a0291e2854854a67c1c3dc40fef7a6f43b2bd38 Mon Sep 17 00:00:00 2001 From: Tosuke Date: Fri, 6 Jan 2017 00:53:28 +0900 Subject: [PATCH 10/17] [Swagger]Add response definitions --- swagger.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/swagger.js b/swagger.js index defd31b281..91b96e1f45 100644 --- a/swagger.js +++ b/swagger.js @@ -28,6 +28,29 @@ const defaultSwagger = { "produces": [ "application/json" ], + + "responses": { + "ShouldSecureKey": { + "name": "i", + "description": "secure key", + "in": "formData", + "required": true, + "type": "string" + }, + "SecureKey": { + "name": "i", + "description": "secure key", + "in": "formData", + "type": "string" + }, + "NormalKey": { + "name": "_userkey", + "description": "normal key", + "in": "formData", + "type": "string" + } + }, + "definitions": { "Error": { "type": "object", @@ -173,8 +196,6 @@ const defaultSwagger = { } } }, - "responses": {}, - "parameters": {}, "securityDefinitions": {}, "tags": [] }; From 43290a9ea3456b7d44efea5ae856c40366408cf3 Mon Sep 17 00:00:00 2001 From: Tosuke Date: Fri, 6 Jan 2017 01:28:59 +0900 Subject: [PATCH 11/17] [Swagger]Add /auth/accept --- src/api/endpoints/auth/accept.js | 23 +++++++++++++++++++++++ swagger.js | 3 +++ 2 files changed, 26 insertions(+) diff --git a/src/api/endpoints/auth/accept.js b/src/api/endpoints/auth/accept.js index 7c45650c6b..e584513c05 100644 --- a/src/api/endpoints/auth/accept.js +++ b/src/api/endpoints/auth/accept.js @@ -7,6 +7,29 @@ import rndstr from 'rndstr'; import AuthSess from '../../models/auth-session'; import Userkey from '../../models/userkey'; +/** + * @swagger + * /auth/accept: + * post: + * summary: Accept a session + * parameters: + * - $ref: "#/parameters/ShouldSecureKey" + * - + * name: token + * description: Session Token + * in: formData + * required: true + * type: string + * responses: + * 204: + * description: OK + * + * default: + * description: Failed + * schema: + * $ref: "#/definitions/Error" + */ + /** * Accept * diff --git a/swagger.js b/swagger.js index 91b96e1f45..16e1a0bf02 100644 --- a/swagger.js +++ b/swagger.js @@ -7,6 +7,9 @@ const yaml = require('js-yaml'); const apiRoot = './src/api/endpoints'; const files = [ 'users.js', + //auth + 'auth/accept.js', + //auth/session 'auth/session/generate.js', 'auth/session/show.js', 'auth/session/userkey.js', From 55f8cb4274b784e5281332c85875ef83c148d716 Mon Sep 17 00:00:00 2001 From: Tosuke Date: Fri, 6 Jan 2017 15:13:46 +0900 Subject: [PATCH 12/17] [Swagger]Following changes --- src/api/endpoints/auth/accept.js | 2 +- src/api/endpoints/auth/session/show.js | 6 +++--- src/api/endpoints/auth/session/userkey.js | 4 ++-- swagger.js | 26 +++++++++++------------ 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/api/endpoints/auth/accept.js b/src/api/endpoints/auth/accept.js index d60d95aea3..131a0e5611 100644 --- a/src/api/endpoints/auth/accept.js +++ b/src/api/endpoints/auth/accept.js @@ -15,7 +15,7 @@ import AccessToken from '../../models/access-token'; * post: * summary: Accept a session * parameters: - * - $ref: "#/parameters/ShouldSecureKey" + * - $ref: "#/parameters/NativeToken" * - * name: token * description: Session Token diff --git a/src/api/endpoints/auth/session/show.js b/src/api/endpoints/auth/session/show.js index c91ac5a12e..9072edc1c0 100644 --- a/src/api/endpoints/auth/session/show.js +++ b/src/api/endpoints/auth/session/show.js @@ -14,7 +14,7 @@ import serialize from '../../../serializers/auth-session'; * parameters: * - * name: token - * description: API Token + * description: Session Token * in: formData * required: true * type: string @@ -28,7 +28,7 @@ import serialize from '../../../serializers/auth-session'; * created_at: * type: string * format: date - * description: de + * description: Date and time of the session creation * app_id: * type: string * description: Application ID @@ -37,7 +37,7 @@ import serialize from '../../../serializers/auth-session'; * description: Session Token * user_id: * type: string - * description: de + * description: ID of user who create the session * app: * $ref: "#/definitions/Application" * default: diff --git a/src/api/endpoints/auth/session/userkey.js b/src/api/endpoints/auth/session/userkey.js index 9252046e57..9905d7d844 100644 --- a/src/api/endpoints/auth/session/userkey.js +++ b/src/api/endpoints/auth/session/userkey.js @@ -12,7 +12,7 @@ import serialize from '../../../serializers/user'; * @swagger * /auth/session/userkey: * post: - * summary: Get a userkey + * summary: Get a access token(userkey) * parameters: * - * name: app_secret @@ -35,7 +35,7 @@ import serialize from '../../../serializers/user'; * properties: * userkey: * type: string - * description: User Key + * description: Access Token * user: * $ref: "#/definitions/User" * default: diff --git a/swagger.js b/swagger.js index 16e1a0bf02..e9fb84a093 100644 --- a/swagger.js +++ b/swagger.js @@ -23,7 +23,8 @@ const defaultSwagger = { }, "host": "api.misskey.local", "schemes": [ - "http" + "http", + "ws" ], "consumes": [ "application/x-www-form-urlencoded" @@ -33,24 +34,21 @@ const defaultSwagger = { ], "responses": { - "ShouldSecureKey": { + "AccessToken": { "name": "i", - "description": "secure key", + "description": "Access Token", "in": "formData", "required": true, "type": "string" }, - "SecureKey": { + + "NativeToken": { "name": "i", - "description": "secure key", + "description": "Native Access Token", "in": "formData", - "type": "string" - }, - "NormalKey": { - "name": "_userkey", - "description": "normal key", - "in": "formData", - "type": "string" + "required": true, + "type": "string", + "pattern": "^\!.+" } }, @@ -212,7 +210,9 @@ options.apis = files.map(c => {return `${apiRoot}/${c}`;}); if(fs.existsSync('.config/config.yml')){ var config = yaml.safeLoad(fs.readFileSync('./.config/config.yml', 'utf8')); options.swaggerDefinition.host = `api.${config.url}`; - options.swaggerDefinition.schemes = config.https.enable ? ['https'] : ['http']; + options.swaggerDefinition.schemes = config.https.enable ? + ['https', 'wss'] : + ['http', 'ws']; } var swaggerSpec = swaggerJSDoc(options); From ac0824b57477051bddb8a43392f45a9d5492c3e2 Mon Sep 17 00:00:00 2001 From: Tosuke Date: Fri, 6 Jan 2017 16:16:53 +0900 Subject: [PATCH 13/17] [Swagger]Add /app/show --- src/api/endpoints/app/show.js | 30 ++++++++++++++++++++++++++++++ swagger.js | 17 +++++++++++------ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/api/endpoints/app/show.js b/src/api/endpoints/app/show.js index 8d12f9aeb1..2b651d53a9 100644 --- a/src/api/endpoints/app/show.js +++ b/src/api/endpoints/app/show.js @@ -7,6 +7,36 @@ import * as mongo from 'mongodb'; import App from '../../models/app'; import serialize from '../../serializers/app'; +/** + * @swagger + * /app/show: + * post: + * summary: Show an application's information + * description: Require app_id or name_id + * parameters: + * - + * name: app_id + * description: Application ID + * in: formData + * type: string + * - + * name: name_id + * description: Application unique name + * in: formData + * type: string + * + * responses: + * 200: + * description: Success + * schema: + * $ref: "#/definitions/Application" + * + * default: + * description: Failed + * schema: + * $ref: "#/definitions/Error" + */ + /** * Show an app * diff --git a/swagger.js b/swagger.js index e9fb84a093..0deff2c5a3 100644 --- a/swagger.js +++ b/swagger.js @@ -7,6 +7,8 @@ const yaml = require('js-yaml'); const apiRoot = './src/api/endpoints'; const files = [ 'users.js', + //app + 'app/show.js', //auth 'auth/accept.js', //auth/session @@ -21,10 +23,9 @@ const defaultSwagger = { "title": "Misskey API", "version": "aoi" }, - "host": "api.misskey.local", + "host": "api.misskey.xyz", "schemes": [ - "http", - "ws" + "https" ], "consumes": [ "application/x-www-form-urlencoded" @@ -33,7 +34,7 @@ const defaultSwagger = { "application/json" ], - "responses": { + "parameters": { "AccessToken": { "name": "i", "description": "Access Token", @@ -171,6 +172,10 @@ const defaultSwagger = { "type": "string", "description": "アプリケーションの名前" }, + "name_id": { + "type": "string", + "description": "アプリケーションのユニークな名前" + }, "description": { "type": "string", "description": "アプリケーションの説明" @@ -211,8 +216,8 @@ if(fs.existsSync('.config/config.yml')){ var config = yaml.safeLoad(fs.readFileSync('./.config/config.yml', 'utf8')); options.swaggerDefinition.host = `api.${config.url}`; options.swaggerDefinition.schemes = config.https.enable ? - ['https', 'wss'] : - ['http', 'ws']; + ['https'] : + ['http']; } var swaggerSpec = swaggerJSDoc(options); From b2dad3a9c2df8faff2aa8baa01016650614a8a8d Mon Sep 17 00:00:00 2001 From: Tosuke Date: Fri, 6 Jan 2017 16:19:41 +0900 Subject: [PATCH 14/17] [Swagger]Fix date format --- src/api/endpoints/auth/session/show.js | 2 +- swagger.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/api/endpoints/auth/session/show.js b/src/api/endpoints/auth/session/show.js index 9072edc1c0..e161d9e576 100644 --- a/src/api/endpoints/auth/session/show.js +++ b/src/api/endpoints/auth/session/show.js @@ -27,7 +27,7 @@ import serialize from '../../../serializers/auth-session'; * properties: * created_at: * type: string - * format: date + * format: date-time * description: Date and time of the session creation * app_id: * type: string diff --git a/swagger.js b/swagger.js index 0deff2c5a3..a4122350fe 100644 --- a/swagger.js +++ b/swagger.js @@ -99,11 +99,12 @@ const defaultSwagger = { }, "birthday": { "type": "string", + "format": "date", "description": "誕生日" }, "created_at": { "type": "string", - "format": "date", + "format": "date-time", "description": "アカウント作成日時" }, "drive_capacity": { @@ -161,7 +162,7 @@ const defaultSwagger = { "properties": { "created_at": { "type": "string", - "format": "date", + "format": "date-time", "description": "アプリケーションの作成日時" }, "user_id": { From 66d6f4420edde0284f5c4012596a080e1f5ca3d7 Mon Sep 17 00:00:00 2001 From: Tosuke Date: Fri, 6 Jan 2017 17:45:04 +0900 Subject: [PATCH 15/17] [Swagger]Add /app/name_id/available --- src/api/endpoints/app/name_id/available.js | 29 ++++++++++++++++++++++ swagger.js | 1 + 2 files changed, 30 insertions(+) diff --git a/src/api/endpoints/app/name_id/available.js b/src/api/endpoints/app/name_id/available.js index 179925dce4..e101e0637f 100644 --- a/src/api/endpoints/app/name_id/available.js +++ b/src/api/endpoints/app/name_id/available.js @@ -5,6 +5,35 @@ */ import App from '../../../models/app'; +/** + * @swagger + * /app/name_id/available: + * post: + * summary: Check available name_id on creation an application + * parameters: + * - + * name: name_id + * description: Application unique name + * in: formData + * required: true + * type: string + * + * responses: + * 200: + * description: Success + * schema: + * type: object + * properties: + * available: + * description: Whether name_id is available + * type: boolean + * + * default: + * description: Failed + * schema: + * $ref: "#/definitions/Error" + */ + /** * Check available name_id of app * diff --git a/swagger.js b/swagger.js index a4122350fe..9391e80c5a 100644 --- a/swagger.js +++ b/swagger.js @@ -9,6 +9,7 @@ const files = [ 'users.js', //app 'app/show.js', + 'app/name_id/available.js', //auth 'auth/accept.js', //auth/session From a5ff6fb285eeb3b6ecce59b846a1f610a89a11c2 Mon Sep 17 00:00:00 2001 From: Tosuke Date: Fri, 6 Jan 2017 18:33:03 +0900 Subject: [PATCH 16/17] [Swagger]Add /app/create --- src/api/endpoints/app/create.js | 53 +++++++++++++++++++++++++++++++++ swagger.js | 1 + 2 files changed, 54 insertions(+) diff --git a/src/api/endpoints/app/create.js b/src/api/endpoints/app/create.js index d83062c8e9..9ce98b197a 100644 --- a/src/api/endpoints/app/create.js +++ b/src/api/endpoints/app/create.js @@ -7,6 +7,59 @@ import rndstr from 'rndstr'; import App from '../../models/app'; import serialize from '../../serializers/app'; +/** + * @swagger + * /app/create: + * post: + * summary: Create an application + * parameters: + * - $ref: "#/parameters/AccessToken" + * - + * name: name_id + * description: Application unique name + * in: formData + * required: true + * type: string + * - + * name: name + * description: Application name + * in: formData + * required: true + * type: string + * - + * name: description + * description: Application description + * in: formData + * required: true + * type: string + * - + * name: permission + * description: Permissions that application has + * in: formData + * required: true + * type: array + * items: + * type: string + * collectionFormat: csv + * - + * name: callback_url + * description: URL called back after authentication + * in: formData + * required: false + * type: string + * + * responses: + * 200: + * description: Created application's information + * schema: + * $ref: "#/definitions/Application" + * + * default: + * description: Failed + * schema: + * $ref: "#/definitions/Error" + */ + /** * Create an app * diff --git a/swagger.js b/swagger.js index 9391e80c5a..4a23ebacb3 100644 --- a/swagger.js +++ b/swagger.js @@ -9,6 +9,7 @@ const files = [ 'users.js', //app 'app/show.js', + 'app/create.js', 'app/name_id/available.js', //auth 'auth/accept.js', From 8149723abf215a51f495fd3232e597eabc05f544 Mon Sep 17 00:00:00 2001 From: Tosuke Date: Fri, 6 Jan 2017 23:39:57 +0900 Subject: [PATCH 17/17] [Swagger]Add /meta --- src/api/endpoints/meta.js | 27 +++++++++++++++++++++++++++ swagger.js | 4 ++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/api/endpoints/meta.js b/src/api/endpoints/meta.js index 7938cb91b4..58ed3824cc 100644 --- a/src/api/endpoints/meta.js +++ b/src/api/endpoints/meta.js @@ -5,6 +5,33 @@ */ import Git from 'nodegit'; +/** + * @swagger + * /meta: + * post: + * summary: Show the misskey's information + * responses: + * 200: + * description: Success + * schema: + * type: object + * properties: + * maintainer: + * description: maintainer's name + * type: string + * commit: + * description: latest commit's hash + * type: string + * secure: + * description: whether the server supports secure protcols + * type: boolean + * + * default: + * description: Failed + * schema: + * $ref: "#/definitions/Error" + */ + /** * Show core info * diff --git a/swagger.js b/swagger.js index 4a23ebacb3..0cfd2fff08 100644 --- a/swagger.js +++ b/swagger.js @@ -6,7 +6,7 @@ const yaml = require('js-yaml'); const apiRoot = './src/api/endpoints'; const files = [ - 'users.js', + 'meta.js', //app 'app/show.js', 'app/create.js', @@ -217,7 +217,7 @@ options.apis = files.map(c => {return `${apiRoot}/${c}`;}); if(fs.existsSync('.config/config.yml')){ var config = yaml.safeLoad(fs.readFileSync('./.config/config.yml', 'utf8')); - options.swaggerDefinition.host = `api.${config.url}`; + options.swaggerDefinition.host = `api.${config.url.match(/\:\/\/(.+)$/)[1]}`; options.swaggerDefinition.schemes = config.https.enable ? ['https'] : ['http'];