mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
Add PostParserInterface to JmsMetadataParser to get ValidatorParser found children parsed.
This commit is contained in:
parent
eddba56c66
commit
3f66888f00
@ -293,14 +293,24 @@ class ApiDocExtractor
|
||||
// output (populates 'response' for the formatters)
|
||||
if (null !== $output = $annotation->getOutput()) {
|
||||
$response = array();
|
||||
$supportedParsers = array();
|
||||
|
||||
$normalizedOutput = $this->normalizeClassParameter($output);
|
||||
|
||||
foreach ($this->getParsers($normalizedOutput) as $parser) {
|
||||
if ($parser->supports($normalizedOutput)) {
|
||||
$supportedParsers[] = $parser;
|
||||
$response = $this->mergeParameters($response, $parser->parse($normalizedOutput));
|
||||
}
|
||||
}
|
||||
|
||||
foreach($supportedParsers as $parser) {
|
||||
if($parser instanceof PostParserInterface) {
|
||||
$mp = $parser->postParse($normalizedOutput, $response);
|
||||
$response = $this->mergeParameters($response, $mp);
|
||||
}
|
||||
}
|
||||
|
||||
$response = $this->clearClasses($response);
|
||||
|
||||
$annotation->setResponse($response);
|
||||
|
@ -22,7 +22,7 @@ use JMS\Serializer\Naming\PropertyNamingStrategyInterface;
|
||||
/**
|
||||
* Uses the JMS metadata factory to extract input/output model information
|
||||
*/
|
||||
class JmsMetadataParser implements ParserInterface
|
||||
class JmsMetadataParser implements ParserInterface, PostParserInterface
|
||||
{
|
||||
/**
|
||||
* @var \Metadata\MetadataFactoryInterface
|
||||
@ -206,6 +206,40 @@ class JmsMetadataParser implements ParserInterface
|
||||
return in_array($type, array('boolean', 'integer', 'string', 'float', 'double', 'array', 'DateTime'));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function postParse(array $input, array $parameters)
|
||||
{
|
||||
return $this->doPostParse($parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive `doPostParse` to avoid circular post parsing.
|
||||
*
|
||||
* @param array $parameters
|
||||
* @param array $visited
|
||||
* @return array
|
||||
*/
|
||||
protected function doPostParse (array $parameters, array $visited = array())
|
||||
{
|
||||
foreach($parameters as $param => $data) {
|
||||
if(isset($data['class']) && isset($data['children']) && !in_array($data['class'], $visited)) {
|
||||
$visited[] = $data['class'];
|
||||
|
||||
$input = array('class' => $data['class'], 'groups' => isset($data['groups']) ? $data['groups'] : array());
|
||||
$parameters[$param]['children'] = array_merge(
|
||||
$parameters[$param]['children'], $this->doPostParse($parameters[$param]['children'], $visited)
|
||||
);
|
||||
$parameters[$param]['children'] = array_merge(
|
||||
$parameters[$param]['children'], $this->doParse($input['class'], $visited, $input['groups'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the various ways JMS describes values in arrays, and
|
||||
* get the value type in the array
|
||||
|
@ -20,6 +20,11 @@ class MultipleTest
|
||||
*/
|
||||
public $baz;
|
||||
|
||||
/**
|
||||
* @JMS\Type("Nelmio\ApiDocBundle\Tests\Fixtures\Model\Test")
|
||||
*/
|
||||
public $related;
|
||||
|
||||
/**
|
||||
* @Assert\Type(type="array")
|
||||
* @Assert\All({
|
||||
|
@ -489,6 +489,18 @@ number:
|
||||
|
||||
* type: DateTime
|
||||
|
||||
related:
|
||||
|
||||
* type: object (Test)
|
||||
|
||||
related[a]:
|
||||
|
||||
* type: string
|
||||
|
||||
related[b]:
|
||||
|
||||
* type: DateTime
|
||||
|
||||
|
||||
### `ANY` /z-return-selected-parsers-input ###
|
||||
|
||||
@ -536,6 +548,18 @@ objects[][b]:
|
||||
number:
|
||||
|
||||
* type: DateTime
|
||||
|
||||
related:
|
||||
|
||||
* type: object (Test)
|
||||
|
||||
related[a]:
|
||||
|
||||
* type: string
|
||||
|
||||
related[b]:
|
||||
|
||||
* type: DateTime
|
||||
MARKDOWN;
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
@ -849,6 +849,27 @@ With multiple lines.',
|
||||
'readonly' => null
|
||||
)
|
||||
)
|
||||
),
|
||||
'related' => array(
|
||||
'dataType' => 'object (Test)',
|
||||
'readonly' => false,
|
||||
'required' => false,
|
||||
'description' => '',
|
||||
'sinceVersion' => null,
|
||||
'untilVersion' => null,
|
||||
'children' => array(
|
||||
'a' => array(
|
||||
'dataType' => 'string',
|
||||
'format' => '{length: min: foo}, {not blank}',
|
||||
'required' => true,
|
||||
'readonly' => null
|
||||
),
|
||||
'b' => array(
|
||||
'dataType' => 'DateTime',
|
||||
'required' => null,
|
||||
'readonly' => null
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
'authenticationRoles' => array(),
|
||||
@ -921,6 +942,27 @@ With multiple lines.',
|
||||
'readonly' => null
|
||||
)
|
||||
)
|
||||
),
|
||||
'related' => array(
|
||||
'dataType' => 'object (Test)',
|
||||
'readonly' => false,
|
||||
'required' => false,
|
||||
'description' => '',
|
||||
'sinceVersion' => null,
|
||||
'untilVersion' => null,
|
||||
'children' => array(
|
||||
'a' => array(
|
||||
'dataType' => 'string',
|
||||
'format' => '{length: min: foo}, {not blank}',
|
||||
'required' => true,
|
||||
'readonly' => null
|
||||
),
|
||||
'b' => array(
|
||||
'dataType' => 'DateTime',
|
||||
'required' => null,
|
||||
'readonly' => null
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
'authenticationRoles' => array(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user