Respect the spec in the FosRestDescriber (#1390)

This commit is contained in:
Guilhem N 2018-08-30 00:41:53 +02:00 committed by GitHub
parent fcb36d8e8d
commit 0e72b64e3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -42,13 +42,21 @@ final class FosRestDescriber implements RouteDescriberInterface
if ($annotation instanceof QueryParam) {
$parameter = $operation->getParameters()->get($annotation->getName(), 'query');
$parameter->setAllowEmptyValue($annotation->nullable && $annotation->allowBlank);
$parameter->setRequired(!$annotation->nullable && $annotation->strict);
} else {
$body = $operation->getParameters()->get('body', 'body')->getSchema();
$body->setType('object');
$parameter = $body->getProperties()->get($annotation->getName());
if (!$annotation->nullable && $annotation->strict) {
$requiredParameters = $body->getRequired();
$requiredParameters[] = $annotation->getName();
$body->setRequired(array_values(array_unique($requiredParameters)));
}
}
$parameter->setRequired(!$annotation->nullable && $annotation->strict);
$parameter->setDefault($annotation->getDefault());
if (null === $parameter->getType()) {
$parameter->setType($annotation->map ? 'array' : 'string');

View File

@ -32,7 +32,7 @@ class DummyType extends AbstractType
$builder->add('password', RepeatedType::class, [
'type' => PasswordType::class,
'first_name' => 'first_field',
'required' => true
'required' => true,
]);
}
}