From 0e122af1b572337aaf6390ba0d84e563eaa452fa Mon Sep 17 00:00:00 2001 From: Ethan Richardson Date: Thu, 30 Jul 2020 13:45:37 -0400 Subject: [PATCH 1/3] Fix array types --- lib/class-wp-rest-swagger-controller.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/class-wp-rest-swagger-controller.php b/lib/class-wp-rest-swagger-controller.php index 72c0d68..ce4811c 100644 --- a/lib/class-wp-rest-swagger-controller.php +++ b/lib/class-wp-rest-swagger-controller.php @@ -248,9 +248,16 @@ function ($matches) use (&$defaultidParams){ if(!empty($pdetails['type'])){ if($pdetails['type']=='array'){ $parameter['type']=$pdetails['type']; - $parameter['items']=array('type'=>'string'); + $parameter['items']=array( + 'type'=> $pdetails['items']['type'], + 'properties'=> $pdetails['items']['properties'] + ); }elseif($pdetails['type']=='object'){ - $parameter['type']='string'; + $parameter['type']=$pdetails['type']; + $parameter['items']=array( + 'type'=> $pdetails['items']['type'], + 'properties'=> $pdetails['items']['properties'] + ); }elseif($pdetails['type']=='date-time'){ $parameter['type']='string'; @@ -344,7 +351,10 @@ private function schemaIntoDefinition($schema){ if($prop['type']=='array'){ - $prop['items']=array('type'=>'string'); + $prop['items'] = array( + 'type'=> $prop['items']['type'], + 'properties'=> $prop['items']['properties'] + ); }else if($prop['type']=='date-time'){ $prop['type']='string'; From b3c3dd13c0c8521109c6e4e8d922d256db7cc67c Mon Sep 17 00:00:00 2001 From: Ethan Richardson Date: Thu, 30 Jul 2020 22:28:16 -0400 Subject: [PATCH 2/3] guards against missing keys --- lib/class-wp-rest-swagger-controller.php | 29 ++++++++++++------------ 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/class-wp-rest-swagger-controller.php b/lib/class-wp-rest-swagger-controller.php index ce4811c..9a0c946 100644 --- a/lib/class-wp-rest-swagger-controller.php +++ b/lib/class-wp-rest-swagger-controller.php @@ -247,18 +247,20 @@ function ($matches) use (&$defaultidParams){ } if(!empty($pdetails['type'])){ if($pdetails['type']=='array'){ - $parameter['type']=$pdetails['type']; - $parameter['items']=array( - 'type'=> $pdetails['items']['type'], - 'properties'=> $pdetails['items']['properties'] - ); + if($pdetails['items']) { + $parameter['items']=$pdetails['items']; + } else { + $parameter['items']=array('type'=>'string'); + } }elseif($pdetails['type']=='object'){ $parameter['type']=$pdetails['type']; - $parameter['items']=array( - 'type'=> $pdetails['items']['type'], - 'properties'=> $pdetails['items']['properties'] - ); - + if($pdetails['items']) { + $parameter['items']=$pdetails['items']; + }else if ($pdetails['properties']) { + $parameter['properties']=$pdetails['properties']['rendered']; + }else { + $parameter['items']=array('type'=>'string'); + } }elseif($pdetails['type']=='date-time'){ $parameter['type']='string'; $parameter['format']='date-time'; @@ -350,11 +352,8 @@ private function schemaIntoDefinition($schema){ //-- - if($prop['type']=='array'){ - $prop['items'] = array( - 'type'=> $prop['items']['type'], - 'properties'=> $prop['items']['properties'] - ); + if($prop['type']=='array' && !$prop['items']){ + $prop['items']=array('type'=>'string'); }else if($prop['type']=='date-time'){ $prop['type']='string'; From 440e2f63bf1ea24c69bc388173a167c6eb835469 Mon Sep 17 00:00:00 2001 From: Ethan Richardson Date: Tue, 8 Sep 2020 08:19:39 -0400 Subject: [PATCH 3/3] more guards --- lib/class-wp-rest-swagger-controller.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/class-wp-rest-swagger-controller.php b/lib/class-wp-rest-swagger-controller.php index 9a0c946..bca1579 100644 --- a/lib/class-wp-rest-swagger-controller.php +++ b/lib/class-wp-rest-swagger-controller.php @@ -247,6 +247,7 @@ function ($matches) use (&$defaultidParams){ } if(!empty($pdetails['type'])){ if($pdetails['type']=='array'){ + $parameter['type']=$pdetails['type']; if($pdetails['items']) { $parameter['items']=$pdetails['items']; } else { @@ -254,12 +255,10 @@ function ($matches) use (&$defaultidParams){ } }elseif($pdetails['type']=='object'){ $parameter['type']=$pdetails['type']; - if($pdetails['items']) { - $parameter['items']=$pdetails['items']; - }else if ($pdetails['properties']) { - $parameter['properties']=$pdetails['properties']['rendered']; + if (isset($pdetails['properties'])) { + $parameter['properties']=$pdetails['properties']; }else { - $parameter['items']=array('type'=>'string'); + $parameter['properties']=array('type'=>'string'); } }elseif($pdetails['type']=='date-time'){ $parameter['type']='string'; @@ -351,13 +350,14 @@ private function schemaIntoDefinition($schema){ } //-- - - if($prop['type']=='array' && !$prop['items']){ - $prop['items']=array('type'=>'string'); - }else - if($prop['type']=='date-time'){ - $prop['type']='string'; - $prop['format']='date-time'; + if (array_key_exists('type', $prop)) { + if($prop['type']=='array' && !array_key_exists('items', $prop)){ + $prop['items']=array('type'=>'string'); + }else + if($prop['type']=='date-time'){ + $prop['type']='string'; + $prop['format']='date-time'; + } } // else if(!empty($prop['context']) && $prop['format']!='date-time'){ // //$prop['enum']=$prop['context'];