@@ -829,23 +829,28 @@ public function test_filter_by_namespace_still_respects_show_in_rest(): void {
829829 }
830830
831831 /**
832- * Test that WordPress-internal schema keywords are stripped from ability schemas in REST response.
832+ * Test that schema keywords outside the allow-list are stripped from ability schemas in REST response.
833833 *
834834 * @ticket 65035
835835 */
836- public function test_internal_schema_keywords_stripped_from_response (): void {
836+ public function test_unsupported_schema_keywords_stripped_from_response (): void {
837837 $ this ->register_test_ability (
838- 'test/with-internal -keywords ' ,
838+ 'test/with-unsupported -keywords ' ,
839839 array (
840- 'label ' => 'Test Internal Keywords ' ,
841- 'description ' => 'Tests stripping of internal schema keywords ' ,
840+ 'label ' => 'Test Unsupported Keywords ' ,
841+ 'description ' => 'Tests stripping of unsupported schema keywords ' ,
842842 'category ' => 'general ' ,
843843 'input_schema ' => array (
844844 'type ' => 'object ' ,
845+ 'required ' => array ( 'content ' ),
845846 'properties ' => array (
846847 'content ' => array (
847848 'type ' => 'string ' ,
848849 'description ' => 'The content value. ' ,
850+ 'example ' => 'example content ' ,
851+ 'examples ' => array ( 'example content ' ),
852+ 'context ' => array ( 'view ' , 'edit ' , 'embed ' ),
853+ 'readonly ' => true ,
849854 'sanitize_callback ' => 'sanitize_text_field ' ,
850855 'validate_callback ' => 'is_string ' ,
851856 'arg_options ' => array ( 'sanitize_callback ' => 'wp_kses_post ' ),
@@ -854,7 +859,13 @@ public function test_internal_schema_keywords_stripped_from_response(): void {
854859 ),
855860 'output_schema ' => array (
856861 'type ' => 'string ' ,
862+ 'example ' => 'example output ' ,
863+ 'examples ' => array ( 'example output ' ),
864+ 'context ' => array ( 'view ' , 'edit ' , 'embed ' ),
865+ 'readonly ' => true ,
857866 'sanitize_callback ' => 'sanitize_text_field ' ,
867+ 'validate_callback ' => 'is_string ' ,
868+ 'arg_options ' => array ( 'sanitize_callback ' => 'wp_kses_post ' ),
858869 ),
859870 'execute_callback ' => static function ( $ input ) {
860871 return $ input ['content ' ];
@@ -864,7 +875,7 @@ public function test_internal_schema_keywords_stripped_from_response(): void {
864875 )
865876 );
866877
867- $ request = new WP_REST_Request ( 'GET ' , '/wp-abilities/v1/abilities/test/with-internal -keywords ' );
878+ $ request = new WP_REST_Request ( 'GET ' , '/wp-abilities/v1/abilities/test/with-unsupported -keywords ' );
868879 $ response = $ this ->server ->dispatch ( $ request );
869880
870881 $ this ->assertSame ( 200 , $ response ->get_status () );
@@ -875,18 +886,29 @@ public function test_internal_schema_keywords_stripped_from_response(): void {
875886 $ this ->assertArrayHasKey ( 'content ' , $ data ['input_schema ' ]['properties ' ] );
876887 $ this ->assertArrayHasKey ( 'output_schema ' , $ data );
877888
878- // Verify internal keywords are stripped from input_schema properties.
889+ // Verify unsupported schema keywords are stripped from input_schema properties.
879890 $ content_schema = $ data ['input_schema ' ]['properties ' ]['content ' ];
880891 $ this ->assertArrayNotHasKey ( 'sanitize_callback ' , $ content_schema );
881892 $ this ->assertArrayNotHasKey ( 'validate_callback ' , $ content_schema );
882893 $ this ->assertArrayNotHasKey ( 'arg_options ' , $ content_schema );
894+ $ this ->assertArrayNotHasKey ( 'example ' , $ content_schema );
895+ $ this ->assertArrayNotHasKey ( 'examples ' , $ content_schema );
896+ $ this ->assertArrayNotHasKey ( 'context ' , $ content_schema );
897+ $ this ->assertArrayNotHasKey ( 'readonly ' , $ content_schema );
883898
884899 // Verify valid JSON Schema keywords are preserved.
885900 $ this ->assertSame ( 'string ' , $ content_schema ['type ' ] );
886901 $ this ->assertSame ( 'The content value. ' , $ content_schema ['description ' ] );
902+ $ this ->assertSame ( array ( 'content ' ), $ data ['input_schema ' ]['required ' ] );
887903
888904 // Verify internal keywords are stripped from output_schema.
889905 $ this ->assertArrayNotHasKey ( 'sanitize_callback ' , $ data ['output_schema ' ] );
906+ $ this ->assertArrayNotHasKey ( 'validate_callback ' , $ data ['output_schema ' ] );
907+ $ this ->assertArrayNotHasKey ( 'arg_options ' , $ data ['output_schema ' ] );
908+ $ this ->assertArrayNotHasKey ( 'example ' , $ data ['output_schema ' ] );
909+ $ this ->assertArrayNotHasKey ( 'examples ' , $ data ['output_schema ' ] );
910+ $ this ->assertArrayNotHasKey ( 'context ' , $ data ['output_schema ' ] );
911+ $ this ->assertArrayNotHasKey ( 'readonly ' , $ data ['output_schema ' ] );
890912 $ this ->assertSame ( 'string ' , $ data ['output_schema ' ]['type ' ] );
891913 }
892914
@@ -947,19 +969,20 @@ public function test_nested_empty_object_schema_defaults_prepared_for_response()
947969 }
948970
949971 /**
950- * Test that internal schema keywords are stripped from nested sub-schema locations.
972+ * Test that schema keywords outside the allow-list are stripped from nested sub-schema locations.
951973 *
952974 * @ticket 64098
953975 */
954- public function test_internal_schema_keywords_stripped_from_nested_sub_schemas (): void {
976+ public function test_unsupported_schema_keywords_stripped_from_nested_sub_schemas (): void {
955977 $ this ->register_test_ability (
956- 'test/nested-internal -keywords ' ,
978+ 'test/nested-unsupported -keywords ' ,
957979 array (
958- 'label ' => 'Test Nested Keywords ' ,
980+ 'label ' => 'Test Nested Unsupported Keywords ' ,
959981 'description ' => 'Tests stripping from all sub-schema locations ' ,
960982 'category ' => 'general ' ,
961983 'input_schema ' => array (
962984 'type ' => 'object ' ,
985+ '$ref ' => '#/definitions/address ' ,
963986 'anyOf ' => array (
964987 array (
965988 'type ' => 'object ' ,
@@ -1053,14 +1076,15 @@ public function test_internal_schema_keywords_stripped_from_nested_sub_schemas()
10531076 )
10541077 );
10551078
1056- $ request = new WP_REST_Request ( 'GET ' , '/wp-abilities/v1/abilities/test/nested-internal -keywords ' );
1079+ $ request = new WP_REST_Request ( 'GET ' , '/wp-abilities/v1/abilities/test/nested-unsupported -keywords ' );
10571080 $ response = $ this ->server ->dispatch ( $ request );
10581081
10591082 $ this ->assertSame ( 200 , $ response ->get_status () );
10601083
10611084 $ data = $ response ->get_data ();
10621085
10631086 // Verify internal keywords are stripped from anyOf sub-schemas.
1087+ $ this ->assertSame ( '#/definitions/address ' , $ data ['input_schema ' ]['$ref ' ] );
10641088 $ this ->assertArrayHasKey ( 'anyOf ' , $ data ['input_schema ' ] );
10651089 $ this ->assertArrayNotHasKey ( 'sanitize_callback ' , $ data ['input_schema ' ]['anyOf ' ][0 ] );
10661090 $ this ->assertSame ( 'object ' , $ data ['input_schema ' ]['anyOf ' ][0 ]['type ' ] );
0 commit comments