1
0
Fork 1
mirror of https://example.com synced 2024-11-24 06:46:39 +09:00
firefish/swagger.js

222 lines
5.3 KiB
JavaScript
Raw Normal View History

2017-01-04 13:56:20 +09:00
'use strict'
2017-01-04 12:59:20 +09:00
const swaggerJSDoc = require('swagger-jsdoc');
const fs = require('fs');
2017-01-04 13:56:20 +09:00
const yaml = require('js-yaml');
2017-01-04 12:59:20 +09:00
const apiRoot = './src/api/endpoints';
const files = [
'users.js',
2017-01-06 01:28:59 +09:00
//auth
'auth/accept.js',
//auth/session
'auth/session/generate.js',
2017-01-05 19:01:37 +09:00
'auth/session/show.js',
'auth/session/userkey.js',
2017-01-04 12:59:20 +09:00
];
2017-01-05 18:52:15 +09:00
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"
],
2017-01-06 00:53:28 +09:00
"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"
}
},
2017-01-05 18:52:15 +09: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"
},
"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"
}
}
2017-01-04 12:59:20 +09:00
}
2017-01-05 18:52:15 +09:00
},
"securityDefinitions": {},
"tags": []
};
2017-01-04 12:59:20 +09:00
var options = {
2017-01-05 18:52:15 +09:00
swaggerDefinition: defaultSwagger,
2017-01-04 12:59:20 +09:00
apis: []
};
options.apis = files.map(c => {return `${apiRoot}/${c}`;});
2017-01-04 13:56:20 +09:00
if(fs.existsSync('.config/config.yml')){
var config = yaml.safeLoad(fs.readFileSync('./.config/config.yml', 'utf8'));
2017-01-04 15:14:34 +09:00
options.swaggerDefinition.host = `api.${config.url}`;
2017-01-04 13:56:20 +09:00
options.swaggerDefinition.schemes = config.https.enable ? ['https'] : ['http'];
}
2017-01-04 12:59:20 +09:00
var swaggerSpec = swaggerJSDoc(options);
fs.writeFileSync('api-docs.json', JSON.stringify(swaggerSpec));