diff --git a/Annotations/AnnotationGenerator.php b/Annotations/AnnotationGenerator.php index 0a699aa..28f1118 100644 --- a/Annotations/AnnotationGenerator.php +++ b/Annotations/AnnotationGenerator.php @@ -94,15 +94,22 @@ class AnnotationGenerator */ protected $missingImportantDataWarnings; + /** + * @var bool + */ + protected $allowLocalRequests; + public function __construct( DocumentationGenerator $generator, ?PathResolver $pathResolver = null, - ?ArtifactWriter $artifactWriter = null + ?ArtifactWriter $artifactWriter = null, + bool $allowLocalRequests = false ) { $this->generator = $generator; $this->pathResolver = $pathResolver ?? new PathResolver(); $this->artifactWriter = $artifactWriter ?? new ArtifactWriter(); $this->missingImportantDataWarnings = []; + $this->allowLocalRequests = $allowLocalRequests; $this->currentPluginDir = Manager::getInstance()::getPluginDirectory('OpenApiDocs'); } @@ -859,6 +866,7 @@ protected function getApplicableDemoExampleUrls(string $pluginName, string $meth */ protected function getDemoReportMetadata(): array { + if (is_array($this->reportMetadata) && count($this->reportMetadata)) { return $this->reportMetadata; } @@ -929,6 +937,7 @@ protected function getExampleIfAvailable(string $url, bool $useLocalToken = fals } } + // Include a specific parameter for the TSV requests. if ($format === 'tsv') { $url .= '&convertToUnicode=0'; @@ -1229,7 +1238,9 @@ protected function determineResponses(array $rules, string $plugin, string $meth $exampleValue = $this->getExampleIfAvailable($url); // If the example lookup failed, try making the same request locally using a local token. if (empty($exampleValue)) { - $exampleValue = $this->getExampleIfAvailable($url, true); + if ($this->allowLocalRequests) { + $exampleValue = $this->getExampleIfAvailable($url, true); + } } if (strlen($exampleValue) > self::EXAMPLE_CHAR_LIMIT) { $exampleValue = $this->cutExampleCloseToCharLimit($exampleValue, $type);