update api documentation
add authentication
This commit is contained in:
+48
-6
@@ -8,9 +8,18 @@ const doc = {
|
||||
},
|
||||
host: 'ipost.rocks',
|
||||
schemes: ['https'],
|
||||
securityDefinitions: {
|
||||
appTokenAuthHeader: {
|
||||
type: 'apiKey',
|
||||
in: 'header', // can be 'header', 'query' or 'cookie'
|
||||
name: 'ipost-auth-token', // name of the header, query parameter or cookie
|
||||
description: 'authenticate using the authentication object in the header'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const outputFile = './swagger-output.json';
|
||||
const outputFile = './swagger-api.json';
|
||||
const tempFile = './swagger-output.json';
|
||||
const endpointsFiles = ['./server.js'];
|
||||
|
||||
function pushdirectory(currentpath) {
|
||||
@@ -27,10 +36,43 @@ function pushdirectory(currentpath) {
|
||||
|
||||
pushdirectory("./routes/");
|
||||
|
||||
console.log(endpointsFiles)
|
||||
swaggerAutogen(tempFile, endpointsFiles, doc);
|
||||
|
||||
/* NOTE: if you use the express Router, you must pass in the
|
||||
'endpointsFiles' only the root file where the route starts,
|
||||
such as index.js, app.js, routes.js, ... */
|
||||
/*
|
||||
Replace some error codes with own error codes, as described in error_codes.txt
|
||||
*/
|
||||
const to_replace = {
|
||||
"401": "login error (invalid cookie)",
|
||||
"402": "login error (bad cookie)",
|
||||
"403": "login error (no cookie)",
|
||||
|
||||
"410": "argument/data error",
|
||||
"411": "argument/data error",
|
||||
"412": "argument/data error",
|
||||
"413": "argument/data error",
|
||||
"414": "argument/data error",
|
||||
"415": "argument/data error",
|
||||
"416": "argument/data error",
|
||||
"417": "argument/data error",
|
||||
"418": "argument/data error",
|
||||
"419": "argument/data error",
|
||||
"420": "invalid authetication object",
|
||||
|
||||
}
|
||||
|
||||
swaggerAutogen(outputFile, endpointsFiles, doc);
|
||||
let file = JSON.parse(fs.readFileSync(tempFile, 'utf8'));
|
||||
|
||||
for (let path in file.paths) {
|
||||
for (let method in file.paths[path]) {
|
||||
for (let response in file.paths[path][method].responses) {
|
||||
if (to_replace[response]) {
|
||||
file.paths[path][method].responses[response].description = to_replace[response];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
file = JSON.stringify(file);
|
||||
console.log(file)
|
||||
fs.writeFileSync(outputFile, file);
|
||||
fs.rmSync(tempFile);
|
||||
Reference in New Issue
Block a user