Skip to content

Tests: Cover how wp_prepare_json_schema_for_client() encodes defaults - #14068

Open
gziolo wants to merge 1 commit into
WordPress:trunkfrom
gziolo:add/json-schema-client-default-tests
Open

gziolo wants to merge 1 commit into
WordPress:trunkfrom
gziolo:add/json-schema-client-default-tests

Conversation

@gziolo

@gziolo gziolo commented Oct 7, 2026

Copy link
Copy Markdown
Member

What?

Adds a test for how wp_prepare_json_schema_for_client() handles the default of a schema. It uses a data provider with three cases:

  • An empty default on an object schema is encoded as {}.
  • A non-empty default on an object schema stays the same.
  • An empty default on an array schema stays [].

Why?

In PHP, an empty array is encoded as [] in JSON. For an object schema, clients expect {}. The helper already fixes this, but only a nested property was tested before, not the root schema.

Abilities rely on this. They can use 'default' => array() in an object input schema, and both the REST API and the AI client still send {}. This came up in #12141.

Testing

npm run test:php -- --filter test_wp_prepare_json_schema_for_client_encodes_default

Trac ticket: https://core.trac.wordpress.org/ticket/64955

Use of AI Tools

The test and this description were drafted with Claude Code and reviewed by me.

🤖 Generated with Claude Code

An empty `default` on an object schema is sent to clients as `{}`.
Other defaults stay unchanged.

See #64955.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props gziolo.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@gziolo gziolo self-assigned this Oct 7, 2026
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.

1 participant