swagger-client 3.34.1 → 3.34.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.
@@ -14,27 +14,27 @@ import { getOperationRaw, idFromPathMethodLegacy } from '../helpers/index.js';
14
14
  import { isOpenAPI3 } from '../helpers/openapi-predicates.js';
15
15
  import { serialize as serializeCookie } from '../helpers/cookie.js';
16
16
  const arrayOrEmpty = ar => Array.isArray(ar) ? ar : [];
17
- const findObjectSchema = (schema, {
17
+ const findObjectOrArraySchema = (schema, {
18
18
  recurse = true,
19
19
  depth = 1
20
20
  } = {}) => {
21
21
  if (!isPlainObject(schema)) return undefined;
22
22
 
23
- // check if the schema is an object type
24
- if (schema.type === 'object' || Array.isArray(schema.type) && schema.type.includes('object')) {
23
+ // check if the schema is an object or array type
24
+ if (schema.type === 'object' || schema.type === 'array' || Array.isArray(schema.type) && (schema.type.includes('object') || schema.type.includes('array'))) {
25
25
  return schema;
26
26
  }
27
27
  if (depth > TRAVERSE_LIMIT) return undefined;
28
28
  if (recurse) {
29
29
  // traverse oneOf keyword first
30
- const oneOfResult = Array.isArray(schema.oneOf) ? schema.oneOf.find(subschema => findObjectSchema(subschema, {
30
+ const oneOfResult = Array.isArray(schema.oneOf) ? schema.oneOf.find(subschema => findObjectOrArraySchema(subschema, {
31
31
  recurse,
32
32
  depth: depth + 1
33
33
  })) : undefined;
34
34
  if (oneOfResult) return oneOfResult;
35
35
 
36
36
  // traverse anyOf keyword second
37
- const anyOfResult = Array.isArray(schema.anyOf) ? schema.anyOf.find(subschema => findObjectSchema(subschema, {
37
+ const anyOfResult = Array.isArray(schema.anyOf) ? schema.anyOf.find(subschema => findObjectOrArraySchema(subschema, {
38
38
  recurse,
39
39
  depth: depth + 1
40
40
  })) : undefined;
@@ -42,21 +42,21 @@ const findObjectSchema = (schema, {
42
42
  }
43
43
  return undefined;
44
44
  };
45
- const parseJsonObject = ({
45
+ const parseJsonObjectOrArray = ({
46
46
  value,
47
47
  silentFail = false
48
48
  }) => {
49
49
  try {
50
50
  const parsedValue = JSON.parse(value);
51
- if (typeof parsedValue === 'object') {
51
+ if (isPlainObject(parsedValue) || Array.isArray(parsedValue)) {
52
52
  return parsedValue;
53
53
  }
54
54
  if (!silentFail) {
55
- throw new Error('Expected JSON serialized object');
55
+ throw new Error('Expected JSON serialized object or array');
56
56
  }
57
57
  } catch {
58
58
  if (!silentFail) {
59
- throw new Error('Could not parse object parameter value string as JSON Object');
59
+ throw new Error('Could not parse parameter value string as JSON Object or JSON Array');
60
60
  }
61
61
  }
62
62
  return value;
@@ -274,17 +274,24 @@ export function buildRequest(options) {
274
274
  throw new Error(`Required parameter ${parameter.name} is not provided`);
275
275
  }
276
276
  if (specIsOAS3 && typeof value === 'string') {
277
- if (has('type', parameter.schema) && findObjectSchema(parameter.schema, {
277
+ if (has('type', parameter.schema) && typeof parameter.schema.type === 'string' && findObjectOrArraySchema(parameter.schema, {
278
278
  recurse: false
279
279
  })) {
280
- value = parseJsonObject({
280
+ value = parseJsonObjectOrArray({
281
281
  value,
282
282
  silentFail: false
283
283
  });
284
- } else if (findObjectSchema(parameter.schema, {
284
+ } else if (has('type', parameter.schema) && Array.isArray(parameter.schema.type) && findObjectOrArraySchema(parameter.schema, {
285
+ recurse: false
286
+ })) {
287
+ value = parseJsonObjectOrArray({
288
+ value,
289
+ silentFail: true
290
+ });
291
+ } else if (!has('type', parameter.schema) && findObjectOrArraySchema(parameter.schema, {
285
292
  recurse: true
286
293
  })) {
287
- value = parseJsonObject({
294
+ value = parseJsonObjectOrArray({
288
295
  value,
289
296
  silentFail: true
290
297
  });
@@ -23,27 +23,27 @@ var _index3 = require("../helpers/index.js");
23
23
  var _openapiPredicates = require("../helpers/openapi-predicates.js");
24
24
  var _cookie = require("../helpers/cookie.js");
25
25
  const arrayOrEmpty = ar => Array.isArray(ar) ? ar : [];
26
- const findObjectSchema = (schema, {
26
+ const findObjectOrArraySchema = (schema, {
27
27
  recurse = true,
28
28
  depth = 1
29
29
  } = {}) => {
30
30
  if (!(0, _ramdaAdjunct.isPlainObject)(schema)) return undefined;
31
31
 
32
- // check if the schema is an object type
33
- if (schema.type === 'object' || Array.isArray(schema.type) && schema.type.includes('object')) {
32
+ // check if the schema is an object or array type
33
+ if (schema.type === 'object' || schema.type === 'array' || Array.isArray(schema.type) && (schema.type.includes('object') || schema.type.includes('array'))) {
34
34
  return schema;
35
35
  }
36
36
  if (depth > _constants.TRAVERSE_LIMIT) return undefined;
37
37
  if (recurse) {
38
38
  // traverse oneOf keyword first
39
- const oneOfResult = Array.isArray(schema.oneOf) ? schema.oneOf.find(subschema => findObjectSchema(subschema, {
39
+ const oneOfResult = Array.isArray(schema.oneOf) ? schema.oneOf.find(subschema => findObjectOrArraySchema(subschema, {
40
40
  recurse,
41
41
  depth: depth + 1
42
42
  })) : undefined;
43
43
  if (oneOfResult) return oneOfResult;
44
44
 
45
45
  // traverse anyOf keyword second
46
- const anyOfResult = Array.isArray(schema.anyOf) ? schema.anyOf.find(subschema => findObjectSchema(subschema, {
46
+ const anyOfResult = Array.isArray(schema.anyOf) ? schema.anyOf.find(subschema => findObjectOrArraySchema(subschema, {
47
47
  recurse,
48
48
  depth: depth + 1
49
49
  })) : undefined;
@@ -51,21 +51,21 @@ const findObjectSchema = (schema, {
51
51
  }
52
52
  return undefined;
53
53
  };
54
- const parseJsonObject = ({
54
+ const parseJsonObjectOrArray = ({
55
55
  value,
56
56
  silentFail = false
57
57
  }) => {
58
58
  try {
59
59
  const parsedValue = JSON.parse(value);
60
- if (typeof parsedValue === 'object') {
60
+ if ((0, _ramdaAdjunct.isPlainObject)(parsedValue) || Array.isArray(parsedValue)) {
61
61
  return parsedValue;
62
62
  }
63
63
  if (!silentFail) {
64
- throw new Error('Expected JSON serialized object');
64
+ throw new Error('Expected JSON serialized object or array');
65
65
  }
66
66
  } catch {
67
67
  if (!silentFail) {
68
- throw new Error('Could not parse object parameter value string as JSON Object');
68
+ throw new Error('Could not parse parameter value string as JSON Object or JSON Array');
69
69
  }
70
70
  }
71
71
  return value;
@@ -283,17 +283,24 @@ function buildRequest(options) {
283
283
  throw new Error(`Required parameter ${parameter.name} is not provided`);
284
284
  }
285
285
  if (specIsOAS3 && typeof value === 'string') {
286
- if ((0, _ramda.has)('type', parameter.schema) && findObjectSchema(parameter.schema, {
286
+ if ((0, _ramda.has)('type', parameter.schema) && typeof parameter.schema.type === 'string' && findObjectOrArraySchema(parameter.schema, {
287
287
  recurse: false
288
288
  })) {
289
- value = parseJsonObject({
289
+ value = parseJsonObjectOrArray({
290
290
  value,
291
291
  silentFail: false
292
292
  });
293
- } else if (findObjectSchema(parameter.schema, {
293
+ } else if ((0, _ramda.has)('type', parameter.schema) && Array.isArray(parameter.schema.type) && findObjectOrArraySchema(parameter.schema, {
294
+ recurse: false
295
+ })) {
296
+ value = parseJsonObjectOrArray({
297
+ value,
298
+ silentFail: true
299
+ });
300
+ } else if (!(0, _ramda.has)('type', parameter.schema) && findObjectOrArraySchema(parameter.schema, {
294
301
  recurse: true
295
302
  })) {
296
- value = parseJsonObject({
303
+ value = parseJsonObjectOrArray({
297
304
  value,
298
305
  silentFail: true
299
306
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swagger-client",
3
- "version": "3.34.1",
3
+ "version": "3.34.3",
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,11 +74,11 @@
74
74
  "dependencies": {
75
75
  "@babel/runtime-corejs3": "^7.22.15",
76
76
  "@scarf/scarf": "=1.4.0",
77
- "@swagger-api/apidom-core": ">=1.0.0-beta.12 <1.0.0-rc.0",
78
- "@swagger-api/apidom-error": ">=1.0.0-beta.12 <1.0.0-rc.0",
79
- "@swagger-api/apidom-json-pointer": ">=1.0.0-beta.12 <1.0.0-rc.0",
80
- "@swagger-api/apidom-ns-openapi-3-1": ">=1.0.0-beta.12 <1.0.0-rc.0",
81
- "@swagger-api/apidom-reference": ">=1.0.0-beta.12 <1.0.0-rc.0",
77
+ "@swagger-api/apidom-core": ">=1.0.0-beta.13 <1.0.0-rc.0",
78
+ "@swagger-api/apidom-error": ">=1.0.0-beta.13 <1.0.0-rc.0",
79
+ "@swagger-api/apidom-json-pointer": ">=1.0.0-beta.13 <1.0.0-rc.0",
80
+ "@swagger-api/apidom-ns-openapi-3-1": ">=1.0.0-beta.13 <1.0.0-rc.0",
81
+ "@swagger-api/apidom-reference": ">=1.0.0-beta.13 <1.0.0-rc.0",
82
82
  "@swaggerexpert/cookie": "^2.0.2",
83
83
  "deepmerge": "~4.3.0",
84
84
  "fast-json-patch": "^3.0.0-1",
@@ -86,10 +86,10 @@
86
86
  "neotraverse": "=0.6.18",
87
87
  "node-abort-controller": "^3.1.1",
88
88
  "node-fetch-commonjs": "^3.3.2",
89
- "openapi-path-templating": "^2.0.1",
90
- "openapi-server-url-templating": "^1.2.0",
89
+ "openapi-path-templating": "^2.2.1",
90
+ "openapi-server-url-templating": "^1.3.0",
91
91
  "ramda": "^0.30.1",
92
- "ramda-adjunct": "^5.0.0"
92
+ "ramda-adjunct": "^5.1.0"
93
93
  },
94
94
  "devDependencies": {
95
95
  "@babel/cli": "^7.21.0",
@@ -100,11 +100,11 @@
100
100
  "@babel/register": "^7.21.0",
101
101
  "@commitlint/cli": "^19.0.3",
102
102
  "@commitlint/config-conventional": "^19.0.3",
103
- "babel-loader": "=9.2.1",
103
+ "babel-loader": "=10.0.0",
104
104
  "cross-env": "=7.0.3",
105
105
  "eslint": "^8.42.0",
106
106
  "eslint-config-airbnb-base": "^15.0.0",
107
- "eslint-config-prettier": "=10.0.1",
107
+ "eslint-config-prettier": "=10.1.1",
108
108
  "eslint-plugin-import": "=2.31.0",
109
109
  "eslint-plugin-prettier": "=5.2.3",
110
110
  "expect": "^29.0.3",