swagger-client 3.28.1 → 3.28.2

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.
@@ -1,7 +1,6 @@
1
- import _matchAllInstanceProperty from "@babel/runtime-corejs3/core-js/instance/match-all";
2
1
  import cookie from 'cookie';
3
- import { isPlainObject } from 'is-plain-object';
4
- import { escapeRegExp } from 'ramda-adjunct';
2
+ import { isPlainObject } from 'ramda-adjunct';
3
+ import { test as testServerURLTemplate, substitute as substituteServerURLTemplate } from 'openapi-server-url-templating';
5
4
  import { ApiDOMStructuredError } from '@swagger-api/apidom-error';
6
5
  import { url } from '@swagger-api/apidom-reference/configuration/empty';
7
6
  import { DEFAULT_BASE_URL, DEFAULT_OPENAPI_3_SERVER } from '../constants.js';
@@ -316,17 +315,18 @@ function oas3BaseUrl({
316
315
  [selectedServerObj] = servers;
317
316
  selectedServerUrl = selectedServerObj.url;
318
317
  }
319
- if (selectedServerUrl.includes('{')) {
320
- // do variable substitution
321
- const varNames = extractServerVariableNames(selectedServerUrl);
322
- varNames.forEach(variable => {
323
- if (selectedServerObj.variables && selectedServerObj.variables[variable]) {
324
- // variable is defined in server
325
- const variableDefinition = selectedServerObj.variables[variable];
326
- const variableValue = serverVariables[variable] || variableDefinition.default;
327
- const re = new RegExp(`{${escapeRegExp(variable)}}`, 'g');
328
- selectedServerUrl = selectedServerUrl.replace(re, variableValue);
329
- }
318
+ if (testServerURLTemplate(selectedServerUrl, {
319
+ strict: true
320
+ })) {
321
+ const selectedServerVariables = Object.entries({
322
+ ...selectedServerObj.variables
323
+ }).reduce((acc, [serverVariableName, serverVariable]) => {
324
+ acc[serverVariableName] = serverVariable.default;
325
+ return acc;
326
+ }, {});
327
+ selectedServerUrl = substituteServerURLTemplate(selectedServerUrl, {
328
+ ...selectedServerVariables,
329
+ ...serverVariables
330
330
  });
331
331
  }
332
332
  return buildOas3UrlWithContext(selectedServerUrl, contextUrl);
@@ -348,10 +348,6 @@ function buildOas3UrlWithContext(ourUrl = '', contextUrl = '') {
348
348
  }
349
349
  return res[res.length - 1] === '/' ? res.slice(0, -1) : res;
350
350
  }
351
- function extractServerVariableNames(serverURL) {
352
- const match = _matchAllInstanceProperty(serverURL).call(serverURL, /\{([^{}]+)}|([^{}]+)/g);
353
- return Array.from(match, ([, variable]) => variable).filter(Boolean);
354
- }
355
351
 
356
352
  // Compose the baseUrl ( scheme + host + basePath )
357
353
  function swagger2BaseUrl({
@@ -1,6 +1,6 @@
1
1
  // This function runs after the common function,
2
2
  // `src/execute/index.js#buildRequest`
3
- import { isPlainObject } from 'is-plain-object';
3
+ import { isPlainObject } from 'ramda-adjunct';
4
4
  import btoa from '../../helpers/btoa.node.js';
5
5
  export default function buildRequest(options, req) {
6
6
  const {
@@ -7,10 +7,9 @@ exports.baseUrl = baseUrl;
7
7
  exports.buildRequest = buildRequest;
8
8
  exports.execute = execute;
9
9
  exports.self = void 0;
10
- var _matchAll = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/match-all"));
11
10
  var _cookie = _interopRequireDefault(require("cookie"));
12
- var _isPlainObject = require("is-plain-object");
13
11
  var _ramdaAdjunct = require("ramda-adjunct");
12
+ var _openapiServerUrlTemplating = require("openapi-server-url-templating");
14
13
  var _apidomError = require("@swagger-api/apidom-error");
15
14
  var _empty = require("@swagger-api/apidom-reference/configuration/empty");
16
15
  var _constants = require("../constants.js");
@@ -104,7 +103,7 @@ function execute({
104
103
  http,
105
104
  ...extras
106
105
  });
107
- if (request.body && ((0, _isPlainObject.isPlainObject)(request.body) || Array.isArray(request.body))) {
106
+ if (request.body && ((0, _ramdaAdjunct.isPlainObject)(request.body) || Array.isArray(request.body))) {
108
107
  request.body = JSON.stringify(request.body);
109
108
  }
110
109
 
@@ -325,17 +324,18 @@ function oas3BaseUrl({
325
324
  [selectedServerObj] = servers;
326
325
  selectedServerUrl = selectedServerObj.url;
327
326
  }
328
- if (selectedServerUrl.includes('{')) {
329
- // do variable substitution
330
- const varNames = extractServerVariableNames(selectedServerUrl);
331
- varNames.forEach(variable => {
332
- if (selectedServerObj.variables && selectedServerObj.variables[variable]) {
333
- // variable is defined in server
334
- const variableDefinition = selectedServerObj.variables[variable];
335
- const variableValue = serverVariables[variable] || variableDefinition.default;
336
- const re = new RegExp(`{${(0, _ramdaAdjunct.escapeRegExp)(variable)}}`, 'g');
337
- selectedServerUrl = selectedServerUrl.replace(re, variableValue);
338
- }
327
+ if ((0, _openapiServerUrlTemplating.test)(selectedServerUrl, {
328
+ strict: true
329
+ })) {
330
+ const selectedServerVariables = Object.entries({
331
+ ...selectedServerObj.variables
332
+ }).reduce((acc, [serverVariableName, serverVariable]) => {
333
+ acc[serverVariableName] = serverVariable.default;
334
+ return acc;
335
+ }, {});
336
+ selectedServerUrl = (0, _openapiServerUrlTemplating.substitute)(selectedServerUrl, {
337
+ ...selectedServerVariables,
338
+ ...serverVariables
339
339
  });
340
340
  }
341
341
  return buildOas3UrlWithContext(selectedServerUrl, contextUrl);
@@ -357,10 +357,6 @@ function buildOas3UrlWithContext(ourUrl = '', contextUrl = '') {
357
357
  }
358
358
  return res[res.length - 1] === '/' ? res.slice(0, -1) : res;
359
359
  }
360
- function extractServerVariableNames(serverURL) {
361
- const match = (0, _matchAll.default)(serverURL).call(serverURL, /\{([^{}]+)}|([^{}]+)/g);
362
- return Array.from(match, ([, variable]) => variable).filter(Boolean);
363
- }
364
360
 
365
361
  // Compose the baseUrl ( scheme + host + basePath )
366
362
  function swagger2BaseUrl({
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequ
4
4
  exports.__esModule = true;
5
5
  exports.applySecurities = applySecurities;
6
6
  exports.default = buildRequest;
7
- var _isPlainObject = require("is-plain-object");
7
+ var _ramdaAdjunct = require("ramda-adjunct");
8
8
  var _btoaNode = _interopRequireDefault(require("../../helpers/btoa.node.js"));
9
9
  // This function runs after the common function,
10
10
  // `src/execute/index.js#buildRequest`
@@ -49,7 +49,7 @@ function buildRequest(options, req) {
49
49
  if (!options.responseContentType && operation.responses) {
50
50
  const mediaTypes = Object.entries(operation.responses).filter(([key, value]) => {
51
51
  const code = parseInt(key, 10);
52
- return code >= 200 && code < 300 && (0, _isPlainObject.isPlainObject)(value.content);
52
+ return code >= 200 && code < 300 && (0, _ramdaAdjunct.isPlainObject)(value.content);
53
53
  }).reduce((acc, [, value]) => acc.concat(Object.keys(value.content)), []);
54
54
  if (mediaTypes.length > 0) {
55
55
  req.headers.accept = mediaTypes.join(', ');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swagger-client",
3
- "version": "3.28.1",
3
+ "version": "3.28.2",
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",
@@ -73,19 +73,19 @@
73
73
  "license": "Apache-2.0",
74
74
  "dependencies": {
75
75
  "@babel/runtime-corejs3": "^7.22.15",
76
- "@swagger-api/apidom-core": ">=1.0.0-alpha.3 <1.0.0-beta.0",
77
- "@swagger-api/apidom-error": ">=1.0.0-alpha.1 <1.0.0-beta.0",
78
- "@swagger-api/apidom-json-pointer": ">=1.0.0-alpha.3 <1.0.0-beta.0",
79
- "@swagger-api/apidom-ns-openapi-3-1": ">=1.0.0-alpha.3 <1.0.0-beta.0",
80
- "@swagger-api/apidom-reference": ">=1.0.0-alpha.3 <1.0.0-beta.0",
76
+ "@swagger-api/apidom-core": ">=1.0.0-alpha.5 <1.0.0-beta.0",
77
+ "@swagger-api/apidom-error": ">=1.0.0-alpha.5 <1.0.0-beta.0",
78
+ "@swagger-api/apidom-json-pointer": ">=1.0.0-alpha.5 <1.0.0-beta.0",
79
+ "@swagger-api/apidom-ns-openapi-3-1": ">=1.0.0-alpha.5 <1.0.0-beta.0",
80
+ "@swagger-api/apidom-reference": ">=1.0.0-alpha.5 <1.0.0-beta.0",
81
81
  "cookie": "~0.6.0",
82
82
  "deepmerge": "~4.3.0",
83
83
  "fast-json-patch": "^3.0.0-1",
84
- "is-plain-object": "^5.0.0",
85
84
  "js-yaml": "^4.1.0",
86
85
  "node-abort-controller": "^3.1.1",
87
86
  "node-fetch-commonjs": "^3.3.2",
88
87
  "openapi-path-templating": "^1.5.1",
88
+ "openapi-server-url-templating": "^1.0.0",
89
89
  "qs": "^6.10.2",
90
90
  "ramda-adjunct": "^5.0.0",
91
91
  "traverse": "=0.6.8"
@@ -107,7 +107,7 @@
107
107
  "eslint-plugin-import": "=2.29.1",
108
108
  "eslint-plugin-prettier": "=5.1.3",
109
109
  "expect": "^29.0.3",
110
- "glob": "=10.3.15",
110
+ "glob": "=10.4.1",
111
111
  "husky": "^9.0.11",
112
112
  "inspectpack": "=4.7.1",
113
113
  "install": "=0.13.0",
@@ -115,7 +115,7 @@
115
115
  "jest-environment-jsdom": "^29.0.3",
116
116
  "json-loader": "=0.5.7",
117
117
  "license-checker": "=25.0.1",
118
- "lint-staged": "=15.2.2",
118
+ "lint-staged": "=15.2.5",
119
119
  "lodash": "^4.17.21",
120
120
  "npm-run-all": "=4.1.5",
121
121
  "prettier": "^3.1.1",