diff options
author | jenkins-bot <jenkins-bot@gerrit.wikimedia.org> | 2025-01-16 21:03:14 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@wikimedia.org> | 2025-01-16 21:03:14 +0000 |
commit | 2e479834024fcb38df666266ee6a4d5ac998e9ca (patch) | |
tree | 14e991b74352961be52cdca30a55946625a037be /includes/Rest | |
parent | 8fd9549784bc341adbecd94684a5ccf4c9a3a6cd (diff) | |
parent | 8dfcccc720a685448db47d3c202299c1100cb0c1 (diff) | |
download | mediawikicore-2e479834024fcb38df666266ee6a4d5ac998e9ca.tar.gz mediawikicore-2e479834024fcb38df666266ee6a4d5ac998e9ca.zip |
Merge "REST: Content/v1: Validate responses against response schemas in tests"
Diffstat (limited to 'includes/Rest')
-rw-r--r-- | includes/Rest/Handler/EditHandler.php | 12 | ||||
-rw-r--r-- | includes/Rest/Handler/PageSourceHandler.php | 2 | ||||
-rw-r--r-- | includes/Rest/Handler/Schema/ExistingPageHtml.json | 1 | ||||
-rw-r--r-- | includes/Rest/Handler/Schema/ExistingPageSource.json | 46 | ||||
-rw-r--r-- | includes/Rest/Handler/Schema/ExistingRevisionHtml.json | 1 | ||||
-rw-r--r-- | includes/Rest/Handler/Schema/RevisionMetaDataBare.json | 61 | ||||
-rw-r--r-- | includes/Rest/Handler/UpdateHandler.php | 7 | ||||
-rw-r--r-- | includes/Rest/ResponseFactory.php | 2 |
8 files changed, 118 insertions, 14 deletions
diff --git a/includes/Rest/Handler/EditHandler.php b/includes/Rest/Handler/EditHandler.php index 933d0c9a8acb..1757ef0f9540 100644 --- a/includes/Rest/Handler/EditHandler.php +++ b/includes/Rest/Handler/EditHandler.php @@ -158,4 +158,16 @@ abstract class EditHandler extends ActionModuleBasedHandler { } } + protected function generateResponseSpec( string $method ): array { + $spec = parent::generateResponseSpec( $method ); + + $spec['201'][parent::OPENAPI_DESCRIPTION_KEY] = 'OK'; + $spec['201']['content']['application/json']['schema'] = + $spec['200']['content']['application/json']['schema']; + $spec['403'] = [ '$ref' => '#/components/responses/GenericErrorResponse' ]; + $spec['409'] = [ '$ref' => '#/components/responses/GenericErrorResponse' ]; + + return $spec; + } + } diff --git a/includes/Rest/Handler/PageSourceHandler.php b/includes/Rest/Handler/PageSourceHandler.php index 39d28357e352..d0da5d519463 100644 --- a/includes/Rest/Handler/PageSourceHandler.php +++ b/includes/Rest/Handler/PageSourceHandler.php @@ -168,8 +168,6 @@ class PageSourceHandler extends SimpleHandler { } public function getResponseBodySchemaFileName( string $method ): ?string { - // This does not include restbase compatibility mode, which is triggered by request - // headers. Presumably, such callers will look at the RESTBase spec instead. switch ( $this->getConfig()['format'] ) { case 'bare': $schema = 'includes/Rest/Handler/Schema/ExistingPageBare.json'; diff --git a/includes/Rest/Handler/Schema/ExistingPageHtml.json b/includes/Rest/Handler/Schema/ExistingPageHtml.json index f2a81b8277f7..7595acc7d987 100644 --- a/includes/Rest/Handler/Schema/ExistingPageHtml.json +++ b/includes/Rest/Handler/Schema/ExistingPageHtml.json @@ -32,6 +32,7 @@ }, "timestamp": { "type": "string", + "format": "date-time", "description": " Timestamp of the latest revision in ISO 8601 format", "nullable": true } diff --git a/includes/Rest/Handler/Schema/ExistingPageSource.json b/includes/Rest/Handler/Schema/ExistingPageSource.json index 73fafb3b5601..ca8d66c3dc96 100644 --- a/includes/Rest/Handler/Schema/ExistingPageSource.json +++ b/includes/Rest/Handler/Schema/ExistingPageSource.json @@ -32,6 +32,7 @@ }, "timestamp": { "type": "string", + "format": "date-time", "description": " Timestamp of the latest revision", "nullable": true } @@ -58,6 +59,51 @@ "source": { "type": "string", "description": "Latest page content in the format specified by the content_model property" + }, + "page_id": { + "type": "integer", + "description": "Included only if the x-restbase-compat header is used to activate RESTBase compatibility" + }, + "rev": { + "type": "integer", + "description": "Included only if the x-restbase-compat header is used to activate RESTBase compatibility" + + }, + "tid": { + "type": "string", + "description": "Included only if the x-restbase-compat header is used to activate RESTBase compatibility" + }, + "namespace": { + "type": "integer", + "description": "Included only if the x-restbase-compat header is used to activate RESTBase compatibility" + }, + "user_id": { + "type": "integer", + "description": "Included only if the x-restbase-compat header is used to activate RESTBase compatibility" + }, + "user_text": { + "type": "string", + "description": "Included only if the x-restbase-compat header is used to activate RESTBase compatibility" + }, + "tags": { + "type": "array", + "description": "Included only if the x-restbase-compat header is used to activate RESTBase compatibility" + }, + "restrictions": { + "type": "array", + "description": "Included only if the x-restbase-compat header is used to activate RESTBase compatibility" + }, + "page_language": { + "type": "string", + "description": "Included only if the x-restbase-compat header is used to activate RESTBase compatibility" + }, + "redirect": { + "type": "boolean", + "description": "Included only if the x-restbase-compat header is used to activate RESTBase compatibility" + }, + "comment": { + "type": "string", + "description": "Included only if the x-restbase-compat header is used to activate RESTBase compatibility" } } } diff --git a/includes/Rest/Handler/Schema/ExistingRevisionHtml.json b/includes/Rest/Handler/Schema/ExistingRevisionHtml.json index 2c5dfa24e62a..96f8c25c3101 100644 --- a/includes/Rest/Handler/Schema/ExistingRevisionHtml.json +++ b/includes/Rest/Handler/Schema/ExistingRevisionHtml.json @@ -28,6 +28,7 @@ }, "timestamp": { "type": "string", + "format": "date-time", "description": "Revision timestamp" }, "content_model": { diff --git a/includes/Rest/Handler/Schema/RevisionMetaDataBare.json b/includes/Rest/Handler/Schema/RevisionMetaDataBare.json index 17db0f336ba8..09aac9cba74f 100644 --- a/includes/Rest/Handler/Schema/RevisionMetaDataBare.json +++ b/includes/Rest/Handler/Schema/RevisionMetaDataBare.json @@ -1,17 +1,7 @@ { "description": "revision meta-data", "required": [ - "id", - "size", - "minor", - "timestamp", - "content_model", - "page", - "license", - "user", - "comment", - "delta", - "html_url" + "timestamp" ], "properties": { "id": { @@ -38,6 +28,7 @@ }, "timestamp": { "type": "string", + "format": "date-time", "description": "Revision timestamp" }, "content_model": { @@ -106,6 +97,54 @@ "html_url": { "type": "string", "description": "Url to retrieve the revision content in html format" + }, + "html": { + "type": "string", + "description": "Included only if the x-restbase-compat header is used to activate RESTBase compatibility" + }, + "title": { + "type": "string", + "description": "Revision Title. Included only if the x-restbase-compat header is used to activate RESTBase compatibility" + }, + "page_id": { + "type": "integer", + "description": "Included only if the x-restbase-compat header is used to activate RESTBase compatibility" + }, + "rev": { + "type": "integer", + "description": "Included only if the x-restbase-compat header is used to activate RESTBase compatibility" + }, + "tid": { + "type": "string", + "description": "Included only if the x-restbase-compat header is used to activate RESTBase compatibility" + }, + "namespace": { + "type": "integer", + "description": "Included only if the x-restbase-compat header is used to activate RESTBase compatibility" + }, + "user_id": { + "type": "integer", + "description": "Included only if the x-restbase-compat header is used to activate RESTBase compatibility" + }, + "user_text": { + "type": "string", + "description": "Included only if the x-restbase-compat header is used to activate RESTBase compatibility" + }, + "tags": { + "type": "array", + "description": "Included only if the x-restbase-compat header is used to activate RESTBase compatibility" + }, + "restrictions": { + "type": "array", + "description": "Included only if the x-restbase-compat header is used to activate RESTBase compatibility" + }, + "page_language": { + "type": "string", + "description": "Included only if the x-restbase-compat header is used to activate RESTBase compatibility" + }, + "redirect": { + "type": "boolean", + "description": "Included only if the x-restbase-compat header is used to activate RESTBase compatibility" } } } diff --git a/includes/Rest/Handler/UpdateHandler.php b/includes/Rest/Handler/UpdateHandler.php index 67359a3942b3..a6b82814eed7 100644 --- a/includes/Rest/Handler/UpdateHandler.php +++ b/includes/Rest/Handler/UpdateHandler.php @@ -173,6 +173,13 @@ class UpdateHandler extends EditHandler { parent::throwHttpExceptionForActionModuleError( $msg, $statusCode ); } + protected function generateResponseSpec( string $method ): array { + $spec = parent::generateResponseSpec( $method ); + + $spec['404'] = [ '$ref' => '#/components/responses/GenericErrorResponse' ]; + return $spec; + } + /** * Returns an associative array to be used in the response in the event of edit conflicts. * diff --git a/includes/Rest/ResponseFactory.php b/includes/Rest/ResponseFactory.php index bff037d36856..145ab7287a6a 100644 --- a/includes/Rest/ResponseFactory.php +++ b/includes/Rest/ResponseFactory.php @@ -401,7 +401,7 @@ class ResponseFactory { 'schemas' => [ 'GenericErrorResponseModel' => [ 'description' => 'Generic error response body', - 'required' => [ 'httpCode', 'httpMessage' ], + 'required' => [ 'httpCode' ], 'properties' => [ 'httpCode' => [ 'type' => 'integer' |