jormungandr-bite/swagger.js

53 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-01-03 21:56:20 -07:00
'use strict'
2017-01-03 20:59:20 -07:00
const swaggerJSDoc = require('swagger-jsdoc');
const fs = require('fs');
2017-01-03 21:56:20 -07:00
const yaml = require('js-yaml');
2017-01-03 20:59:20 -07: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-03 21:56:20 -07:00
host: 'api.misskey.xyz',
schemes: ['https'],
2017-01-03 20:59:20 -07:00
consumes: [
'application/x-www-form-urlencoded'
],
produces: [
'application/json'
]
},
apis: []
};
options.apis = files.map(c => {return `${apiRoot}/${c}`;});
2017-01-03 21:56:20 -07: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-03 20:59:20 -07:00
var swaggerSpec = swaggerJSDoc(options);
swaggerSpec.definitions.Error = errorDefinition;
fs.writeFileSync('api-docs.json', JSON.stringify(swaggerSpec));