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 = [
|
|
|
|
'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',
|
|
|
|
},
|
2017-01-04 05:56:20 +01:00
|
|
|
host: 'api.misskey.xyz',
|
|
|
|
schemes: ['https'],
|
2017-01-04 04:59:20 +01:00
|
|
|
consumes: [
|
|
|
|
'application/x-www-form-urlencoded'
|
|
|
|
],
|
|
|
|
produces: [
|
|
|
|
'application/json'
|
|
|
|
]
|
|
|
|
},
|
|
|
|
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'));
|
|
|
|
options.swaggerDefinition.host = config.url;
|
|
|
|
options.swaggerDefinition.schemes = config.https.enable ? ['https'] : ['http'];
|
|
|
|
}
|
|
|
|
|
2017-01-04 04:59:20 +01:00
|
|
|
var swaggerSpec = swaggerJSDoc(options);
|
|
|
|
swaggerSpec.definitions.Error = errorDefinition;
|
|
|
|
|
|
|
|
fs.writeFileSync('api-docs.json', JSON.stringify(swaggerSpec));
|
|
|
|
|