@express-tools/oas 0.0.1 → 0.0.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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2025 Frederic Charette
1
+ Copyright 2026 Frederic Charette
2
2
 
3
3
  Licensed under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License.
package/bin/index.js CHANGED
@@ -4,13 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.validation = exports.router = exports.response = exports.documentation = exports.definition = void 0;
7
- const definition_1 = __importDefault(require("./definition"));
8
- exports.definition = definition_1.default;
9
- const documentation_1 = __importDefault(require("./documentation"));
10
- exports.documentation = documentation_1.default;
11
- const response_1 = __importDefault(require("./response"));
12
- exports.response = response_1.default;
13
- const router_1 = __importDefault(require("./router"));
14
- exports.router = router_1.default;
15
- const validation_1 = __importDefault(require("./validation"));
16
- exports.validation = validation_1.default;
7
+ const definition_ts_1 = __importDefault(require("./definition.js"));
8
+ exports.definition = definition_ts_1.default;
9
+ const documentation_ts_1 = __importDefault(require("./documentation.js"));
10
+ exports.documentation = documentation_ts_1.default;
11
+ const response_ts_1 = __importDefault(require("./response.js"));
12
+ exports.response = response_ts_1.default;
13
+ const router_ts_1 = __importDefault(require("./router.js"));
14
+ exports.router = router_ts_1.default;
15
+ const validation_ts_1 = __importDefault(require("./validation.js"));
16
+ exports.validation = validation_ts_1.default;
package/bin/response.js CHANGED
@@ -2,13 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = response;
4
4
  const swagger_route_validator_1 = require("swagger-route-validator");
5
- const utils_1 = require("./utils");
5
+ const utils_ts_1 = require("./utils.js");
6
6
  function response() {
7
7
  function OASResponse(req, res, next) {
8
8
  if (!req.route)
9
9
  throw new Error('Response validation middleware must be added to a route');
10
- let operationId = (0, utils_1.formatPathToOAS)(req.route.path);
11
- // substract spec basepath if exists
10
+ let operationId = (0, utils_ts_1.formatPathToOAS)(req.route.path);
11
+ // subtract spec basePath if exists
12
12
  if (req._oas?.basePath && req._oas?.basePath !== '/' && operationId.indexOf(req._oas?.basePath) === 0)
13
13
  operationId = operationId.replace(req._oas?.basePath, '');
14
14
  const matchingSpec = req._oas?.paths?.[operationId]?.[req.method.toLowerCase()];
package/bin/router.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = router;
4
- const utils_1 = require("./utils");
4
+ const utils_ts_1 = require("./utils.js");
5
5
  function router(expressApp, spec) {
6
6
  let scanned = false;
7
7
  // Store a working copy of the spec in express app
@@ -14,8 +14,8 @@ function router(expressApp, spec) {
14
14
  components: {},
15
15
  tags: [],
16
16
  };
17
- (0, utils_1.mergeDefinitions)(expressApp['_oas'], spec);
18
- // Append config to request to prevent gymnastics
17
+ (0, utils_ts_1.mergeDefinitions)(expressApp['_oas'], spec);
18
+ // Append config to request to avoid redundant lookups
19
19
  function OASRouter(req, res, next) {
20
20
  req._oas = expressApp['_oas'];
21
21
  return next();
@@ -33,19 +33,19 @@ function router(expressApp, spec) {
33
33
  // Scan routes for definition middleware
34
34
  for (let i = 0; i < stack.length; i++) {
35
35
  if (stack[i].route) {
36
- const definitionPlugin = stack[i].route.stack.find(middleware => middleware.handle.OASType === 'definition');
36
+ const definitionPlugin = stack[i].route.stack.find(middleware => middleware.handle.name === 'OASDefinition');
37
37
  if (definitionPlugin) {
38
38
  const override = definitionPlugin.handle();
39
39
  let operationId = stack[i].route.path;
40
- // substract spec baspath if exists
40
+ // subtract spec basePath if exists
41
41
  if (spec.basePath && spec.basePath !== '/' && operationId.indexOf(expressApp.mountpath) === 0)
42
42
  operationId = operationId.replace(expressApp.mountpath, '');
43
43
  // Check if path level or method level
44
- expressApp['_oas'].paths[(0, utils_1.formatPathToOAS)(operationId)] = expressApp['_oas'].paths[(0, utils_1.formatPathToOAS)(operationId)] || {};
44
+ expressApp['_oas'].paths[(0, utils_ts_1.formatPathToOAS)(operationId)] = expressApp['_oas'].paths[(0, utils_ts_1.formatPathToOAS)(operationId)] || {};
45
45
  if (override[definitionPlugin.method])
46
- (0, utils_1.mergeDefinitions)(expressApp['_oas'].paths[(0, utils_1.formatPathToOAS)(operationId)], override);
46
+ (0, utils_ts_1.mergeDefinitions)(expressApp['_oas'].paths[(0, utils_ts_1.formatPathToOAS)(operationId)], override);
47
47
  else
48
- (0, utils_1.mergeDefinitions)(expressApp['_oas'].paths[(0, utils_1.formatPathToOAS)(operationId)], { [definitionPlugin.method]: override });
48
+ (0, utils_ts_1.mergeDefinitions)(expressApp['_oas'].paths[(0, utils_ts_1.formatPathToOAS)(operationId)], { [definitionPlugin.method]: override });
49
49
  }
50
50
  }
51
51
  }
package/bin/validation.js CHANGED
@@ -2,13 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = validate;
4
4
  const swagger_route_validator_1 = require("swagger-route-validator");
5
- const utils_1 = require("./utils");
5
+ const utils_ts_1 = require("./utils.js");
6
6
  function validate() {
7
7
  function OASValidation(req, res, next) {
8
8
  if (!req.route)
9
9
  throw new Error('Request validation middleware must be added to a route');
10
- let operationId = (0, utils_1.formatPathToOAS)(req.route.path);
11
- // substract spec baspath if exists
10
+ let operationId = (0, utils_ts_1.formatPathToOAS)(req.route.path);
11
+ // subtract spec basePath if exists
12
12
  if (req._oas?.basePath && req._oas?.basePath !== '/' && operationId.indexOf(req._oas?.basePath) === 0)
13
13
  operationId = operationId.replace(req._oas?.basePath, '');
14
14
  const matchingSpec = req._oas?.paths?.[operationId]?.[req.method.toLowerCase()];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@express-tools/oas",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "OpenAPI plugin for express",
5
5
  "license": "Apache-2.0",
6
6
  "main": "bin/index.js",
@@ -16,6 +16,9 @@
16
16
  "definition",
17
17
  "schema"
18
18
  ],
19
+ "engines": {
20
+ "node": ">=24"
21
+ },
19
22
  "files": [
20
23
  "bin",
21
24
  "types.d.ts"
@@ -24,14 +27,13 @@
24
27
  "swagger-route-validator": "^3.1.0"
25
28
  },
26
29
  "devDependencies": {
27
- "express": "^5.1.0",
28
- "undici": "^7.16.0"
30
+ "express": "^5.2.0"
29
31
  },
30
32
  "typings": "types.d.ts",
31
33
  "scripts": {
32
- "build": "rm -rf ./bin && mkdir ./bin && tsc --project ./tsconfig.json",
33
- "test:unit": "jest src/*",
34
- "test:integration": "jest tests/*",
34
+ "build": "rm -rf ./bin && mkdir ./bin && tsc --project ./tsconfig.json && find ./bin -name '*.js' -exec sed -i \"s/\\.ts'/\\.js'/g; s/\\.ts\\\"/\\.js\\\"/g\" {} \\;",
35
+ "test:unit": "node --test src/*.test.ts",
36
+ "test:integration": "node --test tests/integration/*.test.ts",
35
37
  "test": "npm run test:unit && npm run test:integration",
36
38
  "prepublishOnly": "npm run build && cp ../../LICENSE ./LICENSE"
37
39
  },
@@ -46,17 +48,5 @@
46
48
  "type": "git",
47
49
  "url": "git+ssh://git@github.com/nerve-box/express-tools.git",
48
50
  "directory": "packages/oas"
49
- },
50
- "jest": {
51
- "preset": "ts-jest",
52
- "testEnvironment": "node",
53
- "transform": {
54
- "^.+\\.m?[tj]sx?$": [
55
- "ts-jest",
56
- {
57
- "diagnostics": false
58
- }
59
- ]
60
- }
61
51
  }
62
52
  }