mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-08 18:49:26 +03:00
Merge pull request #352 from sroze/output-post-parser
Add PostParserInterface to JmsMetadataParser to get ValidatorParser found children parsed
This commit is contained in:
commit
0d1bde9f8a
@ -295,14 +295,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);
|
||||
$response = $this->generateHumanReadableTypes($response);
|
||||
|
||||
|
@ -23,7 +23,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
|
||||
@ -229,6 +229,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({
|
||||
|
@ -522,6 +522,18 @@ number:
|
||||
|
||||
* type: DateTime
|
||||
|
||||
related:
|
||||
|
||||
* type: object (Test)
|
||||
|
||||
related[a]:
|
||||
|
||||
* type: string
|
||||
|
||||
related[b]:
|
||||
|
||||
* type: DateTime
|
||||
|
||||
|
||||
### `ANY` /z-return-selected-parsers-input ###
|
||||
|
||||
@ -575,6 +587,18 @@ objects[][b]:
|
||||
number:
|
||||
|
||||
* type: DateTime
|
||||
|
||||
related:
|
||||
|
||||
* type: object (Test)
|
||||
|
||||
related[a]:
|
||||
|
||||
* type: string
|
||||
|
||||
related[b]:
|
||||
|
||||
* type: DateTime
|
||||
MARKDOWN;
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
@ -1070,6 +1070,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(),
|
||||
@ -1176,6 +1197,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