aboutsummaryrefslogtreecommitdiffstats
path: root/includes/Rest
diff options
context:
space:
mode:
authorAtieno <pnjira@wikimedia.org>2024-11-19 18:47:32 +0300
committerAtieno <pnjira@wikimedia.org>2025-01-15 18:21:44 +0300
commit8dfcccc720a685448db47d3c202299c1100cb0c1 (patch)
tree22059a1e5733f80db9c367dca5c47f96430ac8d1 /includes/Rest
parentd039171603ccea5d0fbdc35bed5712485312dec6 (diff)
downloadmediawikicore-8dfcccc720a685448db47d3c202299c1100cb0c1.tar.gz
mediawikicore-8dfcccc720a685448db47d3c202299c1100cb0c1.zip
REST: Content/v1: Validate responses against response schemas in tests
Bug: T376607 Change-Id: I837b0a8471b8a2c8675d33852406d3ba4ce4ae05
Diffstat (limited to 'includes/Rest')
-rw-r--r--includes/Rest/Handler/EditHandler.php12
-rw-r--r--includes/Rest/Handler/PageSourceHandler.php2
-rw-r--r--includes/Rest/Handler/Schema/ExistingPageHtml.json1
-rw-r--r--includes/Rest/Handler/Schema/ExistingPageSource.json46
-rw-r--r--includes/Rest/Handler/Schema/ExistingRevisionHtml.json1
-rw-r--r--includes/Rest/Handler/Schema/RevisionMetaDataBare.json61
-rw-r--r--includes/Rest/Handler/UpdateHandler.php7
-rw-r--r--includes/Rest/ResponseFactory.php2
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'