paricafe/swagger.js
Tosuke 4dd5a443e5 [WIP][Swagger]Add swagger definition
- /auth/session/userkey
- User entity
2017-01-04 15:04:54 +09:00

54 lines
1.2 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 = [
'users.js',
'auth/session/generate.js',
'auth/session/userkey.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));