@@ -20,11 +20,16 @@ import { serialize as serializeCookie } from '../helpers/cookie.js';
2020
2121const arrayOrEmpty = ( ar ) => ( Array . isArray ( ar ) ? ar : [ ] ) ;
2222
23- const findObjectSchema = ( schema , { recurse = true , depth = 1 } = { } ) => {
23+ const findObjectOrArraySchema = ( schema , { recurse = true , depth = 1 } = { } ) => {
2424 if ( ! isPlainObject ( schema ) ) return undefined ;
2525
26- // check if the schema is an object type
27- if ( schema . type === 'object' || ( Array . isArray ( schema . type ) && schema . type . includes ( 'object' ) ) ) {
26+ // check if the schema is an object or array type
27+ if (
28+ schema . type === 'object' ||
29+ schema . type === 'array' ||
30+ ( Array . isArray ( schema . type ) &&
31+ ( schema . type . includes ( 'object' ) || schema . type . includes ( 'array' ) ) )
32+ ) {
2833 return schema ;
2934 }
3035
@@ -33,14 +38,18 @@ const findObjectSchema = (schema, { recurse = true, depth = 1 } = {}) => {
3338 if ( recurse ) {
3439 // traverse oneOf keyword first
3540 const oneOfResult = Array . isArray ( schema . oneOf )
36- ? schema . oneOf . find ( ( subschema ) => findObjectSchema ( subschema , { recurse, depth : depth + 1 } ) )
41+ ? schema . oneOf . find ( ( subschema ) =>
42+ findObjectOrArraySchema ( subschema , { recurse, depth : depth + 1 } )
43+ )
3744 : undefined ;
3845
3946 if ( oneOfResult ) return oneOfResult ;
4047
4148 // traverse anyOf keyword second
4249 const anyOfResult = Array . isArray ( schema . anyOf )
43- ? schema . anyOf . find ( ( subschema ) => findObjectSchema ( subschema , { recurse, depth : depth + 1 } ) )
50+ ? schema . anyOf . find ( ( subschema ) =>
51+ findObjectOrArraySchema ( subschema , { recurse, depth : depth + 1 } )
52+ )
4453 : undefined ;
4554
4655 if ( anyOfResult ) return anyOfResult ;
@@ -49,18 +58,18 @@ const findObjectSchema = (schema, { recurse = true, depth = 1 } = {}) => {
4958 return undefined ;
5059} ;
5160
52- const parseJsonObject = ( { value, silentFail = false } ) => {
61+ const parseJsonObjectOrArray = ( { value, silentFail = false } ) => {
5362 try {
5463 const parsedValue = JSON . parse ( value ) ;
55- if ( typeof parsedValue === 'object' ) {
64+ if ( isPlainObject ( parsedValue ) || Array . isArray ( parsedValue ) ) {
5665 return parsedValue ;
5766 }
5867 if ( ! silentFail ) {
59- throw new Error ( 'Expected JSON serialized object' ) ;
68+ throw new Error ( 'Expected JSON serialized object or array ' ) ;
6069 }
6170 } catch {
6271 if ( ! silentFail ) {
63- throw new Error ( 'Could not parse object parameter value string as JSON Object' ) ;
72+ throw new Error ( 'Could not parse parameter value string as JSON Object or JSON Array ' ) ;
6473 }
6574 }
6675 return value ;
@@ -303,10 +312,23 @@ export function buildRequest(options) {
303312 }
304313
305314 if ( specIsOAS3 && typeof value === 'string' ) {
306- if ( has ( 'type' , parameter . schema ) && findObjectSchema ( parameter . schema , { recurse : false } ) ) {
307- value = parseJsonObject ( { value, silentFail : false } ) ;
308- } else if ( findObjectSchema ( parameter . schema , { recurse : true } ) ) {
309- value = parseJsonObject ( { value, silentFail : true } ) ;
315+ if (
316+ has ( 'type' , parameter . schema ) &&
317+ typeof parameter . schema . type === 'string' &&
318+ findObjectOrArraySchema ( parameter . schema , { recurse : false } )
319+ ) {
320+ value = parseJsonObjectOrArray ( { value, silentFail : false } ) ;
321+ } else if (
322+ has ( 'type' , parameter . schema ) &&
323+ Array . isArray ( parameter . schema . type ) &&
324+ findObjectOrArraySchema ( parameter . schema , { recurse : false } )
325+ ) {
326+ value = parseJsonObjectOrArray ( { value, silentFail : true } ) ;
327+ } else if (
328+ ! has ( 'type' , parameter . schema ) &&
329+ findObjectOrArraySchema ( parameter . schema , { recurse : true } )
330+ ) {
331+ value = parseJsonObjectOrArray ( { value, silentFail : true } ) ;
310332 }
311333 }
312334
0 commit comments