Automattic\WooCommerce\Internal\Abilities\REST
RestAbilityFactory::get_output_schema
Get output schema for operation.
Method of the class: RestAbilityFactory{}
No Hooks.
Returns
Array. Output schema array.
Usage
$result = RestAbilityFactory::get_output_schema( $controller, $operation ): array;
- $controller(object) (required)
- REST controller instance.
- $operation(string) (required)
- Operation type.
RestAbilityFactory::get_output_schema() RestAbilityFactory::get output schema code WC 10.7.0
private static function get_output_schema( $controller, string $operation ): array {
if ( method_exists( $controller, 'get_item_schema' ) ) {
$schema = self::sanitize_schema( $controller->get_item_schema() );
if ( 'list' === $operation ) {
// For list operations, return object wrapping array of items.
// This ensures MCP compatibility while maintaining REST structure.
return array(
'type' => 'object',
'properties' => array(
'data' => array(
'type' => 'array',
'items' => $schema,
),
),
);
} elseif ( 'delete' === $operation ) {
// For delete operations, return simple confirmation.
return array(
'type' => 'object',
'properties' => array(
'deleted' => array( 'type' => 'boolean' ),
'previous' => $schema,
),
);
}
// For get, create, update operations.
return $schema;
}
return array( 'type' => 'object' );
}