@trojs/openapi-server 3.6.0 → 3.7.0
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 +2 -2
- package/src/handlers/not-found.js +3 -1
- package/src/handlers/request-validation.js +3 -1
- package/src/handlers/response-validation.js +23 -11
- package/src/handlers/unauthorized.js +3 -1
- package/src/router.js +1 -3
- package/types/handlers/not-found.d.ts.map +1 -1
- package/types/handlers/request-validation.d.ts.map +1 -1
- package/types/handlers/response-validation.d.ts +1 -1
- package/types/handlers/response-validation.d.ts.map +1 -1
- package/types/handlers/unauthorized.d.ts.map +1 -1
- package/types/router.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trojs/openapi-server",
|
|
3
3
|
"description": "OpenAPI Server",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.7.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Pieter Wigboldus",
|
|
7
7
|
"url": "https://trojs.org/"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@trojs/lint": "^0.4.0",
|
|
41
41
|
"@types/node": "^24.0.0",
|
|
42
42
|
"@types/express-serve-static-core": "^5.0.0",
|
|
43
|
-
"eslint": "^
|
|
43
|
+
"eslint": "^10.0.0",
|
|
44
44
|
"globals": "^17.0.0",
|
|
45
45
|
"jscpd": "^4.0.5",
|
|
46
46
|
"prettier": "^3.3.3",
|
|
@@ -1,13 +1,22 @@
|
|
|
1
|
-
export default (logger) => (context, request, response) => {
|
|
1
|
+
export default (logger, validateResponse) => (context, request, response) => {
|
|
2
|
+
// Prevent sending response if headers are already sent (e.g., after redirect)
|
|
3
|
+
if (response.headersSent) {
|
|
4
|
+
return undefined
|
|
5
|
+
}
|
|
6
|
+
|
|
2
7
|
const responseDoesntNeedValidation = response.statusCode >= 400
|
|
3
8
|
if (responseDoesntNeedValidation) {
|
|
4
9
|
return response.json(context.response)
|
|
5
10
|
}
|
|
6
11
|
|
|
7
|
-
const valid =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
const valid = validateResponse
|
|
13
|
+
? (
|
|
14
|
+
context.api.validateResponse(
|
|
15
|
+
context.response,
|
|
16
|
+
context.operation
|
|
17
|
+
)
|
|
18
|
+
)
|
|
19
|
+
: null
|
|
11
20
|
if (valid?.errors) {
|
|
12
21
|
if (logger) {
|
|
13
22
|
logger.error({
|
|
@@ -18,12 +27,15 @@ export default (logger) => (context, request, response) => {
|
|
|
18
27
|
response: context.response
|
|
19
28
|
})
|
|
20
29
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
if (!response.headersSent) {
|
|
31
|
+
return response.status(502).json({
|
|
32
|
+
errors: valid.errors,
|
|
33
|
+
status: 502,
|
|
34
|
+
timestamp: new Date(),
|
|
35
|
+
message: 'Bad response'
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
return undefined
|
|
27
39
|
}
|
|
28
40
|
|
|
29
41
|
if (!context.response) {
|
package/src/router.js
CHANGED
|
@@ -66,9 +66,7 @@ export const setupRouter = ({
|
|
|
66
66
|
notFound
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
handlers.postResponseHandler = makeResponseValidation(logger)
|
|
71
|
-
}
|
|
69
|
+
handlers.postResponseHandler = makeResponseValidation(logger, validateResponse)
|
|
72
70
|
|
|
73
71
|
api.register(handlers)
|
|
74
72
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"not-found.d.ts","sourceRoot":"","sources":["../../src/handlers/not-found.js"],"names":[],"mappings":"AAAO;;;;
|
|
1
|
+
{"version":3,"file":"not-found.d.ts","sourceRoot":"","sources":["../../src/handlers/not-found.js"],"names":[],"mappings":"AAAO;;;;EASN"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-validation.d.ts","sourceRoot":"","sources":["../../src/handlers/request-validation.js"],"names":[],"mappings":"AAAO;;;;;
|
|
1
|
+
{"version":3,"file":"request-validation.d.ts","sourceRoot":"","sources":["../../src/handlers/request-validation.js"],"names":[],"mappings":"AAAO;;;;;EAUN"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare function _default(logger: any): (context: any, request: any, response: any) => any;
|
|
1
|
+
declare function _default(logger: any, validateResponse: any): (context: any, request: any, response: any) => any;
|
|
2
2
|
export default _default;
|
|
3
3
|
//# sourceMappingURL=response-validation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response-validation.d.ts","sourceRoot":"","sources":["../../src/handlers/response-validation.js"],"names":[],"mappings":"AAAe,
|
|
1
|
+
{"version":3,"file":"response-validation.d.ts","sourceRoot":"","sources":["../../src/handlers/response-validation.js"],"names":[],"mappings":"AAAe,gEAA+B,YAAO,EAAE,YAAO,EAAE,aAAQ,SAkDvE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unauthorized.d.ts","sourceRoot":"","sources":["../../src/handlers/unauthorized.js"],"names":[],"mappings":"AAAO;;;;
|
|
1
|
+
{"version":3,"file":"unauthorized.d.ts","sourceRoot":"","sources":["../../src/handlers/unauthorized.js"],"names":[],"mappings":"AAAO;;;;GASN"}
|
package/types/router.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.js"],"names":[],"mappings":"AAmCO,sNAfJ;IAAuB,oBAAoB,EAAnC,MAAM;IACS,WAAW,EAA1B,MAAM;IACU,OAAO,GAAvB,MAAM,YAAC;IACU,mBAAmB,GAApC,OAAO,YAAC;IACS,YAAY,GAA7B,OAAO,YAAC;IACQ,MAAM,GAAtB,MAAM,YAAC;IACS,IAAI,GAApB,MAAM,YAAC;IACoB,gBAAgB,GAA3C,eAAe,EAAE,YAAC;IACD,mBAAmB,GAApC,OAAO,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