1
0
mirror of https://github.com/misskey-dev/misskey synced 2024-11-25 15:46:39 +09:00
misskey/swagger.js

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