swagger-client 3.27.6 → 3.27.8

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.
@@ -220,7 +220,7 @@ function buildRequest(options) {
220
220
  method,
221
221
  pathName
222
222
  } = operationRaw;
223
- req.url += baseUrl({
223
+ const baseURL = baseUrl({
224
224
  spec,
225
225
  scheme,
226
226
  contextUrl,
@@ -229,6 +229,7 @@ function buildRequest(options) {
229
229
  pathName,
230
230
  method
231
231
  });
232
+ req.url += baseURL;
232
233
 
233
234
  // Mostly for testing
234
235
  if (!operationId) {
@@ -292,7 +293,7 @@ function buildRequest(options) {
292
293
  value,
293
294
  operation,
294
295
  spec,
295
- pathName
296
+ baseURL
296
297
  });
297
298
  }
298
299
  });
@@ -372,7 +373,7 @@ function oas3BaseUrl({
372
373
  }
373
374
  if (selectedServerUrl.includes('{')) {
374
375
  // do variable substitution
375
- const varNames = getVariableTemplateNames(selectedServerUrl);
376
+ const varNames = extractServerVariableNames(selectedServerUrl);
376
377
  varNames.forEach(variable => {
377
378
  if (selectedServerObj.variables && selectedServerObj.variables[variable]) {
378
379
  // variable is defined in server
@@ -402,16 +403,9 @@ function buildOas3UrlWithContext(ourUrl = '', contextUrl = '') {
402
403
  }
403
404
  return res[res.length - 1] === '/' ? res.slice(0, -1) : res;
404
405
  }
405
- function getVariableTemplateNames(str) {
406
- const results = [];
407
- const re = /{([^}]{1,29})}/g;
408
- let text;
409
-
410
- // eslint-disable-next-line no-cond-assign
411
- while (text = re.exec(str)) {
412
- results.push(text[1]);
413
- }
414
- return results;
406
+ function extractServerVariableNames(serverURL) {
407
+ const match = serverURL.matchAll(/\{([^{}]+)}|([^{}]+)/g);
408
+ return Array.from(match, ([, variable]) => variable).filter(Boolean);
415
409
  }
416
410
 
417
411
  // Compose the baseUrl ( scheme + host + basePath )
@@ -680,7 +674,7 @@ function path({
680
674
  req,
681
675
  value,
682
676
  parameter,
683
- pathName
677
+ baseURL
684
678
  }) {
685
679
  const {
686
680
  name,
@@ -689,16 +683,17 @@ function path({
689
683
  content
690
684
  } = parameter;
691
685
  if (value === undefined) return;
686
+ const pathname = req.url.replace(baseURL, '');
692
687
  let resolvedPathname;
693
688
  if (content) {
694
689
  const effectiveMediaType = Object.keys(content)[0];
695
- resolvedPathname = (0,openapi_path_templating__WEBPACK_IMPORTED_MODULE_0__.resolve)(pathName, {
690
+ resolvedPathname = (0,openapi_path_templating__WEBPACK_IMPORTED_MODULE_0__.resolve)(pathname, {
696
691
  [name]: value
697
692
  }, {
698
693
  encoder: val => (0,_style_serializer_js__WEBPACK_IMPORTED_MODULE_1__.encodeCharacters)((0,_content_serializer_js__WEBPACK_IMPORTED_MODULE_2__["default"])(val, effectiveMediaType))
699
694
  });
700
695
  } else {
701
- resolvedPathname = (0,openapi_path_templating__WEBPACK_IMPORTED_MODULE_0__.resolve)(pathName, {
696
+ resolvedPathname = (0,openapi_path_templating__WEBPACK_IMPORTED_MODULE_0__.resolve)(pathname, {
702
697
  [name]: value
703
698
  }, {
704
699
  encoder: val => (0,_style_serializer_js__WEBPACK_IMPORTED_MODULE_1__["default"])({
@@ -710,7 +705,7 @@ function path({
710
705
  })
711
706
  });
712
707
  }
713
- req.url = req.url.replace(pathName, resolvedPathname);
708
+ req.url = baseURL + resolvedPathname;
714
709
  }
715
710
  function query({
716
711
  req,
@@ -1167,13 +1162,14 @@ function pathBuilder({
1167
1162
  req,
1168
1163
  value,
1169
1164
  parameter,
1170
- pathName
1165
+ baseURL
1171
1166
  }) {
1172
1167
  if (value !== undefined) {
1173
- const resolvedPathname = (0,openapi_path_templating__WEBPACK_IMPORTED_MODULE_0__.resolve)(pathName, {
1168
+ const pathname = req.url.replace(baseURL, '');
1169
+ const resolvedPathname = (0,openapi_path_templating__WEBPACK_IMPORTED_MODULE_0__.resolve)(pathname, {
1174
1170
  [parameter.name]: value
1175
1171
  });
1176
- req.url = req.url.replace(pathName, resolvedPathname);
1172
+ req.url = baseURL + resolvedPathname;
1177
1173
  }
1178
1174
  }
1179
1175