From 8fe826a72f9701ef4de0646ba3cb78a5212dff57 Mon Sep 17 00:00:00 2001 From: Robert Jenman <767666+robjenman@users.noreply.github.com> Date: Mon, 16 Jun 2025 12:28:08 +0100 Subject: [PATCH 1/2] fix(openapi): Prevent allowReserved and allowEmptyValue being returned on a path parameter --- src/OpenApi/Model/Parameter.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/OpenApi/Model/Parameter.php b/src/OpenApi/Model/Parameter.php index d242fa8a6d..386ef160a0 100644 --- a/src/OpenApi/Model/Parameter.php +++ b/src/OpenApi/Model/Parameter.php @@ -17,7 +17,7 @@ final class Parameter { 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) { if (null === $style) { if ('query' === $in || 'cookie' === $in) { @@ -55,12 +55,14 @@ public function getDeprecated(): bool public function canAllowEmptyValue(): ?bool { - return $this->allowEmptyValue; + // allowEmptyValue is only valid for parameters where "in" is "query" + return 'query' === $this->in ? $this->allowEmptyValue : null; } public function getAllowEmptyValue(): ?bool { - return $this->allowEmptyValue; + // allowEmptyValue is only valid for parameters where "in" is "query" + return 'query' === $this->in ? $this->allowEmptyValue : null; } public function getSchema(): array @@ -85,12 +87,12 @@ public function getExplode(): bool public function canAllowReserved(): ?bool { - return $this->allowReserved; + return 'query' === $this->in ? $this->allowReserved : null; } public function getAllowReserved(): ?bool { - return $this->allowReserved; + return 'query' === $this->in ? $this->allowReserved : null; } public function getExample() @@ -151,7 +153,9 @@ public function withDeprecated(bool $deprecated): self public function withAllowEmptyValue(bool $allowEmptyValue): self { $clone = clone $this; - $clone->allowEmptyValue = $allowEmptyValue; + if ('query' === $clone->in) { + $clone->allowEmptyValue = $allowEmptyValue; + } return $clone; } @@ -183,7 +187,9 @@ public function withExplode(bool $explode): self public function withAllowReserved(bool $allowReserved): self { $clone = clone $this; - $clone->allowReserved = $allowReserved; + if ('query' === $clone->in) { + $clone->allowReserved = $allowReserved; + } return $clone; } From f1d89a96a10130bb6a17eca630cbe91c9fdb7d44 Mon Sep 17 00:00:00 2001 From: Robert Jenman <767666+robjenman@users.noreply.github.com> Date: Mon, 16 Jun 2025 12:30:48 +0100 Subject: [PATCH 2/2] Update Parameter.php --- src/OpenApi/Model/Parameter.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/OpenApi/Model/Parameter.php b/src/OpenApi/Model/Parameter.php index 386ef160a0..d3856c56ac 100644 --- a/src/OpenApi/Model/Parameter.php +++ b/src/OpenApi/Model/Parameter.php @@ -55,13 +55,11 @@ public function getDeprecated(): bool public function canAllowEmptyValue(): ?bool { - // allowEmptyValue is only valid for parameters where "in" is "query" return 'query' === $this->in ? $this->allowEmptyValue : null; } public function getAllowEmptyValue(): ?bool { - // allowEmptyValue is only valid for parameters where "in" is "query" return 'query' === $this->in ? $this->allowEmptyValue : null; }