Commit 7df2c043632 for woocommerce

commit 7df2c0436321a1b3fbeb0152b23fcf2e358966d0
Author: iris-woocommerce[bot] <282076412+iris-woocommerce[bot]@users.noreply.github.com>
Date:   Thu Dec 3 13:24:47 2026 +0000

    Name the field when an unknown nested key in an ability's extension field is refused (#71349)

    * Name the full path when an unknown nested key in an extension field is refused

    Co-authored-by: matticbot <matticbot@users.noreply.github.com>

    * Keep the WordPress refusal when a required key is missing or an anyOf branch has no type

    An unknown key was reported instead of a missing required key when both were
    in an object under an anyOf. A branch without a type was also validated on its
    own, which made WordPress warn about the missing type.

    Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

    * Cover an unknown key in a map under a oneOf in the nested key path test

    Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

    * Name the fix and the accepted keys when an unknown nested key is refused

    Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

    * Use WordPress brackets below the field in the unknown key path

    Name nested keys as extensions.ns.field[key][child], like the other
    WordPress refusals of the same field. Leave out the accepted keys when
    the object also has patternProperties, because the properties list is
    then incomplete. Correct the docblock on how anyOf and oneOf branches
    are followed, and shorten the testdox.

    Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

    * Follow an untyped anyOf branch that has its own anyOf or oneOf

    A branch with no type but with its own anyOf or oneOf now gets its
    unknown key named, such as extensions.probe.dims[tier][b]. Only a branch
    with no type and no anyOf or oneOf still stops the search, because
    validating it again would repeat the WordPress warnings about the
    missing type.

    Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

    * Name the field instead of the full path when an unknown nested key is refused

    WordPress drops the path from this one refusal. Prefixing the field
    covers the gap without walking the value again.

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

    ---------

    Co-authored-by: zaguiini <luis.felipe.zaguini@automattic.com>
    Co-authored-by: matticbot <matticbot@users.noreply.github.com>
    Co-authored-by: Luis Felipe Zaguini <luisfelipezaguini@gmail.com>
    Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>

diff --git a/plugins/woocommerce/changelog/fix-abilities-unknown-nested-key-path b/plugins/woocommerce/changelog/fix-abilities-unknown-nested-key-path
new file mode 100644
index 00000000000..94984f0b15b
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-abilities-unknown-nested-key-path
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+Comment: Extensible abilities (experimental): name the field when an unknown nested key in an extension field is refused.
+
diff --git a/plugins/woocommerce/src/Abilities/ActionableAbility.php b/plugins/woocommerce/src/Abilities/ActionableAbility.php
index a6801b5b77c..4c1cdbbb586 100644
--- a/plugins/woocommerce/src/Abilities/ActionableAbility.php
+++ b/plugins/woocommerce/src/Abilities/ActionableAbility.php
@@ -524,7 +524,8 @@ abstract class ActionableAbility extends Ability {
 					$param = 'extensions.' . $namespace . '.' . $field;
 					$valid = rest_validate_value_from_schema( $value, $args['input_schema'], $param );
 					if ( is_wp_error( $valid ) ) {
-						$refusals[] = ( isset( $args['input_schema']['anyOf'] ) ? self::describe_any_of_refusal( $value, $args['input_schema']['anyOf'], $param ) : null ) ?? $valid->get_error_message();
+						$message    = 'rest_additional_properties_forbidden' === $valid->get_error_code() ? $param . ': ' . $valid->get_error_message() : $valid->get_error_message();
+						$refusals[] = ( isset( $args['input_schema']['anyOf'] ) ? self::describe_any_of_refusal( $value, $args['input_schema']['anyOf'], $param ) : null ) ?? $message;
 					}
 				}
 			}
diff --git a/plugins/woocommerce/tests/php/src/Internal/AbilitiesApi/ExtensibleAbilitiesTest.php b/plugins/woocommerce/tests/php/src/Internal/AbilitiesApi/ExtensibleAbilitiesTest.php
index b10bde69fee..0b706233e41 100644
--- a/plugins/woocommerce/tests/php/src/Internal/AbilitiesApi/ExtensibleAbilitiesTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/AbilitiesApi/ExtensibleAbilitiesTest.php
@@ -2241,6 +2241,48 @@ class ExtensibleAbilitiesTest extends \WC_REST_Unit_Test_Case {
 		$this->assertSame( 'extensions.shared.size is not of type string,null.', $refused->get_data()['message'] );
 	}

+	/**
+	 * @testdox Should name the field when an unknown nested key is refused.
+	 */
+	public function test_an_unknown_nested_key_is_refused_with_its_field(): void {
+		add_action(
+			'woocommerce_extensible_abilities_init',
+			static function () {
+				ExtensibleAbilities::register_field(
+					array(
+						'resource'     => 'product',
+						'namespace'    => 'probe',
+						'field'        => 'dims',
+						'input_schema' => array(
+							'type'       => 'object',
+							'properties' => array(
+								'metal' => array(
+									'type'                 => 'object',
+									'properties'           => array( 'iron' => array( 'type' => 'integer' ) ),
+									'additionalProperties' => false,
+								),
+							),
+						),
+						'set_callback' => '__return_null',
+					)
+				);
+			}
+		);
+		$this->reset_registries();
+		$product = \WC_Helper_Product::create_simple_product();
+
+		$refused = $this->run_ability_response(
+			'woocommerce/product-update',
+			array(
+				'id'         => $product->get_id(),
+				'extensions' => array( 'probe' => array( 'dims' => array( 'metal' => array( 'gold' => 1 ) ) ) ),
+			)
+		);
+
+		$this->assertSame( 400, $refused->get_status() );
+		$this->assertSame( 'extensions.probe.dims: gold is not a valid property of Object.', $refused->get_data()['message'] );
+	}
+
 	/**
 	 * @testdox Should register a field whose input schema is an anyOf of single types, publish it as declared and pass null or a typed value to the set_callback.
 	 */