| 22 | |
| 23 | |
| 24 | export default class SwaggerController { |
| 25 | constructor(envConfig) { |
| 26 | // swagger definition |
| 27 | const swaggerDefinition = { |
| 28 | info: { |
| 29 | title: 'MARINUS REST API', |
| 30 | version: '1.0.0', |
| 31 | description: 'Marinus APIs. ' + |
| 32 | 'Login to Marinus via /login or use a valid apiKey to ' + |
| 33 | 'authenticate and authorise the API calls.' |
| 34 | }, |
| 35 | host: envConfig.swagger.hostname, |
| 36 | basePath: '/', |
| 37 | schemes: ['https'] |
| 38 | }; |
| 39 | |
| 40 | // options for the swagger docs |
| 41 | const options = { |
| 42 | // import swaggerDefinitions |
| 43 | swaggerDefinition: swaggerDefinition, |
| 44 | // path to the API docs |
| 45 | // The following routes can be added if needed |
| 46 | // './routes/admin.js', |
| 47 | // './routes/censys.js', |
| 48 | apis: [ |
| 49 | './routes/cloud_services.js', |
| 50 | './routes/ct.js', |
| 51 | './routes/dns.js', |
| 52 | './routes/graphs.js', |
| 53 | './routes/iblox.js', |
| 54 | './routes/sonar.js', |
| 55 | './routes/tpds.js', |
| 56 | './routes/tracked_scans.js', |
| 57 | './routes/virustotal.js', |
| 58 | './routes/whois_db.js', |
| 59 | './routes/zones.js', |
| 60 | ], |
| 61 | }; |
| 62 | |
| 63 | // initialize swagger-jsdoc |
| 64 | this._swaggerSpec = swaggerJSDoc(options); |
| 65 | |
| 66 | // Errors |
| 67 | this._swaggerSpec.definitions.BadInputError = Error400; |
| 68 | this._swaggerSpec.definitions.ResultsNotFound = Error404; |
| 69 | this._swaggerSpec.definitions.ServerError = Error500; |
| 70 | |
| 71 | // Valid responses |
| 72 | this._swaggerSpec.definitions.CountResponse = CountResponse; |
| 73 | |
| 74 | // Common defintions |
| 75 | this._swaggerSpec.securityDefinitions.APIKeyHeader = APIKeyHeader; |
| 76 | } |
| 77 | |
| 78 | setup(app, express) { |
| 79 | app.use('/docs/media', express.static('node_modules/swagger-ui-dist')); |
| 80 | app.use('/docs/', express.static('views/swagger/')); |
| 81 |
nothing calls this directly
no outgoing calls
no test coverage detected