2017-01-04 05:56:20 +01:00
|
|
|
'use strict'
|
|
|
|
|
2017-01-04 04:59:20 +01:00
|
|
|
const swaggerJSDoc = require('swagger-jsdoc');
|
|
|
|
const fs = require('fs');
|
2017-01-04 05:56:20 +01:00
|
|
|
const yaml = require('js-yaml');
|
2017-01-04 04:59:20 +01:00
|
|
|
|
|
|
|
const apiRoot = './src/api/endpoints';
|
|
|
|
const files = [
|
2017-01-06 15:39:57 +01:00
|
|
|
'meta.js',
|
2017-01-06 08:16:53 +01:00
|
|
|
//app
|
|
|
|
'app/show.js',
|
2017-01-06 10:33:03 +01:00
|
|
|
'app/create.js',
|
2017-01-06 09:45:04 +01:00
|
|
|
'app/name_id/available.js',
|
2017-01-05 17:28:59 +01:00
|
|
|
//auth
|
|
|
|
'auth/accept.js',
|
|
|
|
//auth/session
|
2017-01-04 07:04:54 +01:00
|
|
|
'auth/session/generate.js',
|
2017-01-05 11:01:37 +01:00
|
|
|
'auth/session/show.js',
|
2017-01-04 07:04:54 +01:00
|
|
|
'auth/session/userkey.js',
|
2017-01-04 04:59:20 +01:00
|
|
|
];
|
|
|
|
|
2017-01-05 10:52:15 +01:00
|
|
|
const defaultSwagger = {
|
|
|
|
"swagger": "2.0",
|
|
|
|
"info": {
|
|
|
|
"title": "Misskey API",
|
2018-03-29 07:48:47 +02:00
|
|
|
"version": "nighthike"
|
2017-01-05 10:52:15 +01:00
|
|
|
},
|
2017-01-06 08:16:53 +01:00
|
|
|
"host": "api.misskey.xyz",
|
2017-01-05 10:52:15 +01:00
|
|
|
"schemes": [
|
2017-01-06 08:16:53 +01:00
|
|
|
"https"
|
2017-01-05 10:52:15 +01:00
|
|
|
],
|
|
|
|
"consumes": [
|
|
|
|
"application/x-www-form-urlencoded"
|
|
|
|
],
|
|
|
|
"produces": [
|
|
|
|
"application/json"
|
|
|
|
],
|
2017-01-05 16:53:28 +01:00
|
|
|
|
2017-01-06 08:16:53 +01:00
|
|
|
"parameters": {
|
2017-01-06 07:13:46 +01:00
|
|
|
"AccessToken": {
|
2017-01-05 16:53:28 +01:00
|
|
|
"name": "i",
|
2017-01-06 07:13:46 +01:00
|
|
|
"description": "Access Token",
|
2017-01-05 16:53:28 +01:00
|
|
|
"in": "formData",
|
|
|
|
"required": true,
|
|
|
|
"type": "string"
|
|
|
|
},
|
2017-01-06 07:13:46 +01:00
|
|
|
|
|
|
|
"NativeToken": {
|
2017-01-05 16:53:28 +01:00
|
|
|
"name": "i",
|
2017-01-06 07:13:46 +01:00
|
|
|
"description": "Native Access Token",
|
2017-01-05 16:53:28 +01:00
|
|
|
"in": "formData",
|
2017-01-06 07:13:46 +01:00
|
|
|
"required": true,
|
|
|
|
"type": "string",
|
|
|
|
"pattern": "^\!.+"
|
2017-01-05 16:53:28 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-01-05 10:52:15 +01:00
|
|
|
"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"
|
|
|
|
},
|
2018-03-29 07:48:47 +02:00
|
|
|
"avatarUrl": {
|
2017-01-05 10:52:15 +01:00
|
|
|
"type": "string",
|
|
|
|
"description": "アバターURL"
|
|
|
|
},
|
|
|
|
"banner_id": {
|
|
|
|
"type": "string",
|
|
|
|
"description": "バナーに設定しているドライブのファイルのID"
|
|
|
|
},
|
2018-03-29 07:48:47 +02:00
|
|
|
"bannerUrl": {
|
2017-01-05 10:52:15 +01:00
|
|
|
"type": "string",
|
|
|
|
"description": "バナーURL"
|
|
|
|
},
|
|
|
|
"bio": {
|
|
|
|
"type": "string",
|
|
|
|
"description": "プロフィール"
|
|
|
|
},
|
|
|
|
"birthday": {
|
|
|
|
"type": "string",
|
2017-01-06 08:19:41 +01:00
|
|
|
"format": "date",
|
2017-01-05 10:52:15 +01:00
|
|
|
"description": "誕生日"
|
|
|
|
},
|
|
|
|
"created_at": {
|
|
|
|
"type": "string",
|
2017-01-06 08:19:41 +01:00
|
|
|
"format": "date-time",
|
2017-01-05 10:52:15 +01:00
|
|
|
"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",
|
2017-01-06 08:19:41 +01:00
|
|
|
"format": "date-time",
|
2017-01-05 10:52:15 +01:00
|
|
|
"description": "アプリケーションの作成日時"
|
|
|
|
},
|
|
|
|
"user_id": {
|
|
|
|
"type": "string",
|
|
|
|
"description": "アプリケーションを作成したユーザーのID"
|
|
|
|
},
|
|
|
|
"name": {
|
|
|
|
"type": "string",
|
|
|
|
"description": "アプリケーションの名前"
|
|
|
|
},
|
2017-01-06 08:16:53 +01:00
|
|
|
"name_id": {
|
|
|
|
"type": "string",
|
|
|
|
"description": "アプリケーションのユニークな名前"
|
|
|
|
},
|
2017-01-05 10:52:15 +01:00
|
|
|
"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"
|
|
|
|
}
|
|
|
|
}
|
2017-01-04 04:59:20 +01:00
|
|
|
}
|
2017-01-05 10:52:15 +01:00
|
|
|
},
|
|
|
|
"securityDefinitions": {},
|
|
|
|
"tags": []
|
|
|
|
};
|
2017-01-04 04:59:20 +01:00
|
|
|
|
|
|
|
var options = {
|
2017-01-05 10:52:15 +01:00
|
|
|
swaggerDefinition: defaultSwagger,
|
2017-01-04 04:59:20 +01:00
|
|
|
apis: []
|
|
|
|
};
|
|
|
|
options.apis = files.map(c => {return `${apiRoot}/${c}`;});
|
|
|
|
|
2017-01-04 05:56:20 +01:00
|
|
|
if(fs.existsSync('.config/config.yml')){
|
|
|
|
var config = yaml.safeLoad(fs.readFileSync('./.config/config.yml', 'utf8'));
|
2017-01-06 15:39:57 +01:00
|
|
|
options.swaggerDefinition.host = `api.${config.url.match(/\:\/\/(.+)$/)[1]}`;
|
2018-03-29 07:48:47 +02:00
|
|
|
options.swaggerDefinition.schemes = config.https.enable ?
|
|
|
|
['https'] :
|
2017-01-06 08:16:53 +01:00
|
|
|
['http'];
|
2017-01-04 05:56:20 +01:00
|
|
|
}
|
|
|
|
|
2017-01-04 04:59:20 +01:00
|
|
|
var swaggerSpec = swaggerJSDoc(options);
|
|
|
|
|
|
|
|
fs.writeFileSync('api-docs.json', JSON.stringify(swaggerSpec));
|
|
|
|
|