@trojs/openapi-server 1.6.1 → 1.7.1

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@trojs/openapi-server",
3
3
  "description": "OpenAPI Server",
4
- "version": "1.6.1",
4
+ "version": "1.7.1",
5
5
  "author": {
6
6
  "name": "Pieter Wigboldus",
7
7
  "url": "https://trojs.org/"
@@ -80,8 +80,8 @@
80
80
  "url": "https://github.com/sponsors/w3nl"
81
81
  },
82
82
  "overrides": {
83
- "semver": "^7.5.3",
84
- "send": "^0.19.0",
83
+ "semver@<=7.5.3": "^7.5.3",
84
+ "send@<=0.19.0": "^0.19.0",
85
85
  "cookie@<=0.7.0": "0.7.0"
86
86
  }
87
87
  }
package/src/api.js CHANGED
@@ -5,6 +5,7 @@ import { setupRouter } from './router.js'
5
5
  /**
6
6
  * @typedef {import('openapi-backend').Handler} Handler
7
7
  * @typedef {import('ajv').Options} AjvOpts
8
+ * @typedef {import('openapi-backend').AjvCustomizer} AjvCustomizer
8
9
  * @typedef {object} Logger
9
10
  * @property {Function} error
10
11
  * @property {Function} warn
@@ -27,6 +28,7 @@ import { setupRouter } from './router.js'
27
28
  * @property {boolean=} swagger
28
29
  * @property {boolean=} apiDocs
29
30
  * @property {AjvOpts=} ajvOptions
31
+ * @property {AjvCustomizer=} customizeAjv
30
32
  */
31
33
 
32
34
  /**
@@ -53,7 +55,8 @@ export class Api {
53
55
  unauthorizedHandler,
54
56
  swagger,
55
57
  apiDocs,
56
- ajvOptions
58
+ ajvOptions,
59
+ customizeAjv
57
60
  }) {
58
61
  this.version = version
59
62
  this.specification = specification
@@ -68,6 +71,7 @@ export class Api {
68
71
  this.swagger = swagger ?? true
69
72
  this.apiDocs = apiDocs ?? true
70
73
  this.ajvOptions = ajvOptions ?? { allErrors: false }
74
+ this.customizeAjv = customizeAjv
71
75
  }
72
76
 
73
77
  setup() {
@@ -96,7 +100,8 @@ export class Api {
96
100
  meta: this.meta,
97
101
  securityHandlers: this.securityHandlers,
98
102
  unauthorizedHandler: this.unauthorizedHandler,
99
- ajvOptions: this.ajvOptions
103
+ ajvOptions: this.ajvOptions,
104
+ customizeAjv: this.customizeAjv
100
105
  })
101
106
  api.init()
102
107
 
package/src/router.js CHANGED
@@ -12,6 +12,7 @@ import { unauthorized } from './handlers/unauthorized.js'
12
12
  * @typedef {import('./api.js').SecurityHandler} SecurityHandler
13
13
  * @typedef {import('./api.js').Handler} Handler
14
14
  * @typedef {import('ajv').Options} AjvOpts
15
+ * @typedef {import('openapi-backend').AjvCustomizer} AjvCustomizer
15
16
  */
16
17
 
17
18
  /**
@@ -27,6 +28,7 @@ import { unauthorized } from './handlers/unauthorized.js'
27
28
  * @param {SecurityHandler[]=} params.securityHandlers
28
29
  * @param {Handler=} params.unauthorizedHandler
29
30
  * @param {AjvOpts=} params.ajvOptions
31
+ * @param {AjvCustomizer=} params.customizeAjv
30
32
  * @param {boolean=} params.mock
31
33
  * @returns {{ api: OpenAPIBackend<any>, openAPISpecification: object }}
32
34
  */
@@ -41,17 +43,19 @@ export const setupRouter = ({
41
43
  securityHandlers = [],
42
44
  unauthorizedHandler,
43
45
  ajvOptions = {},
46
+ customizeAjv,
44
47
  mock
45
48
  }) => {
49
+ const ajvWithExtraFormats = (originalAjv) => {
50
+ addFormats(originalAjv)
51
+ return originalAjv
52
+ }
46
53
  const api = new OpenAPIBackend({
47
54
  definition: openAPISpecification,
48
55
  apiRoot,
49
56
  strict: strictSpecification,
50
57
  ajvOpts: ajvOptions,
51
- customizeAjv: (originalAjv) => {
52
- addFormats(originalAjv)
53
- return originalAjv
54
- }
58
+ customizeAjv: customizeAjv || ajvWithExtraFormats
55
59
  })
56
60
 
57
61
  api.register({