Open thefrosty opened 3 years ago
Hm, is there anything else on the install? The problem is that the default value for the status
parameter doesn't pass strict type checking. But the Middleware is supposed to only validate the passed parameters, not the default values. https://github.com/iron-bound-designs/wp-rest-api-schema-validator/blob/c5452e3ae972a13a1581a219c96c4cf1c81d5e60/src/Middleware.php#L347
TBH though, I've never used this with wp/v2
as the namespace, since the Core REST API schemas and endpoints aren't 100% compatible with JSON Schema. I've just used this for endpoints that I have complete control over.
In the Schema it's a string, but in the endpoints GET args, it's an array. Which seems fine buy the Middleware is blocking the request above, with nothing being passed.
TBH though, I've never used this with wp/v2 as the namespace, since the Core REST API schemas and endpoints aren't 100% compatible with JSON Schema. I've just used this for endpoints that I have complete control over.
Thanks, just thought I would drop a note. I will continue to look into it and see if I can come up with a solution (until we move out of the wp/v2 namespace)
In the Schema it's a string, but in the endpoints GET args, it's an array. Which seems fine buy the Middleware is blocking the request above, with nothing being passed.
Right, but it's the default value in the collection params that is a string. https://github.com/WordPress/wordpress-develop/blob/953e1c5f8313a89d4d3b99ab5996b4660045c976/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L2847
Really, we should make that [ 'publish' ]
.
Quick fix:
<?php
$post_types = \get_post_types();
$fixQueryParams = static function (array $query_params): array {
if (
isset($query_params['status']) &&
(isset($query_params['status']['type']) && \strcasecmp($query_params['status']['type'], 'array') === 0) &&
(isset($query_params['status']['default']) && \gettype($query_params['status']['default']) !== 'array')
) {
$query_params['status']['default'] = (array)$query_params['status']['default'];
}
return $query_params;
};
\array_walk(
$post_types,
fn(string $post_type): bool => \add_filter("rest_{$post_type}_collection_params", $fixQueryParams)
);
Running a curl on my local WordPress install:
Returns:
I could send the OPTIONS request since I do see
status
listed twice, but they are both core fields. 🤔 Curious if it's a core issue or something else.