Skip to content

Commit

Permalink
feat(state): strict query parameters (#6399)
Browse files Browse the repository at this point in the history
* feat(state): strict query parameters

* fixes
  • Loading branch information
soyuka authored Dec 16, 2024
1 parent bd0e929 commit 57f15cf
Show file tree
Hide file tree
Showing 23 changed files with 195 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Metadata/ApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,7 @@ public function __construct(
?string $policy = null,
array|string|null $middleware = null,
array|Parameters|null $parameters = null,
protected ?bool $strictQueryParameterValidation = null,
protected array $extraProperties = [],
) {
parent::__construct(
Expand Down Expand Up @@ -1007,6 +1008,7 @@ class: $class,
rules: $rules,
policy: $policy,
middleware: $middleware,
strictQueryParameterValidation: $strictQueryParameterValidation,
extraProperties: $extraProperties
);

Expand Down
2 changes: 2 additions & 0 deletions src/Metadata/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public function __construct(
mixed $rules = null,
?string $policy = null,
array|string|null $middleware = null,
?bool $strictQueryParameterValidation = null,
array $extraProperties = [],
) {
parent::__construct(
Expand Down Expand Up @@ -178,6 +179,7 @@ class: $class,
extraProperties: $extraProperties,
collectDenormalizationErrors: $collectDenormalizationErrors,
parameters: $parameters,
strictQueryParameterValidation: $strictQueryParameterValidation,
stateOptions: $stateOptions,
);
}
Expand Down
1 change: 1 addition & 0 deletions src/Metadata/Extractor/XmlResourceExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ private function buildExtendedBase(\SimpleXMLElement $resource): array
'paginationViaCursor' => $this->buildPaginationViaCursor($resource),
'exceptionToStatus' => $this->buildExceptionToStatus($resource),
'queryParameterValidationEnabled' => $this->phpize($resource, 'queryParameterValidationEnabled', 'bool'),
'strictQueryParameterValidation' => $this->phpize($resource, 'strictQueryParameterValidation', 'bool'),
'stateOptions' => $this->buildStateOptions($resource),
'links' => $this->buildLinks($resource),
'headers' => $this->buildHeaders($resource),
Expand Down
1 change: 1 addition & 0 deletions src/Metadata/Extractor/YamlResourceExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ private function buildOperations(array $resource, array $root): ?array
'write' => $this->phpize($operation, 'write', 'bool'),
'serialize' => $this->phpize($operation, 'serialize', 'bool'),
'queryParameterValidate' => $this->phpize($operation, 'queryParameterValidate', 'bool'),
'strictQueryParameterValidation' => $this->phpize($operation, 'strictQueryParameterValidation', 'bool'),
'priority' => $this->phpize($operation, 'priority', 'integer'),
'name' => $this->phpize($operation, 'name', 'string'),
'class' => (string) $class,
Expand Down
1 change: 1 addition & 0 deletions src/Metadata/Extractor/schema/resources.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@

<xsd:attributeGroup name="extendedBase">
<xsd:attributeGroup ref="base"/>
<xsd:attribute type="xsd:boolean" name="strictQueryParameterValidation"/>
<xsd:attribute type="xsd:boolean" name="queryParameterValidationEnabled"/>
<xsd:attribute type="xsd:string" name="routePrefix"/>
<xsd:attribute type="xsd:boolean" name="stateless"/>
Expand Down
2 changes: 2 additions & 0 deletions src/Metadata/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public function __construct(
mixed $rules = null,
?string $policy = null,
array|string|null $middleware = null,
?bool $strictQueryParameterValidation = null,
array $extraProperties = [],
) {
parent::__construct(
Expand Down Expand Up @@ -177,6 +178,7 @@ class: $class,
rules: $rules,
policy: $policy,
middleware: $middleware,
strictQueryParameterValidation: $strictQueryParameterValidation,
extraProperties: $extraProperties,
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Metadata/GetCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public function __construct(
array|string|null $rules = null,
?string $policy = null,
array|string|null $middleware = null,
?bool $strictQueryParameterValidation = null,
array $extraProperties = [],
private ?string $itemUriTemplate = null,
) {
Expand Down Expand Up @@ -178,6 +179,7 @@ class: $class,
rules: $rules,
policy: $policy,
middleware: $middleware,
strictQueryParameterValidation: $strictQueryParameterValidation,
stateOptions: $stateOptions,
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Metadata/HttpOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public function __construct(
protected ?array $exceptionToStatus = null,
protected ?array $links = null,
protected ?array $errors = null,
protected ?bool $strictQueryParameterValidation = null,

?string $shortName = null,
?string $class = null,
Expand Down Expand Up @@ -257,6 +258,7 @@ class: $class,
policy: $policy,
middleware: $middleware,
queryParameterValidationEnabled: $queryParameterValidationEnabled,
strictQueryParameterValidation: $strictQueryParameterValidation,
extraProperties: $extraProperties
);
}
Expand Down
14 changes: 14 additions & 0 deletions src/Metadata/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public function __construct(
protected ?string $policy = null,
protected array|string|null $middleware = null,
protected ?bool $queryParameterValidationEnabled = null,
protected ?bool $strictQueryParameterValidation = null,
protected array $extraProperties = [],
) {
if (\is_array($parameters) && $parameters) {
Expand Down Expand Up @@ -666,4 +667,17 @@ public function withExtraProperties(array $extraProperties = []): static

return $self;
}

public function getStrictQueryParameterValidation(): ?bool
{
return $this->strictQueryParameterValidation;
}

public function withStrictQueryParameterValidation(bool $strictQueryParameterValidation): static
{
$self = clone $this;
$self->strictQueryParameterValidation = $strictQueryParameterValidation;

return $self;
}
}
2 changes: 2 additions & 0 deletions src/Metadata/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,7 @@ public function __construct(
?string $policy = null,
array|string|null $middleware = null,
?bool $queryParameterValidationEnabled = null,
protected ?bool $strictQueryParameterValidation = null,
protected array $extraProperties = [],
) {
parent::__construct(
Expand Down Expand Up @@ -856,6 +857,7 @@ class: $class,
policy: $policy,
middleware: $middleware,
queryParameterValidationEnabled: $queryParameterValidationEnabled,
strictQueryParameterValidation: $strictQueryParameterValidation,
extraProperties: $extraProperties,
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Metadata/Patch.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public function __construct(
mixed $rules = null,
?string $policy = null,
array|string|null $middleware = null,
?bool $strictQueryParameterValidation = null,
array $extraProperties = [],
) {
parent::__construct(
Expand Down Expand Up @@ -178,6 +179,7 @@ class: $class,
rules: $rules,
policy: $policy,
middleware: $middleware,
strictQueryParameterValidation: $strictQueryParameterValidation,
extraProperties: $extraProperties
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Metadata/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public function __construct(
array|string|null $middleware = null,
array $extraProperties = [],
private ?string $itemUriTemplate = null,
?bool $strictQueryParameterValidation = null,
) {
parent::__construct(
method: 'POST',
Expand Down Expand Up @@ -179,6 +180,7 @@ class: $class,
rules: $rules,
policy: $policy,
middleware: $middleware,
strictQueryParameterValidation: $strictQueryParameterValidation,
extraProperties: $extraProperties
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Metadata/Put.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public function __construct(
?string $policy = null,
array|string|null $middleware = null,
array $extraProperties = [],
?bool $strictQueryParameterValidation = null,
private ?bool $allowCreate = null,
) {
parent::__construct(
Expand Down Expand Up @@ -179,6 +180,7 @@ class: $class,
rules: $rules,
policy: $policy,
middleware: $middleware,
strictQueryParameterValidation: $strictQueryParameterValidation,
extraProperties: $extraProperties
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ final class XmlResourceAdapter implements ResourceAdapterInterface
'securityPostValidation',
'securityPostValidationMessage',
'queryParameterValidationEnabled',
'strictQueryParameterValidation',
'stateOptions',
'collectDenormalizationErrors',
'links',
Expand Down
Loading

0 comments on commit 57f15cf

Please sign in to comment.