1
0
Fork 1
mirror of https://example.com synced 2024-11-24 06:36:40 +09:00
firefish/swagger.js
2017-01-04 13:56:20 +09:00

52 lines
1.1 KiB
JavaScript

'use strict'
const swaggerJSDoc = require('swagger-jsdoc');
const fs = require('fs');
const yaml = require('js-yaml');
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',
},
host: 'api.misskey.xyz',
schemes: ['https'],
consumes: [
'application/x-www-form-urlencoded'
],
produces: [
'application/json'
]
},
apis: []
};
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;
fs.writeFileSync('api-docs.json', JSON.stringify(swaggerSpec));