mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 23:59:26 +03:00
Put RequestParam annotations in body (#1328)
* Put RequestParam annotations in body * Fix tests * Cs
This commit is contained in:
parent
8678a21fdd
commit
dbfa4ed8bd
@ -40,10 +40,16 @@ final class FosRestDescriber implements RouteDescriberInterface
|
||||
foreach ($this->getOperations($api, $route) as $operation) {
|
||||
foreach ($annotations as $annotation) {
|
||||
$in = $annotation instanceof QueryParam ? 'query' : 'formData';
|
||||
$parameter = $operation->getParameters()->get($annotation->getName(), $in);
|
||||
if ($annotation instanceof QueryParam) {
|
||||
$parameter = $operation->getParameters()->get($annotation->getName(), 'query');
|
||||
$parameter->setAllowEmptyValue($annotation->nullable && $annotation->allowBlank);
|
||||
} else {
|
||||
$body = $operation->getParameters()->get('body', 'body')->getSchema();
|
||||
$body->setType('object');
|
||||
$parameter = $body->getProperties()->get($annotation->getName());
|
||||
}
|
||||
|
||||
$parameter->setRequired(!$annotation->nullable && $annotation->strict);
|
||||
$parameter->setAllowEmptyValue($annotation->nullable && $annotation->allowBlank);
|
||||
$parameter->setDefault($annotation->getDefault());
|
||||
if (null === $parameter->getType()) {
|
||||
$parameter->setType($annotation->map ? 'array' : 'string');
|
||||
|
@ -124,20 +124,23 @@ class FunctionalTest extends WebTestCase
|
||||
|
||||
$parameters = $operation->getParameters();
|
||||
$this->assertTrue($parameters->has('foo', 'query'));
|
||||
$this->assertTrue($parameters->has('bar', 'formData'));
|
||||
$this->assertTrue($parameters->has('baz', 'formData'));
|
||||
$this->assertTrue($parameters->has('body', 'body'));
|
||||
$body = $parameters->get('body', 'body')->getSchema()->getProperties();
|
||||
|
||||
$this->assertTrue($body->has('bar'));
|
||||
$this->assertTrue($body->has('baz'));
|
||||
|
||||
$fooParameter = $parameters->get('foo', 'query');
|
||||
$this->assertNotNull($fooParameter->getPattern());
|
||||
$this->assertEquals('\d+', $fooParameter->getPattern());
|
||||
$this->assertNull($fooParameter->getFormat());
|
||||
|
||||
$barParameter = $parameters->get('bar', 'formData');
|
||||
$barParameter = $body->get('bar');
|
||||
$this->assertNotNull($barParameter->getPattern());
|
||||
$this->assertEquals('\d+', $barParameter->getPattern());
|
||||
$this->assertNull($barParameter->getFormat());
|
||||
|
||||
$bazParameter = $parameters->get('baz', 'formData');
|
||||
$bazParameter = $body->get('baz');
|
||||
$this->assertNotNull($bazParameter->getFormat());
|
||||
$this->assertEquals('IsTrue', $bazParameter->getFormat());
|
||||
$this->assertNull($bazParameter->getPattern());
|
||||
|
Loading…
x
Reference in New Issue
Block a user