|
15 | 15 | use Matomo\Dependencies\OpenApiDocs\phpDocumentor\Reflection\DocBlock\Tags\Param; |
16 | 16 | use Matomo\Dependencies\OpenApiDocs\phpDocumentor\Reflection\DocBlock\Tags\TagWithType; |
17 | 17 | use Matomo\Dependencies\OpenApiDocs\phpDocumentor\Reflection\DocBlockFactory; |
| 18 | +use Piwik\Exception\PluginNotFoundException; |
18 | 19 | use Piwik\API\DocumentationGenerator; |
19 | 20 | use Piwik\API\NoDefaultValue; |
20 | 21 | use Piwik\API\Proxy; |
@@ -98,13 +99,20 @@ public function __construct(DocumentationGenerator $generator) |
98 | 99 | * |
99 | 100 | * @return string[]|array[] The collection of all the lines which make up the generated annotations for the public API |
100 | 101 | * endpoints defined by the plugin. |
101 | | - * @throws \Piwik\Exception\PluginDeactivatedException If the plugin is not activated. It should be loaded. |
| 102 | + * @throws PluginNotFoundException If the plugin is not present in the filesystem. |
102 | 103 | * @throws \Throwable |
103 | 104 | */ |
104 | 105 | public function generatePluginApiAnnotations(string $pluginName, bool $writeToFile = false): array |
105 | 106 | { |
106 | 107 | BaseValidator::check('plugin', $pluginName, [new NotEmpty()]); |
107 | | - Manager::getInstance()->checkIsPluginActivated($pluginName); |
| 108 | + |
| 109 | + if (in_array($pluginName, OpenApiDocs::PLUGIN_BLOCKLIST, true)) { |
| 110 | + throw new \RuntimeException('OpenAPI doc generation is blocked for ' . $pluginName . '.'); |
| 111 | + } |
| 112 | + |
| 113 | + if (!Manager::getInstance()->isPluginInFilesystem($pluginName)) { |
| 114 | + throw new PluginNotFoundException($pluginName); |
| 115 | + } |
108 | 116 |
|
109 | 117 | $rules = require $this->currentPluginDir . '/Annotations/config.php'; |
110 | 118 | $pluginAnnotationDir = $this->currentPluginDir . OpenApiDocs::GENERATED_ANNOTATIONS_PATH; |
@@ -1180,24 +1188,27 @@ protected function determineResponses(array $rules, string $plugin, string $meth |
1180 | 1188 | $responseSchema = !empty($responseInfo['type']) ? $this->buildSchemaObjectArray($responseInfo['type']) : []; |
1181 | 1189 |
|
1182 | 1190 | $mediaTypes = []; |
1183 | | - // This simply reuses the example URLs used by the current documentation, but some endpoints don't work because authentication is required |
1184 | | - $exampleUrls = $this->getApplicableDemoExampleUrls($plugin, $method, $paramsData); |
1185 | | - foreach ($exampleUrls as $type => $url) { |
1186 | | - $exampleValue = $this->getExampleIfAvailable($url); |
1187 | | - // If the example lookup failed, try making the same request locally using a local token. |
1188 | | - if (empty($exampleValue)) { |
1189 | | - $exampleValue = $this->getExampleIfAvailable($url, true); |
1190 | | - } |
1191 | | - if (strlen($exampleValue) > self::EXAMPLE_CHAR_LIMIT) { |
1192 | | - $exampleValue = $this->cutExampleCloseToCharLimit($exampleValue, $type); |
1193 | | - } |
| 1191 | + $exampleUrls = []; |
| 1192 | + if (Manager::getInstance()->isPluginActivated($plugin)) { |
| 1193 | + // Only fetch live examples for activated plugins since their endpoints can be executed safely. |
| 1194 | + $exampleUrls = $this->getApplicableDemoExampleUrls($plugin, $method, $paramsData); |
| 1195 | + foreach ($exampleUrls as $type => $url) { |
| 1196 | + $exampleValue = $this->getExampleIfAvailable($url); |
| 1197 | + // If the example lookup failed, try making the same request locally using a local token. |
| 1198 | + if (empty($exampleValue)) { |
| 1199 | + $exampleValue = $this->getExampleIfAvailable($url, true); |
| 1200 | + } |
| 1201 | + if (strlen($exampleValue) > self::EXAMPLE_CHAR_LIMIT) { |
| 1202 | + $exampleValue = $this->cutExampleCloseToCharLimit($exampleValue, $type); |
| 1203 | + } |
1194 | 1204 |
|
1195 | | - // Skip if there was no example response |
1196 | | - if (empty($exampleValue)) { |
1197 | | - continue; |
1198 | | - } |
| 1205 | + // Skip if there was no example response |
| 1206 | + if (empty($exampleValue)) { |
| 1207 | + continue; |
| 1208 | + } |
1199 | 1209 |
|
1200 | | - $mediaTypes[] = $this->buildMediaTypePropertiesArray($type, $exampleValue, $responseSchema); |
| 1210 | + $mediaTypes[] = $this->buildMediaTypePropertiesArray($type, $exampleValue, $responseSchema); |
| 1211 | + } |
1201 | 1212 | } |
1202 | 1213 |
|
1203 | 1214 | // Check if any example files exist even though there aren't any example URLs |
|
0 commit comments