Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#54484 new defect (bug)

REST API returns (empty) array for Meta but Schema has type object

Reported by: dtrunk90's profile dtrunk90 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.8.2
Component: REST API Keywords:
Focuses: Cc:

Description

When checking http://localhost/wp-json/wp/v2/posts (fresh setup) the meta field is an empty array:

[{"id":1,...,"meta":[],...}]

But the schema (localhost/wp-json/wp/v2/posts?_method=OPTIONS) has type definition object:

{
   ...,
   "schema":{
      "$schema":"http:\/\/json-schema.org\/draft-04\/schema#",
      "title":"post",
      "type":"object",
      "properties":{
         ...,
         "meta":{
            "description":"Metafelder.",
            "type":"object",
            "context":[
               "view",
               "edit"
            ],
            "properties":[
               
            ]
         },
         ...
      },
      ...
   },
   ...
}

Either the schema is wrong and should be array or REST API should not return an empty array

I'm downloading the schema from my local WordPress instance in order to create POJOs and using those with Springs WebClient which results in the following error:

Error: JSON decoding error: Cannot deserialize value of type `com.acme.api.wp.Meta` from Array value (token `JsonToken.START_ARRAY`); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `com.acme.api.wp.Meta` from Array value (token `JsonToken.START_ARRAY`)
 at [Source: UNKNOWN; byte offset: #UNKNOWN] (through reference chain: com.acme.api.wp.Posts["meta"])

Manually changing type from object to array fixes it. But I'm not sure if the schema is wrong or the REST API is returning invalid data.

Change History (2)

#1 @dtrunk90
2 years ago

Still the case for current dev version (5.9)

Version 0, edited 2 years ago by dtrunk90 (next)

#2 @dtrunk90
2 years ago

  • Summary changed from REST API returns (empty) array for Post Meta but Schema has type object to REST API returns (empty) array for Meta but Schema has type object
Note: See TracTickets for help on using tickets.