@trojs/openapi-server 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/api.js +13 -5
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@trojs/openapi-server",
3
3
  "description": "OpenAPI Server",
4
- "version": "1.0.2",
4
+ "version": "1.0.4",
5
5
  "author": {
6
6
  "name": "Pieter Wigboldus",
7
7
  "url": "https://trojs.org/"
@@ -43,7 +43,7 @@
43
43
  "eslint-plugin-n": "^16.0.0",
44
44
  "eslint-plugin-promise": "^6.0.1",
45
45
  "eslint-plugin-sonarjs": "^0.25.1",
46
- "jscpd": "^3.2.1",
46
+ "jscpd": "^4.0.0",
47
47
  "supertest": "^7.0.0"
48
48
  },
49
49
  "repository": {
package/src/api.js CHANGED
@@ -23,6 +23,8 @@ import { setupRouter } from './router.js'
23
23
  * @property {Logger=} logger
24
24
  * @property {object=} meta
25
25
  * @property {SecurityHandler[]=} securityHandlers
26
+ * @property {boolean=} swagger
27
+ * @property {boolean=} apiDocs
26
28
  */
27
29
 
28
30
  /**
@@ -33,7 +35,7 @@ export class Api {
33
35
  /**
34
36
  * @param {ApiSchema} params
35
37
  */
36
- constructor ({ version, specification, controllers, secret, apiRoot, strictSpecification, errorDetails, logger, meta, securityHandlers }) {
38
+ constructor ({ version, specification, controllers, secret, apiRoot, strictSpecification, errorDetails, logger, meta, securityHandlers, swagger, apiDocs }) {
37
39
  this.version = version
38
40
  this.specification = specification
39
41
  this.controllers = controllers
@@ -44,15 +46,21 @@ export class Api {
44
46
  this.logger = logger || console
45
47
  this.meta = meta || {}
46
48
  this.securityHandlers = securityHandlers || []
49
+ this.swagger = swagger ?? true
50
+ this.apiDocs = apiDocs ?? true
47
51
  }
48
52
 
49
53
  setup () {
50
54
  const router = express.Router()
51
55
 
52
- router.use('/swagger', swaggerUi.serveFiles(this.specification, {}), swaggerUi.setup(this.specification))
53
- router.get('/api-docs', (_request, response) =>
54
- response.json(this.specification)
55
- )
56
+ if (this.swagger) {
57
+ router.use('/swagger', swaggerUi.serveFiles(this.specification, {}), swaggerUi.setup(this.specification))
58
+ }
59
+ if (this.apiDocs) {
60
+ router.get('/api-docs', (_request, response) =>
61
+ response.json(this.specification)
62
+ )
63
+ }
56
64
 
57
65
  const { api } = setupRouter({
58
66
  secret: this.secret,