api-platform / api-platform/core

HeaderParameter constraint-validators receive array value by default

Open
#8,499 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
2.6k
Forks
980
Avg merge
2d 5h
Merged PRs (30d)
48

Description

**API Platform version(s) affected**: 4.3.17

**Description**
The symfony constraint validators e.g. `Symfony\Component\Validator\Constraints\NotBlankValidator` receive array value by default. Because of that if we pass empty string then validation does not work. Is this a bug or a feature?

**How to reproduce**
```php
parameters: [
'foo' => new HeaderParameter(
required: true,
constraints: [new NotBlank(message: 'foo missing from header')]
),
],
```

**Possible Solution**
```php
parameters: [
'foo' => new HeaderParameter(
required: true,
constraints: [new NotBlank(message: 'foo missing from header')],
nativeType: new BuiltinType(typeIdentifier: TypeIdentifier::STRING)
),
],
```

**Additional Context**
MR to improve doc: https://github.com/api-platform/docs/pull/2322

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.