Skip to content

fix(openapi): Prevent allowReserved and allowEmptyValue being returned on a path parameter #7220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/OpenApi/Model/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{
use ExtensionTrait;

public function __construct(private string $name, private string $in, private string $description = '', private bool $required = false, private bool $deprecated = false, private ?bool $allowEmptyValue = null, private array $schema = [], private ?string $style = null, private bool $explode = false, private ?bool $allowReserved = null, private $example = null, private ?\ArrayObject $examples = null, private ?\ArrayObject $content = null)
public function __construct(private string $name, private string $in, private string $description = '', private bool $required = false, private bool $deprecated = false, private bool $allowEmptyValue = false, private array $schema = [], private ?string $style = null, private bool $explode = false, private bool $allowReserved = false, private $example = null, private ?\ArrayObject $examples = null, private ?\ArrayObject $content = null)

Check warning on line 20 in src/OpenApi/Model/Parameter.php

View check run for this annotation

Codecov / codecov/patch

src/OpenApi/Model/Parameter.php#L20

Added line #L20 was not covered by tests
{
if (null === $style) {
if ('query' === $in || 'cookie' === $in) {
Expand Down Expand Up @@ -55,12 +55,12 @@

public function canAllowEmptyValue(): ?bool
{
return $this->allowEmptyValue;
return 'query' === $this->in ? $this->allowEmptyValue : null;

Check warning on line 58 in src/OpenApi/Model/Parameter.php

View check run for this annotation

Codecov / codecov/patch

src/OpenApi/Model/Parameter.php#L58

Added line #L58 was not covered by tests
}

public function getAllowEmptyValue(): ?bool
{
return $this->allowEmptyValue;
return 'query' === $this->in ? $this->allowEmptyValue : null;

Check warning on line 63 in src/OpenApi/Model/Parameter.php

View check run for this annotation

Codecov / codecov/patch

src/OpenApi/Model/Parameter.php#L63

Added line #L63 was not covered by tests
}

public function getSchema(): array
Expand All @@ -85,12 +85,12 @@

public function canAllowReserved(): ?bool
{
return $this->allowReserved;
return 'query' === $this->in ? $this->allowReserved : null;

Check warning on line 88 in src/OpenApi/Model/Parameter.php

View check run for this annotation

Codecov / codecov/patch

src/OpenApi/Model/Parameter.php#L88

Added line #L88 was not covered by tests
}

public function getAllowReserved(): ?bool
{
return $this->allowReserved;
return 'query' === $this->in ? $this->allowReserved : null;

Check warning on line 93 in src/OpenApi/Model/Parameter.php

View check run for this annotation

Codecov / codecov/patch

src/OpenApi/Model/Parameter.php#L93

Added line #L93 was not covered by tests
}

public function getExample()
Expand Down Expand Up @@ -151,7 +151,9 @@
public function withAllowEmptyValue(bool $allowEmptyValue): self
{
$clone = clone $this;
$clone->allowEmptyValue = $allowEmptyValue;
if ('query' === $clone->in) {
$clone->allowEmptyValue = $allowEmptyValue;

Check warning on line 155 in src/OpenApi/Model/Parameter.php

View check run for this annotation

Codecov / codecov/patch

src/OpenApi/Model/Parameter.php#L154-L155

Added lines #L154 - L155 were not covered by tests
}

return $clone;
}
Expand Down Expand Up @@ -183,7 +185,9 @@
public function withAllowReserved(bool $allowReserved): self
{
$clone = clone $this;
$clone->allowReserved = $allowReserved;
if ('query' === $clone->in) {
$clone->allowReserved = $allowReserved;

Check warning on line 189 in src/OpenApi/Model/Parameter.php

View check run for this annotation

Codecov / codecov/patch

src/OpenApi/Model/Parameter.php#L188-L189

Added lines #L188 - L189 were not covered by tests
}

return $clone;
}
Expand Down
Loading