Skip to content

Commit

Permalink
feat(preparator): exclude generic headers from random examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sidux committed Feb 23, 2024
1 parent 617f2c2 commit 9b3470e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/Definition/Collection/Parameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,17 @@ public function getExamples(): array
}

/**
* @param string[] $exclude
*
* @return array<string, string>
*/
public function getRandomExamples(): array
public function getRandomExamples(array $exclude = []): array
{
$params = [];
foreach ($this as $parameter) {
if (\in_array(mb_strtolower($parameter->getName()), $exclude, true)) {
continue;
}
$schema = $parameter->getSchema();
if ($schema !== null) {
$random = (new SchemaFaker($schema, new Options()))->generate();
Expand Down
6 changes: 5 additions & 1 deletion src/Definition/Example/OperationExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,11 @@ public function getHeaders(): array
if ($this->forceRandom || ($this->autoComplete && \count($this->headers) < $definitionHeadersCount)) {
$randomHeaders = $this->parent
->getHeaders()
->getRandomExamples()
->getRandomExamples([
'content-type',
'authorization',
'range',
])
;
$this->headers = array_merge($randomHeaders, $this->headers);
}
Expand Down

0 comments on commit 9b3470e

Please sign in to comment.