After some testing in WordPress v6.0.1, it seemed that:
-
We need to set the (default/initial)
type
of thedata.items
tonull
instead ofobject
. (and yes, the type must be set, or else the API response would be invalidated with many “undefined index” notices) -
For each item, i.e. an array in the
oneOf
oranyOf
, set thetype
toobject
.
So your data
schema should look like this, but I purposely used anyOf
(see explanation below):
'data' => array(
'type' => 'array',
'items' => array(
'type' => null,
'anyOf' => array(
array(
'type' => 'object',
'properties' => array( ... ),
'title' => 'Data única',
),
array(
'type' => 'object',
'properties' => array( ... ),
'title' => 'Data corrente',
),
), // end anyOf
), // end items
), // end data
And the reason why I did not use oneOf
, is because it caused an error with the code rest_one_of_multiple_matches
and the message meta.datas[data][0] matches Data única and Data corrente, but should match only one
.
- You could avoid that issue by using unique schemas, e.g. add
enum
to thedia
‘s schema or change thehora_inicio
‘stype
tonumber
, but that is up to you to decide.