Skip to content
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
8 changes: 7 additions & 1 deletion core/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,8 @@ use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\HeaderParameter;
use ApiPlatform\Metadata\QueryParameter;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\TypeInfo\Type\BuiltinType;
use Symfony\Component\TypeInfo\TypeIdentifier;

#[ApiResource(operations: [
new GetCollection(
Expand All @@ -510,7 +512,8 @@ use Symfony\Component\Validator\Constraints as Assert;
'X-Request-ID' => new HeaderParameter(
description: 'A unique request identifier.',
required: true,
constraints: [new Assert\Uuid()]
constraints: [new Assert\Uuid()],
nativeType: new BuiltinType(typeIdentifier: TypeIdentifier::STRING)
)
]
)
Expand All @@ -521,6 +524,9 @@ class User {}
> [!NOTE] When `castToNativeType` is enabled, API Platform infers type validation from the JSON
> Schema.

If `constraints` are used then a valid type needs to be passed using `nativeType` named argument.
Otherwise, the values will be passed as an array to each constraints.

The `ApiPlatform\Validator\Util\ParameterValidationConstraints` trait can be used to automatically
infer validation constraints from the JSON Schema and OpenAPI definitions of a parameter.

Expand Down
Loading