ts-openapi-express 1.0.3 → 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.
package/dist/errors.d.ts CHANGED
@@ -1,12 +1,7 @@
1
- import { error as openapiValidatorErrors } from 'express-openapi-validator';
2
- export type OpenapiValidatorError = (typeof openapiValidatorErrors)[keyof typeof openapiValidatorErrors];
3
- declare const isExpressOpenAPIValidatorError: (err: any) => err is Error & {
4
- status: number;
5
- };
1
+ import { error as OpenapiValidationErrors } from 'express-openapi-validator';
6
2
  declare class HttpError extends Error {
7
3
  readonly status: number;
8
4
  constructor(message: string, status: number);
9
- type(): string;
10
5
  }
11
6
  declare class UnauthorizedError extends HttpError {
12
7
  constructor();
@@ -18,4 +13,4 @@ declare class InvalidJsonError extends HttpError {
18
13
  readonly jsonString: string;
19
14
  constructor(jsonString: string);
20
15
  }
21
- export { isExpressOpenAPIValidatorError, HttpError, RequestBodyTooLargeError, InvalidJsonError, UnauthorizedError, };
16
+ export { OpenapiValidationErrors, HttpError, RequestBodyTooLargeError, InvalidJsonError, UnauthorizedError, };
package/dist/errors.js CHANGED
@@ -1,22 +1,10 @@
1
- import { error as openapiValidatorErrors } from 'express-openapi-validator';
2
- const isExpressOpenAPIValidatorError = (err) => {
3
- for (const key in openapiValidatorErrors) {
4
- if (err instanceof
5
- openapiValidatorErrors[key]) {
6
- return true;
7
- }
8
- }
9
- return false;
10
- };
1
+ import { error as OpenapiValidationErrors } from 'express-openapi-validator';
11
2
  class HttpError extends Error {
12
3
  status;
13
4
  constructor(message, status) {
14
5
  super(message);
15
6
  this.status = status;
16
7
  }
17
- type() {
18
- return this.constructor.name;
19
- }
20
8
  }
21
9
  class UnauthorizedError extends HttpError {
22
10
  constructor() {
@@ -35,4 +23,4 @@ class InvalidJsonError extends HttpError {
35
23
  this.jsonString = jsonString;
36
24
  }
37
25
  }
38
- export { isExpressOpenAPIValidatorError, HttpError, RequestBodyTooLargeError, InvalidJsonError, UnauthorizedError, };
26
+ export { OpenapiValidationErrors, HttpError, RequestBodyTooLargeError, InvalidJsonError, UnauthorizedError, };
@@ -15,7 +15,7 @@ function openapiExpress(options) {
15
15
  if (decodeJsonBody) {
16
16
  app.use(json());
17
17
  }
18
- if (validateRequest || validateResponse)
18
+ if (validateRequest || validateResponse) {
19
19
  app.use(...requestResponseValidatorMiddleware({
20
20
  spec,
21
21
  validation: {
@@ -23,6 +23,7 @@ function openapiExpress(options) {
23
23
  responses: validateResponse,
24
24
  },
25
25
  }));
26
+ }
26
27
  for (const m of middleware) {
27
28
  app.use(m);
28
29
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ts-openapi-express",
3
3
  "type": "module",
4
- "version": "1.0.3",
4
+ "version": "1.0.4",
5
5
  "description": "",
6
6
  "main": "dist/index.js",
7
7
  "directories": {
@@ -28,13 +28,23 @@
28
28
  "author": "",
29
29
  "license": "ISC",
30
30
  "dependencies": {
31
- "express": "^5.0.0",
32
- "express-openapi-validator": "^5.3.9",
33
31
  "lodash-es": "^4.17.23",
34
- "yaml": "^2.8.1"
32
+ "yaml": "^2.8.1",
33
+ "express-openapi-validator": "^5.0.0"
34
+ },
35
+ "peerDependencies": {
36
+ "express": "^5.0.0"
37
+ },
38
+ "peerDependenciesMeta": {
39
+ "express": {
40
+ "optional": false
41
+ },
42
+ "express-openapi-validator": {
43
+ "optional": false
44
+ }
35
45
  },
36
46
  "devDependencies": {
37
- "@types/express": "^5.0.0",
47
+ "@types/express": "^5.0.6",
38
48
  "@types/lodash-es": "^4.17.12",
39
49
  "@types/node": "^22.0.0",
40
50
  "@types/supertest": "^6.0.2",
@@ -50,9 +60,9 @@
50
60
  "README.md"
51
61
  ],
52
62
  "scripts": {
53
- "test": "pnpm test:unit",
54
- "test:unit": "pnpm test:compile:spec && vitest run",
55
- "test:compile:spec": "openapi-typescript test/unit/openapi.test.yaml --output test/unit/test-schema.ts",
63
+ "test": "vitest run",
64
+ "test:unit": "pnpm pretest && vitest run",
65
+ "pretest": "openapi-typescript test/unit/openapi.test.yaml --output test/unit/test-schema.gen.ts",
56
66
  "compile": "tsc -p tsconfig.prod.json",
57
67
  "watch": "tsc -p tsconfig.prod.json --watch"
58
68
  }