Define and store MediaWiki REST API ‘page’ endpoint responses as JSON schemas

Bug: T375530
Change-Id: I4193b9be4516717c7ce423131370a7d0b6ea8962
This commit is contained in:
Wendy Quarshie 2024-10-16 11:27:35 +00:00 committed by Reedy
parent 14b1f8b88f
commit c192133daf
5 changed files with 123 additions and 0 deletions

View file

@ -110,4 +110,13 @@ class CreationHandler extends EditHandler {
$response->setHeader( 'Location', $url );
}
/**
* This method specifies the JSON schema file for the response
* body when creating a new page.
*
* @return ?string The file path to the NewPage JSON schema.
*/
public function getResponseBodySchemaFileName( string $method ): ?string {
return 'includes/Rest/Handler/Schema/NewPage.json';
}
}

View file

@ -166,4 +166,13 @@ class PageSourceHandler extends SimpleHandler {
protected function hasRepresentation() {
return $this->contentHelper->hasContent();
}
/**
* This method specifies the JSON schema file for the response body
*
* @return ?string The file path to the ExistingPage JSON schema.
*/
public function getResponseBodySchemaFileName( string $method ): ?string {
return 'includes/Rest/Handler/Schema/ExistingPage.json';
}
}

View file

@ -0,0 +1,61 @@
{
"description": "Schema for wiki pages.",
"required": [
"id",
"key",
"title",
"latest",
"content_model",
"license"
],
"properties": {
"id": {
"type": "integer",
"description": "Page identifier."
},
"key": {
"type": "string",
"description": "Page title in URL-friendly format"
},
"title": {
"type": "string",
"description": "Page title"
},
"latest": {
"type": "object",
"description": "Information about the latest revision",
"properties": {
"id": {
"type": "integer",
"description": "Revision identifier for the latest revision"
},
"timestamp": {
"type": "string",
"description": " Timestamp of the latest revision"
}
}
},
"content_model": {
"type": "string",
"description": "Page content type"
},
"license": {
"type": "string",
"description": "Information about the wiki's license",
"properties": {
"url": {
"type": "string",
"description": "URL of the applicable license"
},
"title": {
"type": "string",
"description": "Name of the applicable license"
}
}
},
"source": {
"type": "string",
"description": "Latest page content in the format specified by the content_model property"
}
}
}

View file

@ -0,0 +1,34 @@
{
"description": "Schema for wiki pages.",
"required": [
"source",
"title",
"comment",
"content_model",
"token"
],
"properties": {
"source": {
"type": "string",
"description": "Page content in the format specified by the content_model property"
},
"title": {
"type": "string",
"description": "Page title"
},
"comment": {
"type": "string",
"description": "Reason for creating the page."
},
"content_model": {
"type": "string",
"nullable": true,
"description": "Page content type"
},
"token": {
"type": "string",
"nullable": true,
"description": "CSRF token required when using cookie-based authentication."
}
}
}

View file

@ -253,4 +253,14 @@ class UpdateHandler extends EditHandler {
$json = ( $this->jsonDiffFunction )( $from->getText(), $to->getText(), 2 );
return FormatJson::decode( $json, true );
}
/**
* This method specifies the JSON schema file for the response
* body when updating an existing page.
*
* @return ?string The file path to the ExistingPage JSON schema.
*/
public function getResponseBodySchemaFileName( string $method ): ?string {
return 'includes/Rest/Handler/Schema/ExistingPage.json';
}
}