Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix array/object types #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions lib/class-wp-rest-swagger-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,20 @@ function ($matches) use (&$defaultidParams){
}
if(!empty($pdetails['type'])){
if($pdetails['type']=='array'){
$parameter['type']=$pdetails['type'];
$parameter['items']=array('type'=>'string');
if($pdetails['items']) {
$parameter['items']=$pdetails['items'];
} else {
$parameter['items']=array('type'=>'string');
}
}elseif($pdetails['type']=='object'){
$parameter['type']='string';

$parameter['type']=$pdetails['type'];
if($pdetails['items']) {
$parameter['items']=$pdetails['items'];
}else if ($pdetails['properties']) {
$parameter['properties']=$pdetails['properties']['rendered'];
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this make sense to you? I see properties.raw and properties.rendered on some woocommerce endpoints. I just decided to keep the rendered as there appears to be more information. Works for my cases.

}else {
$parameter['items']=array('type'=>'string');
}
}elseif($pdetails['type']=='date-time'){
$parameter['type']='string';
$parameter['format']='date-time';
Expand Down Expand Up @@ -343,7 +352,7 @@ private function schemaIntoDefinition($schema){
//--


if($prop['type']=='array'){
if($prop['type']=='array' && !$prop['items']){
$prop['items']=array('type'=>'string');
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed I was effectively assigning this property to itself...the property items are already set, they were just overriding themselves to string. This works as a fallback in this manner I believe.

}else
if($prop['type']=='date-time'){
Expand Down