-
Notifications
You must be signed in to change notification settings - Fork 0
/
swaggerAutogen.js
50 lines (45 loc) · 1.3 KB
/
swaggerAutogen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"use strict"
require('dotenv').config()
const HOST = process.env?.HOST || '127.0.0.1'
const PORT = process.env?.PORT || 8000
const swaggerAutogen = require('swagger-autogen')()
const packageJson = require('./package.json')
const document = {
info: {
version: packageJson.version,
title: packageJson.title,
description: packageJson.description,
license: { name: packageJson.license, },
},
host: `${HOST}:${PORT}`,
basePath: '/',
schemes: ['http', 'https'],
consumes: ["application/json"],
produces: ["application/json"],
securityDefinitions: {
Token: {
type: 'apiKey',
in: 'header',
name: 'Authorization',
description: 'Simple Token Authentication * Example: <b>Token ...tokenKey...</b>'
},
Bearer: {
type: 'apiKey',
in: 'header',
name: 'Authorization',
description: 'JWT Authentication * Example: <b>Bearer ...accessToken...</b>'
},
},
security: [{ Token: [] }, { Bearer: [] }],
definitions: {
// Models:
"User": require('./src/models/user').schema.obj,
"Category": require('./src/models/category').schema.obj,
"Blog": require('./src/models/blog').schema.obj,
"Comment": require('./src/models/comment').schema.obj,
}
}
const routes = ['./index.js']
const outputFile = './src/configs/swagger.json'
// Create JSON file:
swaggerAutogen(outputFile, routes, document)