swagger-client 3.37.7 → 3.38.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.
@@ -15,6 +15,8 @@ import { getOperationRaw, idFromPathMethodLegacy } from '../helpers/index.js';
15
15
  import { isOpenAPI3 } from '../helpers/openapi-predicates.js';
16
16
  import { serialize as serializeCookie } from '../helpers/cookie.js';
17
17
  const arrayOrEmpty = ar => Array.isArray(ar) ? ar : [];
18
+ const HTTP_METHOD_TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
19
+ const isValidHttpMethod = method => typeof method === 'string' && HTTP_METHOD_TOKEN.test(method);
18
20
  const findObjectOrArraySchema = (schema, {
19
21
  recurse = true,
20
22
  depth = 1
@@ -215,6 +217,9 @@ export function buildRequest(options) {
215
217
  method,
216
218
  pathName
217
219
  } = operationRaw;
220
+ if (!isValidHttpMethod(method)) {
221
+ throw new Error('Invalid HTTP method');
222
+ }
218
223
  baseURL = baseURL ?? baseUrl({
219
224
  spec,
220
225
  scheme,
@@ -223,6 +228,7 @@ export function buildRequest(options) {
223
228
  serverVariables,
224
229
  pathName,
225
230
  method,
231
+ operation,
226
232
  serverVariableEncoder
227
233
  });
228
234
  req.url += baseURL;
@@ -237,7 +243,9 @@ export function buildRequest(options) {
237
243
  return req;
238
244
  }
239
245
  req.url += pathName; // Have not yet replaced the path parameters
240
- req.method = `${method}`.toUpperCase();
246
+ // Standard operations are normalized by eachOperation; additionalOperations
247
+ // must retain the exact HTTP method token defined by the OAS 3.2 document.
248
+ req.method = method;
241
249
  parameters = parameters || {};
242
250
  const path = spec.paths[pathName] || {};
243
251
  if (responseContentType) {
@@ -356,6 +364,7 @@ function oas3BaseUrl({
356
364
  spec,
357
365
  pathName,
358
366
  method,
367
+ operation,
359
368
  server,
360
369
  contextUrl,
361
370
  serverVariables = {},
@@ -366,7 +375,7 @@ function oas3BaseUrl({
366
375
  let selectedServerObj;
367
376
 
368
377
  // compute the servers (this will be taken care of by ApiDOM refrator plugins in future
369
- const operationLevelServers = spec?.paths?.[pathName]?.[(method || '').toLowerCase()]?.servers;
378
+ const operationLevelServers = operation?.servers ?? spec?.paths?.[pathName]?.[(method || '').toLowerCase()]?.servers;
370
379
  const pathItemLevelServers = spec?.paths?.[pathName]?.servers;
371
380
  const rootLevelServers = spec?.servers;
372
381
  servers = isNonEmptyServerList(operationLevelServers) // eslint-disable-line no-nested-ternary
@@ -1,3 +1,5 @@
1
+ import { isOpenAPI32 } from './openapi-predicates.js';
2
+
1
3
  // iterate over each operation, and fire a callback with details
2
4
  // `find=true` will stop iterating, when the cb returns truthy
3
5
  export default function eachOperation(spec, cb, find) {
@@ -7,13 +9,14 @@ export default function eachOperation(spec, cb, find) {
7
9
  const {
8
10
  paths
9
11
  } = spec;
12
+ const supportsAdditionalOperations = isOpenAPI32(spec);
10
13
 
11
14
  // Iterate over the spec, collecting operations
12
15
  // eslint-disable-next-line no-restricted-syntax, guard-for-in
13
16
  for (const pathName in paths) {
14
17
  // eslint-disable-next-line no-restricted-syntax, guard-for-in
15
18
  for (const method in paths[pathName]) {
16
- if (method.toUpperCase() === 'PARAMETERS') {
19
+ if (method.toUpperCase() === 'PARAMETERS' || method === 'additionalOperations') {
17
20
  continue; // eslint-disable-line no-continue
18
21
  }
19
22
  const operation = paths[pathName][method];
@@ -31,6 +34,28 @@ export default function eachOperation(spec, cb, find) {
31
34
  return operationObj;
32
35
  }
33
36
  }
37
+ const {
38
+ additionalOperations
39
+ } = paths[pathName];
40
+ if (supportsAdditionalOperations && additionalOperations && typeof additionalOperations === 'object') {
41
+ // eslint-disable-next-line no-restricted-syntax
42
+ for (const method of Object.keys(additionalOperations)) {
43
+ const operation = additionalOperations[method];
44
+ if (!operation || typeof operation !== 'object') {
45
+ continue; // eslint-disable-line no-continue
46
+ }
47
+ const operationObj = {
48
+ spec,
49
+ pathName,
50
+ method,
51
+ operation
52
+ };
53
+ const cbValue = cb(operationObj);
54
+ if (find && cbValue) {
55
+ return operationObj;
56
+ }
57
+ }
58
+ }
34
59
  }
35
60
  return undefined;
36
61
  }
@@ -1,4 +1,5 @@
1
1
  import replaceSpecialCharsWithUnderscore from '../replace-special-chars-with-underscore.js';
2
+ const STANDARD_HTTP_METHODS = new Set(['connect', 'delete', 'get', 'head', 'options', 'patch', 'post', 'put', 'query', 'trace']);
2
3
  export default function idFromPathMethod(pathName, method, {
3
4
  v2OperationIdCompatibilityMode
4
5
  } = {}) {
@@ -7,5 +8,6 @@ export default function idFromPathMethod(pathName, method, {
7
8
  res = res || `${pathName.substring(1)}_${method}`;
8
9
  return res.replace(/((_){2,})/g, '_').replace(/^(_)*/g, '').replace(/([_])*$/g, '');
9
10
  }
10
- return `${method.toLowerCase()}${replaceSpecialCharsWithUnderscore(pathName)}`;
11
+ const normalizedMethod = STANDARD_HTTP_METHODS.has(method.toLowerCase()) ? method.toLowerCase() : method;
12
+ return `${normalizedMethod}${replaceSpecialCharsWithUnderscore(pathName)}`;
11
13
  }
@@ -24,6 +24,8 @@ var _index3 = require("../helpers/index.js");
24
24
  var _openapiPredicates = require("../helpers/openapi-predicates.js");
25
25
  var _cookie = require("../helpers/cookie.js");
26
26
  const arrayOrEmpty = ar => Array.isArray(ar) ? ar : [];
27
+ const HTTP_METHOD_TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
28
+ const isValidHttpMethod = method => typeof method === 'string' && HTTP_METHOD_TOKEN.test(method);
27
29
  const findObjectOrArraySchema = (schema, {
28
30
  recurse = true,
29
31
  depth = 1
@@ -224,6 +226,9 @@ function buildRequest(options) {
224
226
  method,
225
227
  pathName
226
228
  } = operationRaw;
229
+ if (!isValidHttpMethod(method)) {
230
+ throw new Error('Invalid HTTP method');
231
+ }
227
232
  baseURL = baseURL ?? baseUrl({
228
233
  spec,
229
234
  scheme,
@@ -232,6 +237,7 @@ function buildRequest(options) {
232
237
  serverVariables,
233
238
  pathName,
234
239
  method,
240
+ operation,
235
241
  serverVariableEncoder
236
242
  });
237
243
  req.url += baseURL;
@@ -246,7 +252,9 @@ function buildRequest(options) {
246
252
  return req;
247
253
  }
248
254
  req.url += pathName; // Have not yet replaced the path parameters
249
- req.method = `${method}`.toUpperCase();
255
+ // Standard operations are normalized by eachOperation; additionalOperations
256
+ // must retain the exact HTTP method token defined by the OAS 3.2 document.
257
+ req.method = method;
250
258
  parameters = parameters || {};
251
259
  const path = spec.paths[pathName] || {};
252
260
  if (responseContentType) {
@@ -365,6 +373,7 @@ function oas3BaseUrl({
365
373
  spec,
366
374
  pathName,
367
375
  method,
376
+ operation,
368
377
  server,
369
378
  contextUrl,
370
379
  serverVariables = {},
@@ -375,7 +384,7 @@ function oas3BaseUrl({
375
384
  let selectedServerObj;
376
385
 
377
386
  // compute the servers (this will be taken care of by ApiDOM refrator plugins in future
378
- const operationLevelServers = spec?.paths?.[pathName]?.[(method || '').toLowerCase()]?.servers;
387
+ const operationLevelServers = operation?.servers ?? spec?.paths?.[pathName]?.[(method || '').toLowerCase()]?.servers;
379
388
  const pathItemLevelServers = spec?.paths?.[pathName]?.servers;
380
389
  const rootLevelServers = spec?.servers;
381
390
  servers = isNonEmptyServerList(operationLevelServers) // eslint-disable-line no-nested-ternary
@@ -2,6 +2,7 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  exports.default = eachOperation;
5
+ var _openapiPredicates = require("./openapi-predicates.js");
5
6
  // iterate over each operation, and fire a callback with details
6
7
  // `find=true` will stop iterating, when the cb returns truthy
7
8
  function eachOperation(spec, cb, find) {
@@ -11,13 +12,14 @@ function eachOperation(spec, cb, find) {
11
12
  const {
12
13
  paths
13
14
  } = spec;
15
+ const supportsAdditionalOperations = (0, _openapiPredicates.isOpenAPI32)(spec);
14
16
 
15
17
  // Iterate over the spec, collecting operations
16
18
  // eslint-disable-next-line no-restricted-syntax, guard-for-in
17
19
  for (const pathName in paths) {
18
20
  // eslint-disable-next-line no-restricted-syntax, guard-for-in
19
21
  for (const method in paths[pathName]) {
20
- if (method.toUpperCase() === 'PARAMETERS') {
22
+ if (method.toUpperCase() === 'PARAMETERS' || method === 'additionalOperations') {
21
23
  continue; // eslint-disable-line no-continue
22
24
  }
23
25
  const operation = paths[pathName][method];
@@ -35,6 +37,28 @@ function eachOperation(spec, cb, find) {
35
37
  return operationObj;
36
38
  }
37
39
  }
40
+ const {
41
+ additionalOperations
42
+ } = paths[pathName];
43
+ if (supportsAdditionalOperations && additionalOperations && typeof additionalOperations === 'object') {
44
+ // eslint-disable-next-line no-restricted-syntax
45
+ for (const method of Object.keys(additionalOperations)) {
46
+ const operation = additionalOperations[method];
47
+ if (!operation || typeof operation !== 'object') {
48
+ continue; // eslint-disable-line no-continue
49
+ }
50
+ const operationObj = {
51
+ spec,
52
+ pathName,
53
+ method,
54
+ operation
55
+ };
56
+ const cbValue = cb(operationObj);
57
+ if (find && cbValue) {
58
+ return operationObj;
59
+ }
60
+ }
61
+ }
38
62
  }
39
63
  return undefined;
40
64
  }
@@ -4,6 +4,7 @@ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequ
4
4
  exports.__esModule = true;
5
5
  exports.default = idFromPathMethod;
6
6
  var _replaceSpecialCharsWithUnderscore = _interopRequireDefault(require("../replace-special-chars-with-underscore.js"));
7
+ const STANDARD_HTTP_METHODS = new Set(['connect', 'delete', 'get', 'head', 'options', 'patch', 'post', 'put', 'query', 'trace']);
7
8
  function idFromPathMethod(pathName, method, {
8
9
  v2OperationIdCompatibilityMode
9
10
  } = {}) {
@@ -12,5 +13,6 @@ function idFromPathMethod(pathName, method, {
12
13
  res = res || `${pathName.substring(1)}_${method}`;
13
14
  return res.replace(/((_){2,})/g, '_').replace(/^(_)*/g, '').replace(/([_])*$/g, '');
14
15
  }
15
- return `${method.toLowerCase()}${(0, _replaceSpecialCharsWithUnderscore.default)(pathName)}`;
16
+ const normalizedMethod = STANDARD_HTTP_METHODS.has(method.toLowerCase()) ? method.toLowerCase() : method;
17
+ return `${normalizedMethod}${(0, _replaceSpecialCharsWithUnderscore.default)(pathName)}`;
16
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swagger-client",
3
- "version": "3.37.7",
3
+ "version": "3.38.0",
4
4
  "description": "SwaggerJS - a collection of interfaces for OAI specs",
5
5
  "browser": {
6
6
  "./src/helpers/btoa.node.js": "./src/helpers/btoa.browser.js",
@@ -74,17 +74,17 @@
74
74
  "dependencies": {
75
75
  "@babel/runtime-corejs3": "^7.22.15",
76
76
  "@scarf/scarf": "=1.4.0",
77
- "@swagger-api/apidom-core": "^1.11.0",
78
- "@swagger-api/apidom-error": "^1.11.0",
79
- "@swagger-api/apidom-json-pointer": "^1.11.0",
80
- "@swagger-api/apidom-ns-openapi-3-1": "^1.11.0",
81
- "@swagger-api/apidom-ns-openapi-3-2": "^1.11.0",
82
- "@swagger-api/apidom-reference": "^1.11.0",
77
+ "@swagger-api/apidom-core": "^1.12.0",
78
+ "@swagger-api/apidom-error": "^1.12.0",
79
+ "@swagger-api/apidom-json-pointer": "^1.12.0",
80
+ "@swagger-api/apidom-ns-openapi-3-1": "^1.12.0",
81
+ "@swagger-api/apidom-ns-openapi-3-2": "^1.12.0",
82
+ "@swagger-api/apidom-reference": "^1.12.0",
83
83
  "@swaggerexpert/cookie": "^2.0.2",
84
84
  "deepmerge": "~4.3.0",
85
85
  "fast-json-patch": "^3.0.0-1",
86
86
  "js-yaml": "^4.2.0",
87
- "neotraverse": "=0.6.18",
87
+ "neotraverse": "=1.0.1",
88
88
  "node-abort-controller": "^3.1.1",
89
89
  "openapi-path-templating": "^2.2.1",
90
90
  "openapi-server-url-templating": "^1.3.0",
@@ -101,12 +101,12 @@
101
101
  "@commitlint/cli": "^20.4.1",
102
102
  "@commitlint/config-conventional": "^20.4.1",
103
103
  "babel-loader": "=10.1.1",
104
- "cross-env": "=7.0.3",
104
+ "cross-env": "=10.1.0",
105
105
  "eslint": "^8.42.0",
106
106
  "eslint-config-airbnb-base": "^15.0.0",
107
107
  "eslint-config-prettier": "=10.1.8",
108
108
  "eslint-plugin-import": "=2.32.0",
109
- "eslint-plugin-prettier": "=5.5.4",
109
+ "eslint-plugin-prettier": "=5.5.6",
110
110
  "expect": "^30.3.0",
111
111
  "glob": "=13.0.6",
112
112
  "husky": "^9.0.11",
@@ -116,11 +116,11 @@
116
116
  "jest-environment-jsdom": "^30.4.1",
117
117
  "json-loader": "=0.5.7",
118
118
  "license-checker": "=25.0.1",
119
- "lint-staged": "=16.2.7",
119
+ "lint-staged": "=17.3.0",
120
120
  "lodash": "^4.17.21",
121
121
  "npm-run-all": "=4.1.5",
122
122
  "prettier": "^3.1.1",
123
- "rimraf": "=6.1.2",
123
+ "rimraf": "=6.1.3",
124
124
  "source-map-explorer": "^2.5.3",
125
125
  "terser-webpack-plugin": "^5.0.3",
126
126
  "undici": "^6.27.0",
@@ -130,26 +130,36 @@
130
130
  "webpack-stats-plugin": "=1.1.3"
131
131
  },
132
132
  "optionalDependencies": {
133
- "@swagger-api/apidom-ns-asyncapi-2": "^1.11.3",
134
- "@swagger-api/apidom-ns-asyncapi-3": "^1.11.3",
135
- "@swagger-api/apidom-ns-openapi-2": "^1.11.3",
136
- "@swagger-api/apidom-parser-adapter-api-design-systems-json": "^1.11.3",
137
- "@swagger-api/apidom-parser-adapter-api-design-systems-yaml": "^1.11.3",
138
- "@swagger-api/apidom-parser-adapter-asyncapi-json-2": "^1.11.3",
139
- "@swagger-api/apidom-parser-adapter-asyncapi-json-3": "^1.11.3",
140
- "@swagger-api/apidom-parser-adapter-asyncapi-yaml-2": "^1.11.3",
141
- "@swagger-api/apidom-parser-adapter-asyncapi-yaml-3": "^1.11.3",
142
- "@swagger-api/apidom-parser-adapter-json": "^1.11.3",
143
- "@swagger-api/apidom-parser-adapter-openapi-json-2": "^1.11.3",
144
- "@swagger-api/apidom-parser-adapter-openapi-yaml-2": "^1.11.3",
145
- "@swagger-api/apidom-parser-adapter-openapi-json-3-0": "^1.11.3",
146
- "@swagger-api/apidom-parser-adapter-openapi-json-3-1": "^1.11.3",
147
- "@swagger-api/apidom-parser-adapter-openapi-json-3-2": "^1.11.3",
148
- "@swagger-api/apidom-parser-adapter-openapi-yaml-3-0": "^1.11.3",
149
- "@swagger-api/apidom-parser-adapter-openapi-yaml-3-1": "^1.11.3",
150
- "@swagger-api/apidom-parser-adapter-openapi-yaml-3-2": "^1.11.3",
151
- "@swagger-api/apidom-parser-adapter-arazzo-json-1": "^1.11.3",
152
- "@swagger-api/apidom-parser-adapter-arazzo-yaml-1": "^1.11.3",
153
- "@swagger-api/apidom-parser-adapter-yaml-1-2": "^1.11.3"
133
+ "@swagger-api/apidom-ns-asyncapi-2": "^1.12.0",
134
+ "@swagger-api/apidom-ns-asyncapi-3": "^1.12.0",
135
+ "@swagger-api/apidom-ns-openapi-2": "^1.12.0",
136
+ "@swagger-api/apidom-parser-adapter-api-design-systems-json": "^1.12.0",
137
+ "@swagger-api/apidom-parser-adapter-api-design-systems-yaml": "^1.12.0",
138
+ "@swagger-api/apidom-parser-adapter-asyncapi-json-2": "^1.12.0",
139
+ "@swagger-api/apidom-parser-adapter-asyncapi-json-3": "^1.12.0",
140
+ "@swagger-api/apidom-parser-adapter-asyncapi-yaml-2": "^1.12.0",
141
+ "@swagger-api/apidom-parser-adapter-asyncapi-yaml-3": "^1.12.0",
142
+ "@swagger-api/apidom-parser-adapter-json": "^1.12.0",
143
+ "@swagger-api/apidom-parser-adapter-openapi-json-2": "^1.12.0",
144
+ "@swagger-api/apidom-parser-adapter-openapi-yaml-2": "^1.12.0",
145
+ "@swagger-api/apidom-parser-adapter-openapi-json-3-0": "^1.12.0",
146
+ "@swagger-api/apidom-parser-adapter-openapi-json-3-1": "^1.12.0",
147
+ "@swagger-api/apidom-parser-adapter-openapi-json-3-2": "^1.12.0",
148
+ "@swagger-api/apidom-parser-adapter-openapi-yaml-3-0": "^1.12.0",
149
+ "@swagger-api/apidom-parser-adapter-openapi-yaml-3-1": "^1.12.0",
150
+ "@swagger-api/apidom-parser-adapter-openapi-yaml-3-2": "^1.12.0",
151
+ "@swagger-api/apidom-parser-adapter-arazzo-json-1": "^1.12.0",
152
+ "@swagger-api/apidom-parser-adapter-arazzo-yaml-1": "^1.12.0",
153
+ "@swagger-api/apidom-parser-adapter-yaml-1-2": "^1.12.0"
154
+ },
155
+ "allowScripts": {
156
+ "tree-sitter@0.22.4": true,
157
+ "tree-sitter@0.21.1": true,
158
+ "@tree-sitter-grammars/tree-sitter-yaml@0.7.1": true,
159
+ "tree-sitter-json@0.24.8": true,
160
+ "fsevents@2.3.3": true,
161
+ "unrs-resolver@1.12.2": true,
162
+ "@scarf/scarf": false,
163
+ "core-js-pure": false
154
164
  }
155
165
  }