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

Conversation

eastcoastcoder
Copy link

Previously all array and object types defaulted to strings. This should instead look at the array/object item's type and (if the item is an object) all the properties within that item. I've tested it against two levels deep of arrays of objects and it seems to work correctly now.

Copy link
Owner

@starfishmod starfishmod left a comment

Choose a reason for hiding this comment

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

Hey thanks! :)
I have added some suggestions to this before it should be merged

lib/class-wp-rest-swagger-controller.php Outdated Show resolved Hide resolved
lib/class-wp-rest-swagger-controller.php Outdated Show resolved Hide resolved
lib/class-wp-rest-swagger-controller.php Outdated Show resolved Hide resolved
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.

'properties'=> $prop['items']['properties']
);
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants