@trojs/openapi-server 1.7.2 → 1.7.3

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.7.2",
4
+ "version": "1.7.3",
5
5
  "author": {
6
6
  "name": "Pieter Wigboldus",
7
7
  "url": "https://trojs.org/"
@@ -11,6 +11,7 @@
11
11
  "lint": "eslint",
12
12
  "lint:report": "eslint src/*.js -f json -o report.json",
13
13
  "lint:fix": "eslint --fix",
14
+ "lint:rules": "eslint --print-config src/index.js > eslintconfig.json",
14
15
  "test": "c8 node --test src/*.test.js",
15
16
  "cpd": "node_modules/jscpd/bin/jscpd src",
16
17
  "vulnerabilities": "npm audit --omit=dev"
@@ -36,20 +37,18 @@
36
37
  "@eslint/js": "^9.15.0",
37
38
  "@stylistic/eslint-plugin": "^3.0.0",
38
39
  "@stylistic/eslint-plugin-js": "^3.0.0",
40
+ "@trojs/lint": "^0.2.3",
39
41
  "@types/express-serve-static-core": "^4.17.41",
40
42
  "@types/node": "^22.0.0",
41
43
  "c8": "^10.0.0",
42
44
  "eslint": "^9.15.0",
43
- "eslint-config-prettier": "^10.0.0",
44
45
  "eslint-plugin-import": "^2.31.0",
45
46
  "eslint-plugin-jsdoc": "^50.5.0",
46
47
  "eslint-plugin-n": "^17.14.0",
47
- "eslint-plugin-prettier": "^5.2.1",
48
48
  "eslint-plugin-promise": "^7.1.0",
49
49
  "eslint-plugin-sonarjs": "^2.0.4",
50
50
  "globals": "^15.12.0",
51
51
  "jscpd": "^4.0.0",
52
- "prettier": "^3.3.3",
53
52
  "supertest": "^7.0.0"
54
53
  },
55
54
  "repository": {
package/src/api.js CHANGED
@@ -37,78 +37,78 @@ import { setupRouter } from './router.js'
37
37
  */
38
38
 
39
39
  export class Api {
40
- /**
41
- * Create a new instance of the API
42
- * @class
43
- * @param {ApiSchema} params
44
- */
45
- constructor({
46
- version,
47
- specification,
48
- controllers,
49
- apiRoot,
50
- strictSpecification,
51
- errorDetails,
52
- logger,
53
- meta,
54
- securityHandlers,
55
- unauthorizedHandler,
56
- swagger,
57
- apiDocs,
58
- ajvOptions,
59
- customizeAjv
60
- }) {
61
- this.version = version
62
- this.specification = specification
63
- this.controllers = controllers
64
- this.apiRoot = apiRoot
65
- this.strictSpecification = strictSpecification
66
- this.errorDetails = errorDetails || false
67
- this.logger = logger || console
68
- this.meta = meta || {}
69
- this.securityHandlers = securityHandlers || []
70
- this.unauthorizedHandler = unauthorizedHandler || undefined
71
- this.swagger = swagger ?? true
72
- this.apiDocs = apiDocs ?? true
73
- this.ajvOptions = ajvOptions ?? { allErrors: false }
74
- this.customizeAjv = customizeAjv
75
- }
40
+ /**
41
+ * Create a new instance of the API
42
+ * @class
43
+ * @param {ApiSchema} params
44
+ */
45
+ constructor({
46
+ version,
47
+ specification,
48
+ controllers,
49
+ apiRoot,
50
+ strictSpecification,
51
+ errorDetails,
52
+ logger,
53
+ meta,
54
+ securityHandlers,
55
+ unauthorizedHandler,
56
+ swagger,
57
+ apiDocs,
58
+ ajvOptions,
59
+ customizeAjv
60
+ }) {
61
+ this.version = version
62
+ this.specification = specification
63
+ this.controllers = controllers
64
+ this.apiRoot = apiRoot
65
+ this.strictSpecification = strictSpecification
66
+ this.errorDetails = errorDetails || false
67
+ this.logger = logger || console
68
+ this.meta = meta || {}
69
+ this.securityHandlers = securityHandlers || []
70
+ this.unauthorizedHandler = unauthorizedHandler || undefined
71
+ this.swagger = swagger ?? true
72
+ this.apiDocs = apiDocs ?? true
73
+ this.ajvOptions = ajvOptions ?? { allErrors: false }
74
+ this.customizeAjv = customizeAjv
75
+ }
76
76
 
77
- setup() {
78
- const router = express.Router()
77
+ setup() {
78
+ const router = express.Router()
79
79
 
80
- if (this.swagger) {
81
- router.use(
82
- '/swagger',
83
- swaggerUi.serveFiles(this.specification, {}),
84
- swaggerUi.setup(this.specification)
85
- )
86
- }
87
- if (this.apiDocs) {
88
- router.get('/api-docs', (_request, response) =>
89
- response.json(this.specification)
90
- )
91
- }
80
+ if (this.swagger) {
81
+ router.use(
82
+ '/swagger',
83
+ swaggerUi.serveFiles(this.specification, {}),
84
+ swaggerUi.setup(this.specification)
85
+ )
86
+ }
87
+ if (this.apiDocs) {
88
+ router.get('/api-docs', (_request, response) =>
89
+ response.json(this.specification)
90
+ )
91
+ }
92
92
 
93
- const { api } = setupRouter({
94
- openAPISpecification: this.specification,
95
- controllers: this.controllers,
96
- apiRoot: this.apiRoot,
97
- strictSpecification: this.strictSpecification,
98
- errorDetails: this.errorDetails,
99
- logger: this.logger,
100
- meta: this.meta,
101
- securityHandlers: this.securityHandlers,
102
- unauthorizedHandler: this.unauthorizedHandler,
103
- ajvOptions: this.ajvOptions,
104
- customizeAjv: this.customizeAjv
105
- })
106
- api.init()
93
+ const { api } = setupRouter({
94
+ openAPISpecification: this.specification,
95
+ controllers: this.controllers,
96
+ apiRoot: this.apiRoot,
97
+ strictSpecification: this.strictSpecification,
98
+ errorDetails: this.errorDetails,
99
+ logger: this.logger,
100
+ meta: this.meta,
101
+ securityHandlers: this.securityHandlers,
102
+ unauthorizedHandler: this.unauthorizedHandler,
103
+ ajvOptions: this.ajvOptions,
104
+ customizeAjv: this.customizeAjv
105
+ })
106
+ api.init()
107
107
 
108
- router.use((request, response) =>
109
- api.handleRequest(request, request, response)
110
- )
108
+ router.use((request, response) =>
109
+ api.handleRequest(request, request, response)
110
+ )
111
111
 
112
- return router
113
- }
112
+ return router
113
+ }
114
114
  }
@@ -1,16 +1,16 @@
1
1
  const errorCodesStatus = [
2
- {
3
- type: TypeError,
4
- status: 422
5
- },
6
- {
7
- type: RangeError,
8
- status: 404
9
- },
10
- {
11
- type: Error,
12
- status: 500
13
- }
2
+ {
3
+ type: TypeError,
4
+ status: 422
5
+ },
6
+ {
7
+ type: RangeError,
8
+ status: 404
9
+ },
10
+ {
11
+ type: Error,
12
+ status: 500
13
+ }
14
14
  ]
15
15
 
16
16
  /**
@@ -19,6 +19,6 @@ const errorCodesStatus = [
19
19
  * @param {Error} error
20
20
  * @returns {number}
21
21
  */
22
- export default (error) =>
23
- errorCodesStatus.find((errorCode) => error instanceof errorCode.type)
24
- .status
22
+ export default error =>
23
+ errorCodesStatus.find(errorCode => error instanceof errorCode.type)
24
+ .status
@@ -19,8 +19,8 @@ import { parseParams } from './params.js'
19
19
  * @param {boolean=} params.mock
20
20
  * @returns {Function}
21
21
  */
22
- export const makeExpressCallback =
23
- ({ controller, specification, errorDetails, logger, meta, mock }) =>
22
+ export const makeExpressCallback
23
+ = ({ controller, specification, errorDetails, logger, meta, mock }) =>
24
24
  /**
25
25
  * Handle controller
26
26
  * @async
@@ -29,68 +29,70 @@ export const makeExpressCallback =
29
29
  * @param {Response} response
30
30
  * @returns {Promise<any>}
31
31
  */
32
- async (context, request, response) => {
33
- try {
34
- const allParameters = {
35
- ...(context.request?.params || {}),
36
- ...(context.request?.query || {})
37
- }
38
- const parameters = parseParams({
39
- query: allParameters,
40
- spec: context.operation.parameters,
41
- mock
42
- })
43
- const url = `${request.protocol}://${request.get('Host')}${request.originalUrl}`
44
-
45
- const responseBody = await controller({
46
- context,
47
- request,
48
- response,
49
- parameters,
50
- specification,
51
- post: request.body,
52
- url,
53
- logger,
54
- meta
55
- })
56
- logger.debug({
57
- url,
58
- parameters,
59
- post: request.body,
60
- response: responseBody
61
- })
32
+ async (context, request, response) => {
33
+ try {
34
+ const allParameters = {
35
+ ...(context.request?.params || {}),
36
+ ...(context.request?.query || {})
37
+ }
38
+ const parameters = parseParams({
39
+ query: allParameters,
40
+ spec: context.operation.parameters,
41
+ mock
42
+ })
43
+ const url = `${request.protocol}://${request.get('Host')}${request.originalUrl}`
62
44
 
63
- return responseBody
64
- } catch (error) {
65
- const errorCodeStatus = getStatusByError(error)
45
+ const responseBody = await controller({
46
+ context,
47
+ request,
48
+ response,
49
+ parameters,
50
+ specification,
51
+ post: request.body,
52
+ url,
53
+ logger,
54
+ meta
55
+ })
56
+ logger.debug({
57
+ url,
58
+ parameters,
59
+ post: request.body,
60
+ response: responseBody
61
+ })
66
62
 
67
- if (errorCodeStatus >= 500) {
68
- logger.error(error)
69
- } else {
70
- logger.warn(error)
71
- }
63
+ return responseBody
64
+ }
65
+ catch (error) {
66
+ const errorCodeStatus = getStatusByError(error)
72
67
 
73
- response.status(errorCodeStatus)
68
+ if (errorCodeStatus >= 500) {
69
+ logger.error(error)
70
+ }
71
+ else {
72
+ logger.warn(error)
73
+ }
74
74
 
75
- if (errorDetails) {
76
- return {
77
- errors: [
78
- {
79
- message: error.message,
80
- value: error.valueOf(),
81
- type: error.constructor.name
82
- }
83
- ],
84
- status: errorCodeStatus,
85
- timestamp: new Date(),
86
- message: error.message
87
- }
88
- }
75
+ response.status(errorCodeStatus)
89
76
 
90
- return {
91
- status: errorCodeStatus,
92
- timestamp: new Date(),
93
- message: error.message
77
+ if (errorDetails) {
78
+ return {
79
+ errors: [
80
+ {
81
+ message: error.message,
82
+ value: error.valueOf(),
83
+ type: error.constructor.name
94
84
  }
85
+ ],
86
+ status: errorCodeStatus,
87
+ timestamp: new Date(),
88
+ message: error.message
95
89
  }
90
+ }
91
+
92
+ return {
93
+ status: errorCodeStatus,
94
+ timestamp: new Date(),
95
+ message: error.message
96
+ }
96
97
  }
98
+ }
@@ -1,8 +1,8 @@
1
1
  export const notFound = (_context, request, response) => {
2
- response.status(404)
3
- return {
4
- status: 404,
5
- timestamp: new Date(),
6
- message: 'Not found'
7
- }
2
+ response.status(404)
3
+ return {
4
+ status: 404,
5
+ timestamp: new Date(),
6
+ message: 'Not found'
7
+ }
8
8
  }
@@ -1,9 +1,9 @@
1
1
  export const requestValidation = (context, request, response) => {
2
- response.status(400)
3
- return {
4
- errors: context.validation.errors,
5
- status: 400,
6
- timestamp: new Date(),
7
- message: 'Bad Request'
8
- }
2
+ response.status(400)
3
+ return {
4
+ errors: context.validation.errors,
5
+ status: 400,
6
+ timestamp: new Date(),
7
+ message: 'Bad Request'
8
+ }
9
9
  }
@@ -1,30 +1,30 @@
1
1
  export const responseValidation = (context, request, response) => {
2
- const responseDoesntNeedValidation = response.statusCode >= 400
3
- if (responseDoesntNeedValidation) {
4
- return response.json(context.response)
5
- }
2
+ const responseDoesntNeedValidation = response.statusCode >= 400
3
+ if (responseDoesntNeedValidation) {
4
+ return response.json(context.response)
5
+ }
6
6
 
7
- const valid = context.api.validateResponse(
8
- context.response,
9
- context.operation
10
- )
11
- if (valid?.errors) {
12
- return response.status(502).json({
13
- errors: valid.errors,
14
- status: 502,
15
- timestamp: new Date(),
16
- message: 'Bad response'
17
- })
18
- }
7
+ const valid = context.api.validateResponse(
8
+ context.response,
9
+ context.operation
10
+ )
11
+ if (valid?.errors) {
12
+ return response.status(502).json({
13
+ errors: valid.errors,
14
+ status: 502,
15
+ timestamp: new Date(),
16
+ message: 'Bad response'
17
+ })
18
+ }
19
19
 
20
- if (!context.response) {
21
- return response.end()
22
- }
20
+ if (!context.response) {
21
+ return response.end()
22
+ }
23
23
 
24
- const contentType = request?.headers?.accept ?? 'application/json'
25
- if (contentType === 'application/json') {
26
- return response.json(context.response)
27
- }
24
+ const contentType = request?.headers?.accept ?? 'application/json'
25
+ if (contentType === 'application/json') {
26
+ return response.json(context.response)
27
+ }
28
28
 
29
- return response.send(context.response)
29
+ return response.send(context.response)
30
30
  }
@@ -1,8 +1,8 @@
1
1
  export const unauthorized = async (context, request, response) => {
2
- response.status(401)
3
- return {
4
- status: 401,
5
- timestamp: new Date(),
6
- message: 'Unauthorized'
7
- }
2
+ response.status(401)
3
+ return {
4
+ status: 401,
5
+ timestamp: new Date(),
6
+ message: 'Unauthorized'
7
+ }
8
8
  }
package/src/openapi.js CHANGED
@@ -9,7 +9,7 @@ import { readFile } from 'node:fs/promises'
9
9
  * @returns {Promise<{ openAPISpecification: object; }>}
10
10
  */
11
11
  export const openAPI = async ({ file, base = import.meta.url }) => {
12
- const fileUrl = new URL(file, base)
13
- const openAPISpecification = JSON.parse(await readFile(fileUrl, 'utf8'))
14
- return { openAPISpecification }
12
+ const fileUrl = new URL(file, base)
13
+ const openAPISpecification = JSON.parse(await readFile(fileUrl, 'utf8'))
14
+ return { openAPISpecification }
15
15
  }
@@ -7,10 +7,10 @@ const operations = ['get', 'put', 'patch', 'post', 'delete']
7
7
  * @returns {string[]}
8
8
  */
9
9
  export const operationIds = ({ specification }) =>
10
- Object.values(specification.paths)
11
- .map((path) =>
12
- Object.entries(path).map(([operation, data]) =>
13
- operations.includes(operation) ? data.operationId : null
14
- )
15
- )
16
- .flat()
10
+ Object.values(specification.paths)
11
+ .map(path =>
12
+ Object.entries(path).map(([operation, data]) =>
13
+ operations.includes(operation) ? data.operationId : null
14
+ )
15
+ )
16
+ .flat()
package/src/params.js CHANGED
@@ -9,41 +9,41 @@ import { types } from './types.js'
9
9
  * @returns {object}
10
10
  */
11
11
  export const parseParams = ({ query, spec, mock = false }) =>
12
- spec
13
- .map((parameter) => {
14
- const { name, schema } = parameter
15
- const {
16
- type,
17
- default: defaultValue,
18
- example: exampleValue
19
- } = schema
20
- const Type = types[type]
21
- const paramName = query?.[name]
12
+ spec
13
+ .map((parameter) => {
14
+ const { name, schema } = parameter
15
+ const {
16
+ type,
17
+ default: defaultValue,
18
+ example: exampleValue
19
+ } = schema
20
+ const Type = types[type]
21
+ const paramName = query?.[name]
22
22
 
23
- if (!paramName && defaultValue !== undefined) {
24
- return { name, value: defaultValue }
25
- }
23
+ if (!paramName && defaultValue !== undefined) {
24
+ return { name, value: defaultValue }
25
+ }
26
26
 
27
- if (!paramName && mock && exampleValue !== undefined) {
28
- return { name, value: exampleValue }
29
- }
27
+ if (!paramName && mock && exampleValue !== undefined) {
28
+ return { name, value: exampleValue }
29
+ }
30
30
 
31
- if (!paramName) {
32
- return undefined
33
- }
31
+ if (!paramName) {
32
+ return undefined
33
+ }
34
34
 
35
- if (Type === Boolean) {
36
- return {
37
- name,
38
- value: JSON.parse(paramName.toLowerCase())
39
- }
40
- }
35
+ if (Type === Boolean) {
36
+ return {
37
+ name,
38
+ value: JSON.parse(paramName.toLowerCase())
39
+ }
40
+ }
41
41
 
42
- const value = new Type(paramName).valueOf()
43
- return { name, value }
44
- })
45
- .filter(Boolean)
46
- .reduce((acc, { name, value }) => {
47
- acc[name] = value
48
- return acc
49
- }, {})
42
+ const value = new Type(paramName).valueOf()
43
+ return { name, value }
44
+ })
45
+ .filter(Boolean)
46
+ .reduce((acc, { name, value }) => {
47
+ acc[name] = value
48
+ return acc
49
+ }, {})
package/src/router.js CHANGED
@@ -33,69 +33,69 @@ import { unauthorized } from './handlers/unauthorized.js'
33
33
  * @returns {{ api: OpenAPIBackend<any>, openAPISpecification: object }}
34
34
  */
35
35
  export const setupRouter = ({
36
- openAPISpecification,
37
- controllers,
38
- apiRoot,
39
- strictSpecification,
40
- errorDetails,
41
- logger,
42
- meta,
43
- securityHandlers = [],
44
- unauthorizedHandler,
45
- ajvOptions = {},
46
- customizeAjv,
47
- mock
36
+ openAPISpecification,
37
+ controllers,
38
+ apiRoot,
39
+ strictSpecification,
40
+ errorDetails,
41
+ logger,
42
+ meta,
43
+ securityHandlers = [],
44
+ unauthorizedHandler,
45
+ ajvOptions = {},
46
+ customizeAjv,
47
+ mock
48
48
  }) => {
49
- const ajvWithExtraFormats = (originalAjv) => {
50
- addFormats(originalAjv)
51
- return originalAjv
52
- }
53
- const api = new OpenAPIBackend({
54
- definition: openAPISpecification,
55
- apiRoot,
56
- strict: strictSpecification,
57
- ajvOpts: ajvOptions,
58
- customizeAjv: customizeAjv || ajvWithExtraFormats
59
- })
49
+ const ajvWithExtraFormats = (originalAjv) => {
50
+ addFormats(originalAjv)
51
+ return originalAjv
52
+ }
53
+ const api = new OpenAPIBackend({
54
+ definition: openAPISpecification,
55
+ apiRoot,
56
+ strict: strictSpecification,
57
+ ajvOpts: ajvOptions,
58
+ customizeAjv: customizeAjv || ajvWithExtraFormats
59
+ })
60
60
 
61
- api.register({
62
- unauthorizedHandler: unauthorizedHandler || unauthorized,
63
- validationFail: requestValidation,
64
- notFound,
65
- postResponseHandler: responseValidation
66
- })
61
+ api.register({
62
+ unauthorizedHandler: unauthorizedHandler || unauthorized,
63
+ validationFail: requestValidation,
64
+ notFound,
65
+ postResponseHandler: responseValidation
66
+ })
67
67
 
68
- operationIds({ specification: openAPISpecification }).forEach(
69
- (operationId) => {
70
- if (!Object.hasOwn(controllers, operationId)) {
71
- return
72
- }
73
- api.register(
74
- operationId,
75
- makeExpressCallback({
76
- controller: controllers[operationId],
77
- specification: openAPISpecification,
78
- errorDetails,
79
- logger,
80
- meta,
81
- mock
82
- })
83
- )
84
- }
85
- )
68
+ operationIds({ specification: openAPISpecification }).forEach(
69
+ (operationId) => {
70
+ if (!Object.hasOwn(controllers, operationId)) {
71
+ return
72
+ }
73
+ api.register(
74
+ operationId,
75
+ makeExpressCallback({
76
+ controller: controllers[operationId],
77
+ specification: openAPISpecification,
78
+ errorDetails,
79
+ logger,
80
+ meta,
81
+ mock
82
+ })
83
+ )
84
+ }
85
+ )
86
86
 
87
- api.register('notImplemented', (context) => {
88
- const { mock: mockImplementation } =
89
- context.api.mockResponseForOperation(context.operation.operationId)
90
- return mockImplementation
91
- })
87
+ api.register('notImplemented', (context) => {
88
+ const { mock: mockImplementation }
89
+ = context.api.mockResponseForOperation(context.operation.operationId)
90
+ return mockImplementation
91
+ })
92
92
 
93
- securityHandlers.forEach((securityHandler) => {
94
- api.registerSecurityHandler(
95
- securityHandler.name,
96
- securityHandler.handler
97
- )
98
- })
93
+ securityHandlers.forEach((securityHandler) => {
94
+ api.registerSecurityHandler(
95
+ securityHandler.name,
96
+ securityHandler.handler
97
+ )
98
+ })
99
99
 
100
- return { api, openAPISpecification }
100
+ return { api, openAPISpecification }
101
101
  }
package/src/server.js CHANGED
@@ -14,14 +14,14 @@ import { Api } from './api.js'
14
14
  * @param {string} origin
15
15
  * @returns {{ crossOriginResourcePolicy: { policy: string, directives: object } }}
16
16
  */
17
- const getOriginResourcePolicy = (origin) => ({
18
- crossOriginResourcePolicy: {
19
- policy: origin === '*' ? 'cross-origin' : 'same-origin',
20
- directives: {
21
- // ...
22
- 'require-trusted-types-for': ["'script'"]
23
- }
17
+ const getOriginResourcePolicy = origin => ({
18
+ crossOriginResourcePolicy: {
19
+ policy: origin === '*' ? 'cross-origin' : 'same-origin',
20
+ directives: {
21
+ // ...
22
+ 'require-trusted-types-for': ['\'script\'']
24
23
  }
24
+ }
25
25
  })
26
26
 
27
27
  /**
@@ -70,63 +70,63 @@ const getOriginResourcePolicy = (origin) => ({
70
70
  * @returns {Promise<{ app: Express }>}
71
71
  */
72
72
  export const setupServer = async ({
73
- apis,
74
- origin = '*',
75
- staticFolder,
76
- sentry,
77
- poweredBy = 'TroJS',
78
- version = '1.0.0',
79
- middleware = [],
80
- maximumBodySize = undefined
73
+ apis,
74
+ origin = '*',
75
+ staticFolder,
76
+ sentry,
77
+ poweredBy = 'TroJS',
78
+ version = '1.0.0',
79
+ middleware = [],
80
+ maximumBodySize = undefined
81
81
  }) => {
82
- const corsOptions = {
83
- origin
84
- }
82
+ const corsOptions = {
83
+ origin
84
+ }
85
85
 
86
- const app = express()
86
+ const app = express()
87
87
 
88
- if (sentry) {
89
- Sentry.init({
90
- dsn: sentry.dsn,
91
- integrations: [
92
- new Sentry.Integrations.Http({ tracing: true }),
93
- new Sentry.Integrations.Express({ app })
94
- ],
95
- tracesSampleRate: sentry.tracesSampleRate || 1.0,
96
- profilesSampleRate: sentry.profilesSampleRate || 1.0,
97
- release: sentry.release
98
- })
88
+ if (sentry) {
89
+ Sentry.init({
90
+ dsn: sentry.dsn,
91
+ integrations: [
92
+ new Sentry.Integrations.Http({ tracing: true }),
93
+ new Sentry.Integrations.Express({ app })
94
+ ],
95
+ tracesSampleRate: sentry.tracesSampleRate || 1.0,
96
+ profilesSampleRate: sentry.profilesSampleRate || 1.0,
97
+ release: sentry.release
98
+ })
99
99
 
100
- app.use(Sentry.Handlers.requestHandler())
101
- }
100
+ app.use(Sentry.Handlers.requestHandler())
101
+ }
102
102
 
103
- app.use(cors(corsOptions))
104
- app.use(compression())
105
- app.use(helmet(getOriginResourcePolicy(origin)))
106
- app.use(express.json({ limit: maximumBodySize }))
107
- middleware.forEach((fn) => app.use(fn))
108
- app.use(bodyParser.urlencoded({ extended: false, limit: maximumBodySize }))
109
- app.use((_request, response, next) => {
110
- response.setHeader('X-Powered-By', poweredBy)
111
- response.setHeader('X-Version', version)
112
- next()
113
- })
103
+ app.use(cors(corsOptions))
104
+ app.use(compression())
105
+ app.use(helmet(getOriginResourcePolicy(origin)))
106
+ app.use(express.json({ limit: maximumBodySize }))
107
+ middleware.forEach(fn => app.use(fn))
108
+ app.use(bodyParser.urlencoded({ extended: false, limit: maximumBodySize }))
109
+ app.use((_request, response, next) => {
110
+ response.setHeader('X-Powered-By', poweredBy)
111
+ response.setHeader('X-Version', version)
112
+ next()
113
+ })
114
114
 
115
- if (staticFolder) {
116
- app.use(express.static(staticFolder))
117
- }
115
+ if (staticFolder) {
116
+ app.use(express.static(staticFolder))
117
+ }
118
118
 
119
- apis.forEach((api) => {
120
- const apiRoutes = new Api(api)
121
- const routes = apiRoutes.setup()
122
- app.use(`/${api.version}`, routes)
123
- })
119
+ apis.forEach((api) => {
120
+ const apiRoutes = new Api(api)
121
+ const routes = apiRoutes.setup()
122
+ app.use(`/${api.version}`, routes)
123
+ })
124
124
 
125
- if (sentry) {
126
- app.use(Sentry.Handlers.errorHandler())
127
- }
125
+ if (sentry) {
126
+ app.use(Sentry.Handlers.errorHandler())
127
+ }
128
128
 
129
- return { app }
129
+ return { app }
130
130
  }
131
131
 
132
132
  export { openAPI, Api }
package/src/types.js CHANGED
@@ -1,12 +1,12 @@
1
1
  const types = {
2
- string: String,
3
- array: Array,
4
- object: Object,
5
- number: Number,
6
- integer: Number,
7
- boolean: Boolean,
8
- url: URL,
9
- date: Date
2
+ string: String,
3
+ array: Array,
4
+ object: Object,
5
+ number: Number,
6
+ integer: Number,
7
+ boolean: Boolean,
8
+ url: URL,
9
+ date: Date
10
10
  }
11
11
 
12
12
  export { types }