Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions .github/workflows/matomo-tests.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Action for running tests
# This file has been automatically created.
# To recreate it you can run this command
# ./console generate:test-action --plugin="OpenApiDocs" --php-versions="7.2,8.4" --schedule-cron="0 19 * * 6"
# ./console generate:test-action --plugin="ApiReference" --php-versions="7.2,8.4" --schedule-cron="0 19 * * 6"

name: Plugin OpenApiDocs Tests
name: Plugin ApiReference Tests

on:
pull_request:
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
- name: Run tests
uses: matomo-org/github-action-tests@main
with:
plugin-name: 'OpenApiDocs'
plugin-name: 'ApiReference'
php-version: ${{ matrix.php }}
test-type: 'PluginTests'
matomo-test-branch: ${{ matrix.target }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
tools: cs2pr
- name: Install dependencies
run:
composer init --name=matomo/openapidocs --quiet;
composer init --name=matomo/apireference --quiet;
composer --no-plugins config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true -n;
composer config repositories.matomo-coding-standards vcs https://github.com/matomo-org/matomo-coding-standards -n;
composer require matomo-org/matomo-coding-standards:dev-master;
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ permissions:
statuses: read

env:
PLUGIN_NAME: OpenApiDocs
PLUGIN_NAME: ApiReference

jobs:
phpstan:
Expand Down
16 changes: 8 additions & 8 deletions API.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

namespace Piwik\Plugins\OpenApiDocs;
namespace Piwik\Plugins\ApiReference;

use Piwik\Piwik;
use Piwik\Plugins\OpenApiDocs\Generation\PluginListProvider;
use Piwik\Plugins\ApiReference\Generation\PluginListProvider;
use Piwik\Plugin\Manager;
use Piwik\Plugins\OpenApiDocs\Specs\SpecGenerator;
use Piwik\Plugins\OpenApiDocs\Specs\PathResolver;
use Piwik\Plugins\ApiReference\Specs\SpecGenerator;
use Piwik\Plugins\ApiReference\Specs\PathResolver;

/**
* Provides Reporting API endpoints for reading OpenAPI plugin configuration and specifications.
*
* Exposes endpoints to return the effective plugin list for spec generation, read pre-generated spec files,
* or generate plugin OpenAPI specifications on demand.
*
* @method static \Piwik\Plugins\OpenApiDocs\API getInstance()
* @method static \Piwik\Plugins\ApiReference\API getInstance()
*/
class API extends \Piwik\Plugin\API
{
/**
* Returns the plugin names used for OpenApiDocs spec generation.
* Returns the plugin names used for ApiReference spec generation.
*
* @return array<int, string>
*/
Expand All @@ -38,7 +38,7 @@ public function getAllowedPlugins(): array
}

/**
* Returns metadata for the plugins used by OpenApiDocs spec generation.
* Returns metadata for the plugins used by ApiReference spec generation.
*
* @return array<string, array{description: string}>
*/
Expand Down Expand Up @@ -74,7 +74,7 @@ public function getOpenApiSpec(string $pluginName, string $format = 'json'): arr

$filePath = $this->getSpecFilePath($pluginName);
if (!$this->isSpecFileReadable($filePath)) {
throw new \Exception('OpenAPI spec file was not found. Generate it first via openapidocs:generate-spec-file.');
throw new \Exception('OpenAPI spec file was not found. Generate it first via apireference:generate-spec-file.');
}

$specContents = $this->readSpecFile($filePath);
Expand Down
38 changes: 19 additions & 19 deletions Annotations/AnnotationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

declare(strict_types=1);

namespace Piwik\Plugins\OpenApiDocs\Annotations;
namespace Piwik\Plugins\ApiReference\Annotations;

use Matomo\Dependencies\OpenApiDocs\phpDocumentor\Reflection\DocBlock\Description;
use Matomo\Dependencies\OpenApiDocs\phpDocumentor\Reflection\DocBlock\Tags\Param;
use Matomo\Dependencies\OpenApiDocs\phpDocumentor\Reflection\DocBlock\Tags\TagWithType;
use Matomo\Dependencies\OpenApiDocs\phpDocumentor\Reflection\DocBlockFactory;
use Matomo\Dependencies\ApiReference\phpDocumentor\Reflection\DocBlock\Description;
use Matomo\Dependencies\ApiReference\phpDocumentor\Reflection\DocBlock\Tags\Param;
use Matomo\Dependencies\ApiReference\phpDocumentor\Reflection\DocBlock\Tags\TagWithType;
use Matomo\Dependencies\ApiReference\phpDocumentor\Reflection\DocBlockFactory;
use Piwik\Exception\PluginNotFoundException;
use Piwik\API\DocumentationGenerator;
use Piwik\API\NoDefaultValue;
Expand All @@ -23,9 +23,9 @@
use Piwik\Http;
use Piwik\Piwik;
use Piwik\Plugin\Manager;
use Piwik\Plugins\OpenApiDocs\Artifact\ArtifactWriter;
use Piwik\Plugins\OpenApiDocs\OpenApiDocs;
use Piwik\Plugins\OpenApiDocs\Specs\PathResolver;
use Piwik\Plugins\ApiReference\Artifact\ArtifactWriter;
use Piwik\Plugins\ApiReference\ApiReference;
use Piwik\Plugins\ApiReference\Specs\PathResolver;
use Piwik\SettingsPiwik;
use Piwik\Url;
use Piwik\UrlHelper;
Expand Down Expand Up @@ -116,7 +116,7 @@ public function __construct(
$this->missingImportantDataWarnings = [];
$this->allowLocalRequests = $allowLocalRequests;
$this->parameterExamples = null;
$this->currentPluginDir = Manager::getInstance()::getPluginDirectory('OpenApiDocs');
$this->currentPluginDir = Manager::getInstance()::getPluginDirectory('ApiReference');
}

/**
Expand All @@ -136,7 +136,7 @@ public function generatePluginApiAnnotations(string $pluginName, bool $writeToFi
{
BaseValidator::check('plugin', $pluginName, [new NotEmpty()]);

if (in_array($pluginName, OpenApiDocs::PLUGIN_BLOCKLIST, true)) {
if (in_array($pluginName, ApiReference::PLUGIN_BLOCKLIST, true)) {
throw new \RuntimeException('OpenAPI doc generation is blocked for ' . $pluginName . '.');
}

Expand Down Expand Up @@ -224,7 +224,7 @@ public function getContentForGeneratedAnnotationsFile(array $annotations, string
$lines = [
'<?php',
'',
'namespace Piwik\\Plugins\\OpenApiDocs\\tmp\\annotations;',
'namespace Piwik\\Plugins\\ApiReference\\tmp\\annotations;',
'',
'/**',
];
Expand Down Expand Up @@ -1089,7 +1089,7 @@ protected function getExampleIfAvailable(string $url, bool $useLocalToken = fals
// If the flag to use a temp token is set, get a token and update the request URL
$tempUrl = $url . '&hideIdSubDatable=1';
if ($useLocalToken) {
$token = Piwik::requestTemporarySystemAuthToken('OpenApiDocs', 24);
$token = Piwik::requestTemporarySystemAuthToken('ApiReference', 24);
$tempUrl = str_replace('&token_auth=anonymous', '&token_auth=' . $token, $tempUrl);
}
try {
Expand Down Expand Up @@ -1288,7 +1288,7 @@ public function convertExampleXmlToObject(string $xml): array
// Handle any attributes
$grouped = [];
foreach ($node->attributes() as $attribute) {
$grouped[OpenApiDocs::OA_XML_ATTRIBUTES_TEMP_PROPERTY_NAME][] = [$attribute->getName() => (string) $attribute];
$grouped[ApiReference::OA_XML_ATTRIBUTES_TEMP_PROPERTY_NAME][] = [$attribute->getName() => (string) $attribute];
}

// Group children by tag name; repeated names become arrays
Expand Down Expand Up @@ -1476,7 +1476,7 @@ protected function buildMediaTypePropertiesArray(string $format, string $example
$jsonSchema = $format === 'json' ? $this->buildSchemaAnnotationFromJsonExample($decodedExampleValue) : [];
$xmlSchema = $format === 'xml' ? $this->buildSchemaAnnotationFromXmlExample($decodedExampleValue) : [];
// If the XML example contains the temporary property to assist in building XML attributes in the schema, replace with newly encoded array with property removed
if ($format === 'xml' && strpos($exampleValue, OpenApiDocs::OA_XML_ATTRIBUTES_TEMP_PROPERTY_NAME) !== false) {
if ($format === 'xml' && strpos($exampleValue, ApiReference::OA_XML_ATTRIBUTES_TEMP_PROPERTY_NAME) !== false) {
$exampleValue = json_encode($decodedExampleValue);
}

Expand Down Expand Up @@ -1718,7 +1718,7 @@ public function buildSchemaAnnotationFromXmlExample(array &$xmlArrayObject, stri
protected function removeTempOaXmlAttributeProperty(array &$decodedExampleValue): void
{
foreach ($decodedExampleValue as $key => &$value) {
if ($key === OpenApiDocs::OA_XML_ATTRIBUTES_TEMP_PROPERTY_NAME) {
if ($key === ApiReference::OA_XML_ATTRIBUTES_TEMP_PROPERTY_NAME) {
unset($decodedExampleValue[$key]);
// Add the attributes as actual properties so that they are visible in the example
foreach ($value as $attributeName => $attributeValue) {
Expand Down Expand Up @@ -1794,8 +1794,8 @@ public function buildPropertyAnnotationFromXmlExample(string $propName, array $v
$key = null;
foreach ($keys as $candidate) {
if (
$candidate !== OpenApiDocs::OA_XML_ATTRIBUTES_TEMP_PROPERTY_NAME
&& $candidate !== OpenApiDocs::OA_XML_ATTRIBUTES_DEFAULT_KEY_NAME
$candidate !== ApiReference::OA_XML_ATTRIBUTES_TEMP_PROPERTY_NAME
&& $candidate !== ApiReference::OA_XML_ATTRIBUTES_DEFAULT_KEY_NAME
) {
$key = $candidate;
break;
Expand All @@ -1807,8 +1807,8 @@ public function buildPropertyAnnotationFromXmlExample(string $propName, array $v

// Special handling for XML attributes (metadata-only)
if (
$key === OpenApiDocs::OA_XML_ATTRIBUTES_TEMP_PROPERTY_NAME
|| $key === OpenApiDocs::OA_XML_ATTRIBUTES_DEFAULT_KEY_NAME
$key === ApiReference::OA_XML_ATTRIBUTES_TEMP_PROPERTY_NAME
|| $key === ApiReference::OA_XML_ATTRIBUTES_DEFAULT_KEY_NAME
) {
$hasAttributes = true;
$childLines = array_merge($childLines, $this->buildXmlAttributeSchemaLines($value));
Expand Down
6 changes: 3 additions & 3 deletions Annotations/ApiMethodInfoExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

declare(strict_types=1);

namespace Piwik\Plugins\OpenApiDocs\Annotations;
namespace Piwik\Plugins\ApiReference\Annotations;

use Piwik\Exception\PluginNotFoundException;
use Piwik\API\Proxy;
use Piwik\API\Request;
use Piwik\Plugin\Manager;
use Piwik\Plugins\OpenApiDocs\Artifact\ArtifactWriter;
use Piwik\Plugins\OpenApiDocs\Specs\PathResolver;
use Piwik\Plugins\ApiReference\Artifact\ArtifactWriter;
use Piwik\Plugins\ApiReference\Specs\PathResolver;
use Piwik\Validators\BaseValidator;
use Piwik\Validators\NotEmpty;

Expand Down
2 changes: 1 addition & 1 deletion Annotations/GlobalApiComponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

namespace Piwik\Plugins\OpenApiDocs\Annotations;
namespace Piwik\Plugins\ApiReference\Annotations;

/**
* Global components for generating OpenAPI specs for the Matomo Reporting API.
Expand Down
28 changes: 14 additions & 14 deletions OpenApiDocs.php → ApiReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

namespace Piwik\Plugins\OpenApiDocs;
namespace Piwik\Plugins\ApiReference;

class OpenApiDocs extends \Piwik\Plugin
class ApiReference extends \Piwik\Plugin
{
public const DEFAULT_SPEC_VERSION = '1.0.0';
public const OA_XML_ATTRIBUTES_TEMP_PROPERTY_NAME = 'oaXmlAttributes';
Expand All @@ -30,17 +30,17 @@ public function registerEvents()
public function getClientSideTranslationKeys(&$translationKeys): void
{
$translationKeys[] = 'CoreHome_LearnMoreFullStop';
$translationKeys[] = 'OpenApiDocs_ReportingApiMoreInformation';
$translationKeys[] = 'OpenApiDocs_ReportingApiReference';
$translationKeys[] = 'OpenApiDocs_ReportingApiSummary';
$translationKeys[] = 'OpenApiDocs_SwaggerApi';
$translationKeys[] = 'OpenApiDocs_SwaggerPagePluginEmpty';
$translationKeys[] = 'OpenApiDocs_SwaggerPageRequestFailed';
$translationKeys[] = 'OpenApiDocs_SwaggerPageSpecLoadFailed';
$translationKeys[] = 'OpenApiDocs_SwaggerPageSearchNoResults';
$translationKeys[] = 'OpenApiDocs_SwaggerPageSearchPlaceholder';
$translationKeys[] = 'OpenApiDocs_UserAuthentication';
$translationKeys[] = 'OpenApiDocs_UserAuthenticationManageTokens';
$translationKeys[] = 'OpenApiDocs_UserAuthenticationUsingTokenAuth';
$translationKeys[] = 'ApiReference_ReportingApiMoreInformation';
$translationKeys[] = 'ApiReference_ReportingApiReference';
$translationKeys[] = 'ApiReference_ReportingApiSummary';
$translationKeys[] = 'ApiReference_SwaggerApi';
$translationKeys[] = 'ApiReference_SwaggerPagePluginEmpty';
$translationKeys[] = 'ApiReference_SwaggerPageRequestFailed';
$translationKeys[] = 'ApiReference_SwaggerPageSpecLoadFailed';
$translationKeys[] = 'ApiReference_SwaggerPageSearchNoResults';
$translationKeys[] = 'ApiReference_SwaggerPageSearchPlaceholder';
$translationKeys[] = 'ApiReference_UserAuthentication';
$translationKeys[] = 'ApiReference_UserAuthenticationManageTokens';
$translationKeys[] = 'ApiReference_UserAuthenticationUsingTokenAuth';
}
}
2 changes: 1 addition & 1 deletion Artifact/ArtifactWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

declare(strict_types=1);

namespace Piwik\Plugins\OpenApiDocs\Artifact;
namespace Piwik\Plugins\ApiReference\Artifact;

use Piwik\Filesystem;

Expand Down
15 changes: 2 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
## Changelog

5.0.2-b1 - 2026-03-16
- Added support for string literal union types
- Added API endpoint to retrieve static matomo swagger file
- Added support for deactivated plugins
- Removed token auth support

5.0.1-b1 - 2026-02-16
- Added class and function level docs
- Updated spec generation command to allow single swagger file generation

5.0.0-b1
- Initial implementation of plugin and POC generating documentation from annotations
5.0.0
- Initial release of ApiReference plugin
10 changes: 5 additions & 5 deletions Commands/ExtractReportingApiMethodInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

declare(strict_types=1);

namespace Piwik\Plugins\OpenApiDocs\Commands;
namespace Piwik\Plugins\ApiReference\Commands;

use Piwik\Container\StaticContainer;
use Piwik\Plugin\ConsoleCommand;
use Piwik\Plugins\OpenApiDocs\Annotations\ApiMethodInfoExtractor;
use Piwik\Plugins\OpenApiDocs\Specs\PathResolver;
use Piwik\Plugins\ApiReference\Annotations\ApiMethodInfoExtractor;
use Piwik\Plugins\ApiReference\Specs\PathResolver;

/**
* This class lets you define a new command. To read more about commands have a look at our Matomo Console guide on
Expand All @@ -31,7 +31,7 @@ class ExtractReportingApiMethodInfo extends ConsoleCommand
*/
protected function configure()
{
$this->setName('openapidocs:extract-api-method-info');
$this->setName('apireference:extract-api-method-info');
$this->setDescription('Extract the comment block and basic information about methods for the Matomo Reporting API.');
$this->addRequiredValueOption('plugin', 'p', 'Name of the plugin to inspect');
$this->addNoValueOption('not-dry-run', null, 'Flag to allow writing to file instead of outputting a dry run.');
Expand Down Expand Up @@ -68,7 +68,7 @@ protected function doInitialize(): void
* Ideally, the actual command is quite short as it acts like a controller. It should only receive the input values,
* execute the task by calling a method of another class and output any useful information.
*
* Execute the command like: ./console openapidocs:extract-api-method-info --plugin=TagManager --not-dry-run
* Execute the command like: ./console apireference:extract-api-method-info --plugin=TagManager --not-dry-run
*/
protected function doExecute(): int
{
Expand Down
10 changes: 5 additions & 5 deletions Commands/GenerateAnnotations.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

namespace Piwik\Plugins\OpenApiDocs\Commands;
namespace Piwik\Plugins\ApiReference\Commands;

use Piwik\Container\StaticContainer;
use Piwik\Plugin\ConsoleCommand;
use Piwik\Plugins\OpenApiDocs\Annotations\AnnotationGenerator;
use Piwik\Plugins\OpenApiDocs\Specs\PathResolver;
use Piwik\Plugins\ApiReference\Annotations\AnnotationGenerator;
use Piwik\Plugins\ApiReference\Specs\PathResolver;

/**
* This class lets you define a new command. To read more about commands have a look at our Matomo Console guide on
Expand All @@ -29,7 +29,7 @@ class GenerateAnnotations extends ConsoleCommand
*/
protected function configure()
{
$this->setName('openapidocs:generate-annotations');
$this->setName('apireference:generate-annotations');
$this->setDescription('Generate the annotations swagger-php uses to generate OpenAPI specs.');
$this->addRequiredValueOption('plugin', null, 'Name of the plugin to annotate');
$this->addNoValueOption('not-dry-run', null, 'Flag to allow writing to file instead of outputting a dry run.');
Expand Down Expand Up @@ -66,7 +66,7 @@ protected function doInitialize(): void
* Ideally, the actual command is quite short as it acts like a controller. It should only receive the input values,
* execute the task by calling a method of another class and output any useful information.
*
* Execute the command like: ./console openapidocs:generate-annotations --plugin=TagManager --not-dry-run
* Execute the command like: ./console apireference:generate-annotations --plugin=TagManager --not-dry-run
*/
protected function doExecute(): int
{
Expand Down
Loading
Loading