2017-01-04 04:56:20 +00:00
|
|
|
'use strict'
|
|
|
|
|
2017-01-04 03:59:20 +00:00
|
|
|
const swaggerJSDoc = require('swagger-jsdoc');
|
|
|
|
const fs = require('fs');
|
2017-01-04 04:56:20 +00:00
|
|
|
const yaml = require('js-yaml');
|
2017-01-04 03:59:20 +00:00
|
|
|
|
|
|
|
const apiRoot = './src/api/endpoints';
|
|
|
|
const files = [
|
2017-01-04 06:04:54 +00:00
|
|
|
'users.js',
|
|
|
|
'auth/session/generate.js',
|
|
|
|
'auth/session/userkey.js',
|
2017-01-04 03:59:20 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
const errorDefinition = {
|
|
|
|
'type': 'object',
|
|
|
|
'properties':{
|
|
|
|
'error': {
|
|
|
|
'type': 'string',
|
|
|
|
'description': 'Error message'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
swaggerDefinition: {
|
|
|
|
swagger: '2.0',
|
|
|
|
info: {
|
|
|
|
title: 'Misskey API',
|
|
|
|
version: 'aoi',
|
|
|
|
},
|
2017-01-04 04:56:20 +00:00
|
|
|
host: 'api.misskey.xyz',
|
|
|
|
schemes: ['https'],
|
2017-01-04 03:59:20 +00:00
|
|
|
consumes: [
|
|
|
|
'application/x-www-form-urlencoded'
|
|
|
|
],
|
|
|
|
produces: [
|
|
|
|
'application/json'
|
|
|
|
]
|
|
|
|
},
|
|
|
|
apis: []
|
|
|
|
};
|
|
|
|
options.apis = files.map(c => {return `${apiRoot}/${c}`;});
|
|
|
|
|
2017-01-04 04:56:20 +00:00
|
|
|
if(fs.existsSync('.config/config.yml')){
|
|
|
|
var config = yaml.safeLoad(fs.readFileSync('./.config/config.yml', 'utf8'));
|
2017-01-04 06:14:34 +00:00
|
|
|
options.swaggerDefinition.host = `api.${config.url}`;
|
2017-01-04 04:56:20 +00:00
|
|
|
options.swaggerDefinition.schemes = config.https.enable ? ['https'] : ['http'];
|
|
|
|
}
|
|
|
|
|
2017-01-04 03:59:20 +00:00
|
|
|
var swaggerSpec = swaggerJSDoc(options);
|
|
|
|
swaggerSpec.definitions.Error = errorDefinition;
|
|
|
|
|
|
|
|
fs.writeFileSync('api-docs.json', JSON.stringify(swaggerSpec));
|
|
|
|
|