diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php index b0ac65a6476aa..767917d6f6fd0 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php @@ -802,7 +802,16 @@ public function get_item_schema() { 'app_id' => array( 'description' => __( 'A UUID provided by the application to uniquely identify it. It is recommended to use an UUID v5 with the URL or DNS namespace.' ), 'type' => 'string', - 'format' => 'uuid', + 'oneOf' => array( + array( + 'type' => 'string', + 'format' => 'uuid', + ), + array( + 'type' => 'string', + 'enum' => array( '' ), + ), + ), 'context' => array( 'view', 'edit', 'embed' ), ), 'name' => array( diff --git a/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php b/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php index 7a06bb006dffe..9b2eafcc9b956 100644 --- a/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php +++ b/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php @@ -847,6 +847,67 @@ public function test_prepare_item() { $this->check_response( $prepared->get_data(), $item ); } + /** + * @ticket 53692 + */ + public function test_app_id_schema() { + $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users/me/application-passwords' ); + $response = rest_get_server()->dispatch( $request ); + $data = $response->get_data(); + $properties = $data['schema']['properties']; + + $this->assertArrayHasKey( 'app_id', $properties ); + $this->assertSame( 'string', $properties['app_id']['type'] ); + $this->assertCount( 2, $properties['app_id']['oneOf'] ); + + $this->assertSame( 'string', $properties['app_id']['oneOf'][0]['type'] ); + $this->assertSame( 'uuid', $properties['app_id']['oneOf'][0]['format'] ); + + $this->assertSame( 'string', $properties['app_id']['oneOf'][1]['type'] ); + $this->assertSame( array( '' ), $properties['app_id']['oneOf'][1]['enum'] ); + } + + /** + * @ticket 53692 + */ + public function test_create_item_with_empty_app_id() { + wp_set_current_user( self::$admin ); + + $request = new WP_REST_Request( 'POST', '/wp/v2/users/' . self::$admin . '/application-passwords' ); + $request->set_body_params( + array( + 'name' => 'Test', + 'app_id' => '', + ) + ); + + $response = rest_get_server()->dispatch( $request ); + $this->assertSame( 201, $response->get_status() ); + $data = $response->get_data(); + $this->assertSame( '', $data['app_id'] ); + } + + /** + * @ticket 53692 + */ + public function test_create_item_with_uuid_app_id() { + wp_set_current_user( self::$admin ); + + $uuid = wp_generate_uuid4(); + $request = new WP_REST_Request( 'POST', '/wp/v2/users/' . self::$admin . '/application-passwords' ); + $request->set_body_params( + array( + 'name' => 'Test', + 'app_id' => $uuid, + ) + ); + + $response = rest_get_server()->dispatch( $request ); + $this->assertSame( 201, $response->get_status() ); + $data = $response->get_data(); + $this->assertSame( $uuid, $data['app_id'] ); + } + /** * Checks the password response matches the expected format. * diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index 448548aab0c07..8c2cf0eca53d4 100644 --- a/tests/qunit/fixtures/wp-api-generated.js +++ b/tests/qunit/fixtures/wp-api-generated.js @@ -10028,7 +10028,16 @@ mockedApiResponse.Schema = { "app_id": { "description": "A UUID provided by the application to uniquely identify it. It is recommended to use an UUID v5 with the URL or DNS namespace.", "type": "string", - "format": "uuid", + "oneOf": [ + { + "type": "string", + "format": "uuid", + }, + { + "type": "string", + "enum": [ "" ], + }, + ], "required": false }, "name": { @@ -10112,7 +10121,16 @@ mockedApiResponse.Schema = { "app_id": { "description": "A UUID provided by the application to uniquely identify it. It is recommended to use an UUID v5 with the URL or DNS namespace.", "type": "string", - "format": "uuid", + "oneOf": [ + { + "type": "string", + "format": "uuid", + }, + { + "type": "string", + "enum": [ "" ], + }, + ], "required": false }, "name": {