2013-02-11 14:42:17 +01:00
|
|
|
<?php
|
|
|
|
namespace NelmioApiDocBundle\Tests\Parser;
|
|
|
|
|
Unified data types [actualType and subType]
This is the result of https://github.com/nelmio/NelmioApiDocBundle/issues/410.
This PR aims to provide a uniform way of declaring data-types of parameters for
parsers and handlers to follow. In turn, this would allow formatters to
determine data-types in a cleaner and less volatile manner. (See use-case that
can be improved with this PR:
https://github.com/nelmio/NelmioApiDocBundle/blob/master/Formatter/AbstractFormatter.php#L103)
This is possible by the addition two properties to each property item in
`response`, and `parameters` fields in each API endpoint produced by the
`ApiDocExtractor`:
* `actualType` Contains a value from one of the `DataTypes` class constants.
* `subType` Can contain either `null`, or any other `DataTypes` class constant.
This is relevant when the `actualType` is a `DataTypes::COLLECTION`, wherein
`subType` would specify the type of the collection items. It is also relevant
when `actualType` is a `DataTypes::MODEL`, wherein `subType` would contain an
identifier of the model (the FQCN or anything the parser would wish to specify)
Examples:
```php
array(
'id' => array(
'dataType' => 'integer',
'actualType' => DataTypes::INTEGER,
'subType' => null,
),
'profile' => array(
'dataType' => 'object (Profile)',
'actualType' => DataTypes::MODEL,
'subType' => 'Foo\Entity\Profile',
'children' => array(
'name' => array(
'dataType' => 'string',
'actualType' => DataTypes::STRING,
'subType' => null,
),
'birthDate' => array(
'dataType' => 'date',
'actualType' => DataTypes::DATE,
'subType' => null,
),
)
),
'languages' => array(
'dataType' => 'array of strings',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::STRING,
),
'roles' => array(
'dataType' => 'array of choices',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::ENUM,
),
'groups' => array(
'dataType' => 'array of objects (Group)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Group',
),
'profileRevisions' => array(
'dataType' => 'array of objects (Profile)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Profile',
),
'address' => array(
'dataType' => 'object (a_type_a_custom_JMS_serializer_handler_handles)',
'actualType' => DataTypes::MODEL,
'subType' => 'a_type_a_custom_JMS_serializer_handler_handles',
),
);
```
When a formatter omits the `dataType` property or leaves it blank, it is
inferred within `ApiDocExtractor` before everything is passed to formatters.
2014-06-17 17:05:00 -07:00
|
|
|
use Nelmio\ApiDocBundle\DataTypes;
|
2013-02-11 14:42:17 +01:00
|
|
|
use Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsNested;
|
|
|
|
use Nelmio\ApiDocBundle\Parser\JmsMetadataParser;
|
|
|
|
use JMS\Serializer\Metadata\ClassMetadata;
|
|
|
|
use JMS\Serializer\Metadata\PropertyMetadata;
|
2013-03-25 12:28:00 +01:00
|
|
|
use JMS\Serializer\Naming\CamelCaseNamingStrategy;
|
2013-02-11 14:42:17 +01:00
|
|
|
|
|
|
|
class JmsMetadataParserTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2013-02-26 19:24:14 +01:00
|
|
|
/**
|
|
|
|
* @dataProvider dataTestParserWithNestedType
|
|
|
|
*/
|
|
|
|
public function testParserWithNestedType($type)
|
2013-02-11 14:42:17 +01:00
|
|
|
{
|
|
|
|
$metadataFactory = $this->getMock('Metadata\MetadataFactoryInterface');
|
|
|
|
$docCommentExtractor = $this->getMockBuilder('Nelmio\ApiDocBundle\Util\DocCommentExtractor')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$propertyMetadataFoo = new PropertyMetadata('Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsNested', 'foo');
|
2013-02-15 10:48:29 +01:00
|
|
|
$propertyMetadataFoo->type = array(
|
|
|
|
'name' => 'DateTime'
|
|
|
|
);
|
2013-02-11 14:42:17 +01:00
|
|
|
|
|
|
|
$propertyMetadataBar = new PropertyMetadata('Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsNested', 'bar');
|
|
|
|
$propertyMetadataBar->type = array(
|
|
|
|
'name' => 'string'
|
|
|
|
);
|
|
|
|
|
|
|
|
$propertyMetadataBaz = new PropertyMetadata('Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsNested', 'baz');
|
|
|
|
$propertyMetadataBaz->type = array(
|
2013-02-26 19:24:14 +01:00
|
|
|
'name' => $type,
|
2013-02-11 14:42:17 +01:00
|
|
|
'params' => array(
|
|
|
|
array(
|
|
|
|
'name' => 'integer',
|
|
|
|
'params' => array()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$metadata = new ClassMetadata('Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsNested');
|
|
|
|
$metadata->addPropertyMetadata($propertyMetadataFoo);
|
|
|
|
$metadata->addPropertyMetadata($propertyMetadataBar);
|
|
|
|
$metadata->addPropertyMetadata($propertyMetadataBaz);
|
|
|
|
|
2013-03-26 10:37:33 -07:00
|
|
|
$propertyNamingStrategy = $this->getMock('JMS\Serializer\Naming\PropertyNamingStrategyInterface');
|
|
|
|
|
|
|
|
$propertyNamingStrategy
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('translateName')
|
|
|
|
->will($this->returnValue('foo'));
|
|
|
|
|
|
|
|
$propertyNamingStrategy
|
|
|
|
->expects($this->at(1))
|
|
|
|
->method('translateName')
|
|
|
|
->will($this->returnValue('bar'));
|
|
|
|
|
|
|
|
$propertyNamingStrategy
|
|
|
|
->expects($this->at(2))
|
|
|
|
->method('translateName')
|
|
|
|
->will($this->returnValue('baz'));
|
|
|
|
|
2013-03-25 12:28:00 +01:00
|
|
|
$input = 'Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsNested';
|
2013-02-11 14:42:17 +01:00
|
|
|
|
|
|
|
$metadataFactory->expects($this->once())
|
|
|
|
->method('getMetadataForClass')
|
|
|
|
->with($input)
|
|
|
|
->will($this->returnValue($metadata));
|
|
|
|
|
2013-03-26 10:37:33 -07:00
|
|
|
$jmsMetadataParser = new JmsMetadataParser($metadataFactory, $propertyNamingStrategy, $docCommentExtractor);
|
2013-02-11 14:42:17 +01:00
|
|
|
|
2013-03-25 12:28:00 +01:00
|
|
|
$output = $jmsMetadataParser->parse(
|
|
|
|
array(
|
|
|
|
'class' => $input,
|
|
|
|
'groups' => array(),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
array(
|
|
|
|
'foo' => array(
|
2013-04-24 22:28:46 +02:00
|
|
|
'dataType' => 'DateTime',
|
Unified data types [actualType and subType]
This is the result of https://github.com/nelmio/NelmioApiDocBundle/issues/410.
This PR aims to provide a uniform way of declaring data-types of parameters for
parsers and handlers to follow. In turn, this would allow formatters to
determine data-types in a cleaner and less volatile manner. (See use-case that
can be improved with this PR:
https://github.com/nelmio/NelmioApiDocBundle/blob/master/Formatter/AbstractFormatter.php#L103)
This is possible by the addition two properties to each property item in
`response`, and `parameters` fields in each API endpoint produced by the
`ApiDocExtractor`:
* `actualType` Contains a value from one of the `DataTypes` class constants.
* `subType` Can contain either `null`, or any other `DataTypes` class constant.
This is relevant when the `actualType` is a `DataTypes::COLLECTION`, wherein
`subType` would specify the type of the collection items. It is also relevant
when `actualType` is a `DataTypes::MODEL`, wherein `subType` would contain an
identifier of the model (the FQCN or anything the parser would wish to specify)
Examples:
```php
array(
'id' => array(
'dataType' => 'integer',
'actualType' => DataTypes::INTEGER,
'subType' => null,
),
'profile' => array(
'dataType' => 'object (Profile)',
'actualType' => DataTypes::MODEL,
'subType' => 'Foo\Entity\Profile',
'children' => array(
'name' => array(
'dataType' => 'string',
'actualType' => DataTypes::STRING,
'subType' => null,
),
'birthDate' => array(
'dataType' => 'date',
'actualType' => DataTypes::DATE,
'subType' => null,
),
)
),
'languages' => array(
'dataType' => 'array of strings',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::STRING,
),
'roles' => array(
'dataType' => 'array of choices',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::ENUM,
),
'groups' => array(
'dataType' => 'array of objects (Group)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Group',
),
'profileRevisions' => array(
'dataType' => 'array of objects (Profile)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Profile',
),
'address' => array(
'dataType' => 'object (a_type_a_custom_JMS_serializer_handler_handles)',
'actualType' => DataTypes::MODEL,
'subType' => 'a_type_a_custom_JMS_serializer_handler_handles',
),
);
```
When a formatter omits the `dataType` property or leaves it blank, it is
inferred within `ApiDocExtractor` before everything is passed to formatters.
2014-06-17 17:05:00 -07:00
|
|
|
'actualType' => DataTypes::DATETIME,
|
|
|
|
'subType' => null,
|
2014-06-17 17:05:00 -07:00
|
|
|
'default' => null,
|
2013-04-24 22:28:46 +02:00
|
|
|
'required' => false,
|
|
|
|
'description' => null,
|
|
|
|
'readonly' => false,
|
|
|
|
'sinceVersion' => null,
|
|
|
|
'untilVersion' => null,
|
2013-03-25 12:28:00 +01:00
|
|
|
),
|
|
|
|
'bar' => array(
|
2013-04-24 22:28:46 +02:00
|
|
|
'dataType' => 'string',
|
Unified data types [actualType and subType]
This is the result of https://github.com/nelmio/NelmioApiDocBundle/issues/410.
This PR aims to provide a uniform way of declaring data-types of parameters for
parsers and handlers to follow. In turn, this would allow formatters to
determine data-types in a cleaner and less volatile manner. (See use-case that
can be improved with this PR:
https://github.com/nelmio/NelmioApiDocBundle/blob/master/Formatter/AbstractFormatter.php#L103)
This is possible by the addition two properties to each property item in
`response`, and `parameters` fields in each API endpoint produced by the
`ApiDocExtractor`:
* `actualType` Contains a value from one of the `DataTypes` class constants.
* `subType` Can contain either `null`, or any other `DataTypes` class constant.
This is relevant when the `actualType` is a `DataTypes::COLLECTION`, wherein
`subType` would specify the type of the collection items. It is also relevant
when `actualType` is a `DataTypes::MODEL`, wherein `subType` would contain an
identifier of the model (the FQCN or anything the parser would wish to specify)
Examples:
```php
array(
'id' => array(
'dataType' => 'integer',
'actualType' => DataTypes::INTEGER,
'subType' => null,
),
'profile' => array(
'dataType' => 'object (Profile)',
'actualType' => DataTypes::MODEL,
'subType' => 'Foo\Entity\Profile',
'children' => array(
'name' => array(
'dataType' => 'string',
'actualType' => DataTypes::STRING,
'subType' => null,
),
'birthDate' => array(
'dataType' => 'date',
'actualType' => DataTypes::DATE,
'subType' => null,
),
)
),
'languages' => array(
'dataType' => 'array of strings',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::STRING,
),
'roles' => array(
'dataType' => 'array of choices',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::ENUM,
),
'groups' => array(
'dataType' => 'array of objects (Group)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Group',
),
'profileRevisions' => array(
'dataType' => 'array of objects (Profile)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Profile',
),
'address' => array(
'dataType' => 'object (a_type_a_custom_JMS_serializer_handler_handles)',
'actualType' => DataTypes::MODEL,
'subType' => 'a_type_a_custom_JMS_serializer_handler_handles',
),
);
```
When a formatter omits the `dataType` property or leaves it blank, it is
inferred within `ApiDocExtractor` before everything is passed to formatters.
2014-06-17 17:05:00 -07:00
|
|
|
'actualType' => DataTypes::STRING,
|
|
|
|
'subType' => null,
|
2014-06-26 12:27:47 -07:00
|
|
|
'default' => 'baz',
|
2013-04-24 22:28:46 +02:00
|
|
|
'required' => false,
|
|
|
|
'description' => null,
|
|
|
|
'readonly' => false,
|
|
|
|
'sinceVersion' => null,
|
|
|
|
'untilVersion' => null,
|
2013-03-25 12:28:00 +01:00
|
|
|
),
|
|
|
|
'baz' => array(
|
2013-04-24 22:28:46 +02:00
|
|
|
'dataType' => 'array of integers',
|
Unified data types [actualType and subType]
This is the result of https://github.com/nelmio/NelmioApiDocBundle/issues/410.
This PR aims to provide a uniform way of declaring data-types of parameters for
parsers and handlers to follow. In turn, this would allow formatters to
determine data-types in a cleaner and less volatile manner. (See use-case that
can be improved with this PR:
https://github.com/nelmio/NelmioApiDocBundle/blob/master/Formatter/AbstractFormatter.php#L103)
This is possible by the addition two properties to each property item in
`response`, and `parameters` fields in each API endpoint produced by the
`ApiDocExtractor`:
* `actualType` Contains a value from one of the `DataTypes` class constants.
* `subType` Can contain either `null`, or any other `DataTypes` class constant.
This is relevant when the `actualType` is a `DataTypes::COLLECTION`, wherein
`subType` would specify the type of the collection items. It is also relevant
when `actualType` is a `DataTypes::MODEL`, wherein `subType` would contain an
identifier of the model (the FQCN or anything the parser would wish to specify)
Examples:
```php
array(
'id' => array(
'dataType' => 'integer',
'actualType' => DataTypes::INTEGER,
'subType' => null,
),
'profile' => array(
'dataType' => 'object (Profile)',
'actualType' => DataTypes::MODEL,
'subType' => 'Foo\Entity\Profile',
'children' => array(
'name' => array(
'dataType' => 'string',
'actualType' => DataTypes::STRING,
'subType' => null,
),
'birthDate' => array(
'dataType' => 'date',
'actualType' => DataTypes::DATE,
'subType' => null,
),
)
),
'languages' => array(
'dataType' => 'array of strings',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::STRING,
),
'roles' => array(
'dataType' => 'array of choices',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::ENUM,
),
'groups' => array(
'dataType' => 'array of objects (Group)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Group',
),
'profileRevisions' => array(
'dataType' => 'array of objects (Profile)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Profile',
),
'address' => array(
'dataType' => 'object (a_type_a_custom_JMS_serializer_handler_handles)',
'actualType' => DataTypes::MODEL,
'subType' => 'a_type_a_custom_JMS_serializer_handler_handles',
),
);
```
When a formatter omits the `dataType` property or leaves it blank, it is
inferred within `ApiDocExtractor` before everything is passed to formatters.
2014-06-17 17:05:00 -07:00
|
|
|
'actualType' => DataTypes::COLLECTION,
|
|
|
|
'subType' => DataTypes::INTEGER,
|
2014-06-17 17:05:00 -07:00
|
|
|
'default' => null,
|
2013-04-24 22:28:46 +02:00
|
|
|
'required' => false,
|
|
|
|
'description' => null,
|
|
|
|
'readonly' => false,
|
|
|
|
'sinceVersion' => null,
|
|
|
|
'untilVersion' => null,
|
2013-03-25 12:28:00 +01:00
|
|
|
)
|
|
|
|
),
|
|
|
|
$output
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testParserWithGroups()
|
|
|
|
{
|
|
|
|
$metadataFactory = $this->getMock('Metadata\MetadataFactoryInterface');
|
|
|
|
$docCommentExtractor = $this->getMockBuilder('Nelmio\ApiDocBundle\Util\DocCommentExtractor')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$propertyMetadataFoo = new PropertyMetadata('Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsNested', 'foo');
|
|
|
|
$propertyMetadataFoo->type = array('name' => 'string');
|
|
|
|
|
|
|
|
$propertyMetadataBar = new PropertyMetadata('Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsNested', 'bar');
|
|
|
|
$propertyMetadataBar->type = array('name' => 'string');
|
|
|
|
$propertyMetadataBar->groups = array('Default', 'Special');
|
|
|
|
|
|
|
|
$propertyMetadataBaz = new PropertyMetadata('Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsNested', 'baz');
|
|
|
|
$propertyMetadataBaz->type = array('name' => 'string');
|
|
|
|
$propertyMetadataBaz->groups = array('Special');
|
|
|
|
|
|
|
|
$input = 'Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsNested';
|
|
|
|
|
|
|
|
$metadata = new ClassMetadata($input);
|
|
|
|
$metadata->addPropertyMetadata($propertyMetadataFoo);
|
|
|
|
$metadata->addPropertyMetadata($propertyMetadataBar);
|
|
|
|
$metadata->addPropertyMetadata($propertyMetadataBaz);
|
|
|
|
|
|
|
|
$metadataFactory->expects($this->any())
|
|
|
|
->method('getMetadataForClass')
|
|
|
|
->with($input)
|
|
|
|
->will($this->returnValue($metadata));
|
|
|
|
|
|
|
|
$propertyNamingStrategy = new CamelCaseNamingStrategy();
|
|
|
|
|
|
|
|
$jmsMetadataParser = new JmsMetadataParser($metadataFactory, $propertyNamingStrategy, $docCommentExtractor);
|
|
|
|
|
|
|
|
// No group specified.
|
|
|
|
$output = $jmsMetadataParser->parse(
|
|
|
|
array(
|
|
|
|
'class' => $input,
|
|
|
|
'groups' => array(),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
array(
|
|
|
|
'foo' => array(
|
2013-04-24 22:28:46 +02:00
|
|
|
'dataType' => 'string',
|
Unified data types [actualType and subType]
This is the result of https://github.com/nelmio/NelmioApiDocBundle/issues/410.
This PR aims to provide a uniform way of declaring data-types of parameters for
parsers and handlers to follow. In turn, this would allow formatters to
determine data-types in a cleaner and less volatile manner. (See use-case that
can be improved with this PR:
https://github.com/nelmio/NelmioApiDocBundle/blob/master/Formatter/AbstractFormatter.php#L103)
This is possible by the addition two properties to each property item in
`response`, and `parameters` fields in each API endpoint produced by the
`ApiDocExtractor`:
* `actualType` Contains a value from one of the `DataTypes` class constants.
* `subType` Can contain either `null`, or any other `DataTypes` class constant.
This is relevant when the `actualType` is a `DataTypes::COLLECTION`, wherein
`subType` would specify the type of the collection items. It is also relevant
when `actualType` is a `DataTypes::MODEL`, wherein `subType` would contain an
identifier of the model (the FQCN or anything the parser would wish to specify)
Examples:
```php
array(
'id' => array(
'dataType' => 'integer',
'actualType' => DataTypes::INTEGER,
'subType' => null,
),
'profile' => array(
'dataType' => 'object (Profile)',
'actualType' => DataTypes::MODEL,
'subType' => 'Foo\Entity\Profile',
'children' => array(
'name' => array(
'dataType' => 'string',
'actualType' => DataTypes::STRING,
'subType' => null,
),
'birthDate' => array(
'dataType' => 'date',
'actualType' => DataTypes::DATE,
'subType' => null,
),
)
),
'languages' => array(
'dataType' => 'array of strings',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::STRING,
),
'roles' => array(
'dataType' => 'array of choices',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::ENUM,
),
'groups' => array(
'dataType' => 'array of objects (Group)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Group',
),
'profileRevisions' => array(
'dataType' => 'array of objects (Profile)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Profile',
),
'address' => array(
'dataType' => 'object (a_type_a_custom_JMS_serializer_handler_handles)',
'actualType' => DataTypes::MODEL,
'subType' => 'a_type_a_custom_JMS_serializer_handler_handles',
),
);
```
When a formatter omits the `dataType` property or leaves it blank, it is
inferred within `ApiDocExtractor` before everything is passed to formatters.
2014-06-17 17:05:00 -07:00
|
|
|
'actualType' => DataTypes::STRING,
|
|
|
|
'subType' => null,
|
2014-06-17 17:05:00 -07:00
|
|
|
'default' => null,
|
2013-04-24 22:28:46 +02:00
|
|
|
'required' => false,
|
|
|
|
'description' => null,
|
|
|
|
'readonly' => false,
|
|
|
|
'sinceVersion' => null,
|
|
|
|
'untilVersion' => null,
|
2013-03-25 12:28:00 +01:00
|
|
|
),
|
|
|
|
'bar' => array(
|
2013-04-24 22:28:46 +02:00
|
|
|
'dataType' => 'string',
|
Unified data types [actualType and subType]
This is the result of https://github.com/nelmio/NelmioApiDocBundle/issues/410.
This PR aims to provide a uniform way of declaring data-types of parameters for
parsers and handlers to follow. In turn, this would allow formatters to
determine data-types in a cleaner and less volatile manner. (See use-case that
can be improved with this PR:
https://github.com/nelmio/NelmioApiDocBundle/blob/master/Formatter/AbstractFormatter.php#L103)
This is possible by the addition two properties to each property item in
`response`, and `parameters` fields in each API endpoint produced by the
`ApiDocExtractor`:
* `actualType` Contains a value from one of the `DataTypes` class constants.
* `subType` Can contain either `null`, or any other `DataTypes` class constant.
This is relevant when the `actualType` is a `DataTypes::COLLECTION`, wherein
`subType` would specify the type of the collection items. It is also relevant
when `actualType` is a `DataTypes::MODEL`, wherein `subType` would contain an
identifier of the model (the FQCN or anything the parser would wish to specify)
Examples:
```php
array(
'id' => array(
'dataType' => 'integer',
'actualType' => DataTypes::INTEGER,
'subType' => null,
),
'profile' => array(
'dataType' => 'object (Profile)',
'actualType' => DataTypes::MODEL,
'subType' => 'Foo\Entity\Profile',
'children' => array(
'name' => array(
'dataType' => 'string',
'actualType' => DataTypes::STRING,
'subType' => null,
),
'birthDate' => array(
'dataType' => 'date',
'actualType' => DataTypes::DATE,
'subType' => null,
),
)
),
'languages' => array(
'dataType' => 'array of strings',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::STRING,
),
'roles' => array(
'dataType' => 'array of choices',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::ENUM,
),
'groups' => array(
'dataType' => 'array of objects (Group)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Group',
),
'profileRevisions' => array(
'dataType' => 'array of objects (Profile)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Profile',
),
'address' => array(
'dataType' => 'object (a_type_a_custom_JMS_serializer_handler_handles)',
'actualType' => DataTypes::MODEL,
'subType' => 'a_type_a_custom_JMS_serializer_handler_handles',
),
);
```
When a formatter omits the `dataType` property or leaves it blank, it is
inferred within `ApiDocExtractor` before everything is passed to formatters.
2014-06-17 17:05:00 -07:00
|
|
|
'actualType' => DataTypes::STRING,
|
|
|
|
'subType' => null,
|
2014-06-26 12:27:47 -07:00
|
|
|
'default' => 'baz',
|
2013-04-24 22:28:46 +02:00
|
|
|
'required' => false,
|
|
|
|
'description' => null,
|
|
|
|
'readonly' => false,
|
|
|
|
'sinceVersion' => null,
|
|
|
|
'untilVersion' => null,
|
2013-03-25 12:28:00 +01:00
|
|
|
),
|
2013-12-20 12:58:34 +01:00
|
|
|
'baz' => array(
|
|
|
|
'dataType' => 'string',
|
Unified data types [actualType and subType]
This is the result of https://github.com/nelmio/NelmioApiDocBundle/issues/410.
This PR aims to provide a uniform way of declaring data-types of parameters for
parsers and handlers to follow. In turn, this would allow formatters to
determine data-types in a cleaner and less volatile manner. (See use-case that
can be improved with this PR:
https://github.com/nelmio/NelmioApiDocBundle/blob/master/Formatter/AbstractFormatter.php#L103)
This is possible by the addition two properties to each property item in
`response`, and `parameters` fields in each API endpoint produced by the
`ApiDocExtractor`:
* `actualType` Contains a value from one of the `DataTypes` class constants.
* `subType` Can contain either `null`, or any other `DataTypes` class constant.
This is relevant when the `actualType` is a `DataTypes::COLLECTION`, wherein
`subType` would specify the type of the collection items. It is also relevant
when `actualType` is a `DataTypes::MODEL`, wherein `subType` would contain an
identifier of the model (the FQCN or anything the parser would wish to specify)
Examples:
```php
array(
'id' => array(
'dataType' => 'integer',
'actualType' => DataTypes::INTEGER,
'subType' => null,
),
'profile' => array(
'dataType' => 'object (Profile)',
'actualType' => DataTypes::MODEL,
'subType' => 'Foo\Entity\Profile',
'children' => array(
'name' => array(
'dataType' => 'string',
'actualType' => DataTypes::STRING,
'subType' => null,
),
'birthDate' => array(
'dataType' => 'date',
'actualType' => DataTypes::DATE,
'subType' => null,
),
)
),
'languages' => array(
'dataType' => 'array of strings',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::STRING,
),
'roles' => array(
'dataType' => 'array of choices',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::ENUM,
),
'groups' => array(
'dataType' => 'array of objects (Group)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Group',
),
'profileRevisions' => array(
'dataType' => 'array of objects (Profile)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Profile',
),
'address' => array(
'dataType' => 'object (a_type_a_custom_JMS_serializer_handler_handles)',
'actualType' => DataTypes::MODEL,
'subType' => 'a_type_a_custom_JMS_serializer_handler_handles',
),
);
```
When a formatter omits the `dataType` property or leaves it blank, it is
inferred within `ApiDocExtractor` before everything is passed to formatters.
2014-06-17 17:05:00 -07:00
|
|
|
'actualType' => DataTypes::STRING,
|
|
|
|
'subType' => null,
|
2014-06-17 17:05:00 -07:00
|
|
|
'default' => null,
|
2013-12-20 12:58:34 +01:00
|
|
|
'required' => false,
|
|
|
|
'description' => null,
|
|
|
|
'readonly' => false,
|
|
|
|
'sinceVersion' => null,
|
|
|
|
'untilVersion' => null,
|
|
|
|
),
|
2013-03-25 12:28:00 +01:00
|
|
|
),
|
|
|
|
$output
|
|
|
|
);
|
|
|
|
|
|
|
|
// Default group.
|
|
|
|
$output = $jmsMetadataParser->parse(
|
|
|
|
array(
|
|
|
|
'class' => $input,
|
|
|
|
'groups' => array('Default'),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
array(
|
|
|
|
'foo' => array(
|
2013-04-24 22:28:46 +02:00
|
|
|
'dataType' => 'string',
|
Unified data types [actualType and subType]
This is the result of https://github.com/nelmio/NelmioApiDocBundle/issues/410.
This PR aims to provide a uniform way of declaring data-types of parameters for
parsers and handlers to follow. In turn, this would allow formatters to
determine data-types in a cleaner and less volatile manner. (See use-case that
can be improved with this PR:
https://github.com/nelmio/NelmioApiDocBundle/blob/master/Formatter/AbstractFormatter.php#L103)
This is possible by the addition two properties to each property item in
`response`, and `parameters` fields in each API endpoint produced by the
`ApiDocExtractor`:
* `actualType` Contains a value from one of the `DataTypes` class constants.
* `subType` Can contain either `null`, or any other `DataTypes` class constant.
This is relevant when the `actualType` is a `DataTypes::COLLECTION`, wherein
`subType` would specify the type of the collection items. It is also relevant
when `actualType` is a `DataTypes::MODEL`, wherein `subType` would contain an
identifier of the model (the FQCN or anything the parser would wish to specify)
Examples:
```php
array(
'id' => array(
'dataType' => 'integer',
'actualType' => DataTypes::INTEGER,
'subType' => null,
),
'profile' => array(
'dataType' => 'object (Profile)',
'actualType' => DataTypes::MODEL,
'subType' => 'Foo\Entity\Profile',
'children' => array(
'name' => array(
'dataType' => 'string',
'actualType' => DataTypes::STRING,
'subType' => null,
),
'birthDate' => array(
'dataType' => 'date',
'actualType' => DataTypes::DATE,
'subType' => null,
),
)
),
'languages' => array(
'dataType' => 'array of strings',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::STRING,
),
'roles' => array(
'dataType' => 'array of choices',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::ENUM,
),
'groups' => array(
'dataType' => 'array of objects (Group)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Group',
),
'profileRevisions' => array(
'dataType' => 'array of objects (Profile)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Profile',
),
'address' => array(
'dataType' => 'object (a_type_a_custom_JMS_serializer_handler_handles)',
'actualType' => DataTypes::MODEL,
'subType' => 'a_type_a_custom_JMS_serializer_handler_handles',
),
);
```
When a formatter omits the `dataType` property or leaves it blank, it is
inferred within `ApiDocExtractor` before everything is passed to formatters.
2014-06-17 17:05:00 -07:00
|
|
|
'actualType' => DataTypes::STRING,
|
|
|
|
'subType' => null,
|
2014-06-17 17:05:00 -07:00
|
|
|
'default' => null,
|
2013-04-24 22:28:46 +02:00
|
|
|
'required' => false,
|
|
|
|
'description' => null,
|
|
|
|
'readonly' => false,
|
|
|
|
'sinceVersion' => null,
|
|
|
|
'untilVersion' => null,
|
2013-03-25 12:28:00 +01:00
|
|
|
),
|
|
|
|
'bar' => array(
|
2013-04-24 22:28:46 +02:00
|
|
|
'dataType' => 'string',
|
Unified data types [actualType and subType]
This is the result of https://github.com/nelmio/NelmioApiDocBundle/issues/410.
This PR aims to provide a uniform way of declaring data-types of parameters for
parsers and handlers to follow. In turn, this would allow formatters to
determine data-types in a cleaner and less volatile manner. (See use-case that
can be improved with this PR:
https://github.com/nelmio/NelmioApiDocBundle/blob/master/Formatter/AbstractFormatter.php#L103)
This is possible by the addition two properties to each property item in
`response`, and `parameters` fields in each API endpoint produced by the
`ApiDocExtractor`:
* `actualType` Contains a value from one of the `DataTypes` class constants.
* `subType` Can contain either `null`, or any other `DataTypes` class constant.
This is relevant when the `actualType` is a `DataTypes::COLLECTION`, wherein
`subType` would specify the type of the collection items. It is also relevant
when `actualType` is a `DataTypes::MODEL`, wherein `subType` would contain an
identifier of the model (the FQCN or anything the parser would wish to specify)
Examples:
```php
array(
'id' => array(
'dataType' => 'integer',
'actualType' => DataTypes::INTEGER,
'subType' => null,
),
'profile' => array(
'dataType' => 'object (Profile)',
'actualType' => DataTypes::MODEL,
'subType' => 'Foo\Entity\Profile',
'children' => array(
'name' => array(
'dataType' => 'string',
'actualType' => DataTypes::STRING,
'subType' => null,
),
'birthDate' => array(
'dataType' => 'date',
'actualType' => DataTypes::DATE,
'subType' => null,
),
)
),
'languages' => array(
'dataType' => 'array of strings',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::STRING,
),
'roles' => array(
'dataType' => 'array of choices',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::ENUM,
),
'groups' => array(
'dataType' => 'array of objects (Group)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Group',
),
'profileRevisions' => array(
'dataType' => 'array of objects (Profile)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Profile',
),
'address' => array(
'dataType' => 'object (a_type_a_custom_JMS_serializer_handler_handles)',
'actualType' => DataTypes::MODEL,
'subType' => 'a_type_a_custom_JMS_serializer_handler_handles',
),
);
```
When a formatter omits the `dataType` property or leaves it blank, it is
inferred within `ApiDocExtractor` before everything is passed to formatters.
2014-06-17 17:05:00 -07:00
|
|
|
'actualType' => DataTypes::STRING,
|
|
|
|
'subType' => null,
|
2014-06-26 12:27:47 -07:00
|
|
|
'default' => 'baz',
|
2013-04-24 22:28:46 +02:00
|
|
|
'required' => false,
|
|
|
|
'description' => null,
|
|
|
|
'readonly' => false,
|
|
|
|
'sinceVersion' => null,
|
|
|
|
'untilVersion' => null,
|
2013-03-25 12:28:00 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
$output
|
|
|
|
);
|
|
|
|
|
|
|
|
// Special group.
|
|
|
|
$output = $jmsMetadataParser->parse(
|
|
|
|
array(
|
|
|
|
'class' => $input,
|
|
|
|
'groups' => array('Special'),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
array(
|
|
|
|
'bar' => array(
|
2013-04-24 22:28:46 +02:00
|
|
|
'dataType' => 'string',
|
Unified data types [actualType and subType]
This is the result of https://github.com/nelmio/NelmioApiDocBundle/issues/410.
This PR aims to provide a uniform way of declaring data-types of parameters for
parsers and handlers to follow. In turn, this would allow formatters to
determine data-types in a cleaner and less volatile manner. (See use-case that
can be improved with this PR:
https://github.com/nelmio/NelmioApiDocBundle/blob/master/Formatter/AbstractFormatter.php#L103)
This is possible by the addition two properties to each property item in
`response`, and `parameters` fields in each API endpoint produced by the
`ApiDocExtractor`:
* `actualType` Contains a value from one of the `DataTypes` class constants.
* `subType` Can contain either `null`, or any other `DataTypes` class constant.
This is relevant when the `actualType` is a `DataTypes::COLLECTION`, wherein
`subType` would specify the type of the collection items. It is also relevant
when `actualType` is a `DataTypes::MODEL`, wherein `subType` would contain an
identifier of the model (the FQCN or anything the parser would wish to specify)
Examples:
```php
array(
'id' => array(
'dataType' => 'integer',
'actualType' => DataTypes::INTEGER,
'subType' => null,
),
'profile' => array(
'dataType' => 'object (Profile)',
'actualType' => DataTypes::MODEL,
'subType' => 'Foo\Entity\Profile',
'children' => array(
'name' => array(
'dataType' => 'string',
'actualType' => DataTypes::STRING,
'subType' => null,
),
'birthDate' => array(
'dataType' => 'date',
'actualType' => DataTypes::DATE,
'subType' => null,
),
)
),
'languages' => array(
'dataType' => 'array of strings',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::STRING,
),
'roles' => array(
'dataType' => 'array of choices',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::ENUM,
),
'groups' => array(
'dataType' => 'array of objects (Group)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Group',
),
'profileRevisions' => array(
'dataType' => 'array of objects (Profile)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Profile',
),
'address' => array(
'dataType' => 'object (a_type_a_custom_JMS_serializer_handler_handles)',
'actualType' => DataTypes::MODEL,
'subType' => 'a_type_a_custom_JMS_serializer_handler_handles',
),
);
```
When a formatter omits the `dataType` property or leaves it blank, it is
inferred within `ApiDocExtractor` before everything is passed to formatters.
2014-06-17 17:05:00 -07:00
|
|
|
'actualType' => DataTypes::STRING,
|
|
|
|
'subType' => null,
|
2014-06-26 12:27:47 -07:00
|
|
|
'default' => 'baz',
|
2013-04-24 22:28:46 +02:00
|
|
|
'required' => false,
|
|
|
|
'description' => null,
|
|
|
|
'readonly' => false,
|
|
|
|
'sinceVersion' => null,
|
|
|
|
'untilVersion' => null,
|
2013-03-25 12:28:00 +01:00
|
|
|
),
|
|
|
|
'baz' => array(
|
2013-04-24 22:28:46 +02:00
|
|
|
'dataType' => 'string',
|
Unified data types [actualType and subType]
This is the result of https://github.com/nelmio/NelmioApiDocBundle/issues/410.
This PR aims to provide a uniform way of declaring data-types of parameters for
parsers and handlers to follow. In turn, this would allow formatters to
determine data-types in a cleaner and less volatile manner. (See use-case that
can be improved with this PR:
https://github.com/nelmio/NelmioApiDocBundle/blob/master/Formatter/AbstractFormatter.php#L103)
This is possible by the addition two properties to each property item in
`response`, and `parameters` fields in each API endpoint produced by the
`ApiDocExtractor`:
* `actualType` Contains a value from one of the `DataTypes` class constants.
* `subType` Can contain either `null`, or any other `DataTypes` class constant.
This is relevant when the `actualType` is a `DataTypes::COLLECTION`, wherein
`subType` would specify the type of the collection items. It is also relevant
when `actualType` is a `DataTypes::MODEL`, wherein `subType` would contain an
identifier of the model (the FQCN or anything the parser would wish to specify)
Examples:
```php
array(
'id' => array(
'dataType' => 'integer',
'actualType' => DataTypes::INTEGER,
'subType' => null,
),
'profile' => array(
'dataType' => 'object (Profile)',
'actualType' => DataTypes::MODEL,
'subType' => 'Foo\Entity\Profile',
'children' => array(
'name' => array(
'dataType' => 'string',
'actualType' => DataTypes::STRING,
'subType' => null,
),
'birthDate' => array(
'dataType' => 'date',
'actualType' => DataTypes::DATE,
'subType' => null,
),
)
),
'languages' => array(
'dataType' => 'array of strings',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::STRING,
),
'roles' => array(
'dataType' => 'array of choices',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::ENUM,
),
'groups' => array(
'dataType' => 'array of objects (Group)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Group',
),
'profileRevisions' => array(
'dataType' => 'array of objects (Profile)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Profile',
),
'address' => array(
'dataType' => 'object (a_type_a_custom_JMS_serializer_handler_handles)',
'actualType' => DataTypes::MODEL,
'subType' => 'a_type_a_custom_JMS_serializer_handler_handles',
),
);
```
When a formatter omits the `dataType` property or leaves it blank, it is
inferred within `ApiDocExtractor` before everything is passed to formatters.
2014-06-17 17:05:00 -07:00
|
|
|
'actualType' => DataTypes::STRING,
|
|
|
|
'subType' => null,
|
2014-06-17 17:05:00 -07:00
|
|
|
'default' => null,
|
2013-04-24 22:28:46 +02:00
|
|
|
'required' => false,
|
|
|
|
'description' => null,
|
|
|
|
'readonly' => false,
|
|
|
|
'sinceVersion' => null,
|
|
|
|
'untilVersion' => null,
|
2013-03-25 12:28:00 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
$output
|
|
|
|
);
|
2013-02-11 14:42:17 +01:00
|
|
|
|
2013-03-25 12:28:00 +01:00
|
|
|
// Default + Special groups.
|
|
|
|
$output = $jmsMetadataParser->parse(
|
|
|
|
array(
|
|
|
|
'class' => $input,
|
|
|
|
'groups' => array('Default', 'Special'),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
array(
|
|
|
|
'foo' => array(
|
2013-04-24 22:28:46 +02:00
|
|
|
'dataType' => 'string',
|
Unified data types [actualType and subType]
This is the result of https://github.com/nelmio/NelmioApiDocBundle/issues/410.
This PR aims to provide a uniform way of declaring data-types of parameters for
parsers and handlers to follow. In turn, this would allow formatters to
determine data-types in a cleaner and less volatile manner. (See use-case that
can be improved with this PR:
https://github.com/nelmio/NelmioApiDocBundle/blob/master/Formatter/AbstractFormatter.php#L103)
This is possible by the addition two properties to each property item in
`response`, and `parameters` fields in each API endpoint produced by the
`ApiDocExtractor`:
* `actualType` Contains a value from one of the `DataTypes` class constants.
* `subType` Can contain either `null`, or any other `DataTypes` class constant.
This is relevant when the `actualType` is a `DataTypes::COLLECTION`, wherein
`subType` would specify the type of the collection items. It is also relevant
when `actualType` is a `DataTypes::MODEL`, wherein `subType` would contain an
identifier of the model (the FQCN or anything the parser would wish to specify)
Examples:
```php
array(
'id' => array(
'dataType' => 'integer',
'actualType' => DataTypes::INTEGER,
'subType' => null,
),
'profile' => array(
'dataType' => 'object (Profile)',
'actualType' => DataTypes::MODEL,
'subType' => 'Foo\Entity\Profile',
'children' => array(
'name' => array(
'dataType' => 'string',
'actualType' => DataTypes::STRING,
'subType' => null,
),
'birthDate' => array(
'dataType' => 'date',
'actualType' => DataTypes::DATE,
'subType' => null,
),
)
),
'languages' => array(
'dataType' => 'array of strings',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::STRING,
),
'roles' => array(
'dataType' => 'array of choices',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::ENUM,
),
'groups' => array(
'dataType' => 'array of objects (Group)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Group',
),
'profileRevisions' => array(
'dataType' => 'array of objects (Profile)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Profile',
),
'address' => array(
'dataType' => 'object (a_type_a_custom_JMS_serializer_handler_handles)',
'actualType' => DataTypes::MODEL,
'subType' => 'a_type_a_custom_JMS_serializer_handler_handles',
),
);
```
When a formatter omits the `dataType` property or leaves it blank, it is
inferred within `ApiDocExtractor` before everything is passed to formatters.
2014-06-17 17:05:00 -07:00
|
|
|
'actualType' => DataTypes::STRING,
|
|
|
|
'subType' => null,
|
2014-06-17 17:05:00 -07:00
|
|
|
'default' => null,
|
2013-04-24 22:28:46 +02:00
|
|
|
'required' => false,
|
|
|
|
'description' => null,
|
|
|
|
'readonly' => false,
|
|
|
|
'sinceVersion' => null,
|
|
|
|
'untilVersion' => null,
|
2013-03-25 12:28:00 +01:00
|
|
|
),
|
|
|
|
'bar' => array(
|
2013-04-24 22:28:46 +02:00
|
|
|
'dataType' => 'string',
|
Unified data types [actualType and subType]
This is the result of https://github.com/nelmio/NelmioApiDocBundle/issues/410.
This PR aims to provide a uniform way of declaring data-types of parameters for
parsers and handlers to follow. In turn, this would allow formatters to
determine data-types in a cleaner and less volatile manner. (See use-case that
can be improved with this PR:
https://github.com/nelmio/NelmioApiDocBundle/blob/master/Formatter/AbstractFormatter.php#L103)
This is possible by the addition two properties to each property item in
`response`, and `parameters` fields in each API endpoint produced by the
`ApiDocExtractor`:
* `actualType` Contains a value from one of the `DataTypes` class constants.
* `subType` Can contain either `null`, or any other `DataTypes` class constant.
This is relevant when the `actualType` is a `DataTypes::COLLECTION`, wherein
`subType` would specify the type of the collection items. It is also relevant
when `actualType` is a `DataTypes::MODEL`, wherein `subType` would contain an
identifier of the model (the FQCN or anything the parser would wish to specify)
Examples:
```php
array(
'id' => array(
'dataType' => 'integer',
'actualType' => DataTypes::INTEGER,
'subType' => null,
),
'profile' => array(
'dataType' => 'object (Profile)',
'actualType' => DataTypes::MODEL,
'subType' => 'Foo\Entity\Profile',
'children' => array(
'name' => array(
'dataType' => 'string',
'actualType' => DataTypes::STRING,
'subType' => null,
),
'birthDate' => array(
'dataType' => 'date',
'actualType' => DataTypes::DATE,
'subType' => null,
),
)
),
'languages' => array(
'dataType' => 'array of strings',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::STRING,
),
'roles' => array(
'dataType' => 'array of choices',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::ENUM,
),
'groups' => array(
'dataType' => 'array of objects (Group)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Group',
),
'profileRevisions' => array(
'dataType' => 'array of objects (Profile)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Profile',
),
'address' => array(
'dataType' => 'object (a_type_a_custom_JMS_serializer_handler_handles)',
'actualType' => DataTypes::MODEL,
'subType' => 'a_type_a_custom_JMS_serializer_handler_handles',
),
);
```
When a formatter omits the `dataType` property or leaves it blank, it is
inferred within `ApiDocExtractor` before everything is passed to formatters.
2014-06-17 17:05:00 -07:00
|
|
|
'actualType' => DataTypes::STRING,
|
|
|
|
'subType' => null,
|
2014-06-26 12:27:47 -07:00
|
|
|
'default' => 'baz',
|
2013-04-24 22:28:46 +02:00
|
|
|
'required' => false,
|
|
|
|
'description' => null,
|
|
|
|
'readonly' => false,
|
|
|
|
'sinceVersion' => null,
|
|
|
|
'untilVersion' => null,
|
2013-03-25 12:28:00 +01:00
|
|
|
),
|
|
|
|
'baz' => array(
|
2013-04-24 22:28:46 +02:00
|
|
|
'dataType' => 'string',
|
Unified data types [actualType and subType]
This is the result of https://github.com/nelmio/NelmioApiDocBundle/issues/410.
This PR aims to provide a uniform way of declaring data-types of parameters for
parsers and handlers to follow. In turn, this would allow formatters to
determine data-types in a cleaner and less volatile manner. (See use-case that
can be improved with this PR:
https://github.com/nelmio/NelmioApiDocBundle/blob/master/Formatter/AbstractFormatter.php#L103)
This is possible by the addition two properties to each property item in
`response`, and `parameters` fields in each API endpoint produced by the
`ApiDocExtractor`:
* `actualType` Contains a value from one of the `DataTypes` class constants.
* `subType` Can contain either `null`, or any other `DataTypes` class constant.
This is relevant when the `actualType` is a `DataTypes::COLLECTION`, wherein
`subType` would specify the type of the collection items. It is also relevant
when `actualType` is a `DataTypes::MODEL`, wherein `subType` would contain an
identifier of the model (the FQCN or anything the parser would wish to specify)
Examples:
```php
array(
'id' => array(
'dataType' => 'integer',
'actualType' => DataTypes::INTEGER,
'subType' => null,
),
'profile' => array(
'dataType' => 'object (Profile)',
'actualType' => DataTypes::MODEL,
'subType' => 'Foo\Entity\Profile',
'children' => array(
'name' => array(
'dataType' => 'string',
'actualType' => DataTypes::STRING,
'subType' => null,
),
'birthDate' => array(
'dataType' => 'date',
'actualType' => DataTypes::DATE,
'subType' => null,
),
)
),
'languages' => array(
'dataType' => 'array of strings',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::STRING,
),
'roles' => array(
'dataType' => 'array of choices',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::ENUM,
),
'groups' => array(
'dataType' => 'array of objects (Group)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Group',
),
'profileRevisions' => array(
'dataType' => 'array of objects (Profile)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Profile',
),
'address' => array(
'dataType' => 'object (a_type_a_custom_JMS_serializer_handler_handles)',
'actualType' => DataTypes::MODEL,
'subType' => 'a_type_a_custom_JMS_serializer_handler_handles',
),
);
```
When a formatter omits the `dataType` property or leaves it blank, it is
inferred within `ApiDocExtractor` before everything is passed to formatters.
2014-06-17 17:05:00 -07:00
|
|
|
'actualType' => DataTypes::STRING,
|
|
|
|
'subType' => null,
|
2014-06-17 17:05:00 -07:00
|
|
|
'default' => null,
|
2013-04-24 22:28:46 +02:00
|
|
|
'required' => false,
|
|
|
|
'description' => null,
|
|
|
|
'readonly' => false,
|
|
|
|
'sinceVersion' => null,
|
|
|
|
'untilVersion' => null,
|
2013-03-25 12:28:00 +01:00
|
|
|
)
|
2013-02-11 14:42:17 +01:00
|
|
|
),
|
2013-03-25 12:28:00 +01:00
|
|
|
$output
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-08-08 12:49:24 +02:00
|
|
|
public function testNestedGroups()
|
|
|
|
{
|
|
|
|
$metadataFactory = $this->getMock('Metadata\MetadataFactoryInterface');
|
|
|
|
$docCommentExtractor = $this->getMockBuilder('Nelmio\ApiDocBundle\Util\DocCommentExtractor')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$input = 'Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsNested';
|
|
|
|
$nestedInput = 'Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsTest';
|
|
|
|
|
|
|
|
$nestedPropertyMetadataHidden = new PropertyMetadata($nestedInput, 'hidden');
|
|
|
|
$nestedPropertyMetadataHidden->type = array('name' => 'string');
|
|
|
|
$nestedPropertyMetadataHidden->groups = array('hidden');
|
|
|
|
|
|
|
|
$nestedPropertyMetadataFoo = new PropertyMetadata($nestedInput, 'foo');
|
|
|
|
$nestedPropertyMetadataFoo->type = array('name' => 'string');
|
|
|
|
|
|
|
|
$nestedMetadata = new ClassMetadata($nestedInput);
|
|
|
|
$nestedMetadata->addPropertyMetadata($nestedPropertyMetadataHidden);
|
|
|
|
$nestedMetadata->addPropertyMetadata($nestedPropertyMetadataFoo);
|
|
|
|
|
|
|
|
$propertyMetadataFoo = new PropertyMetadata($input, 'foo');
|
|
|
|
$propertyMetadataFoo->type = array('name' => 'string');
|
|
|
|
|
|
|
|
$propertyMetadataBar = new PropertyMetadata($input, 'bar');
|
|
|
|
$propertyMetadataBar->type = array('name' => 'string');
|
|
|
|
$propertyMetadataBar->groups = array('Default');
|
|
|
|
|
|
|
|
$propertyMetadataParent = new PropertyMetadata($input, 'parent');
|
|
|
|
$propertyMetadataParent->type = array('name' => $nestedInput);
|
|
|
|
$propertyMetadataParent->groups = array('hidden');
|
|
|
|
|
|
|
|
$metadata = new ClassMetadata($input);
|
|
|
|
$metadata->addPropertyMetadata($propertyMetadataFoo);
|
|
|
|
$metadata->addPropertyMetadata($propertyMetadataBar);
|
|
|
|
$metadata->addPropertyMetadata($propertyMetadataParent);
|
|
|
|
|
|
|
|
$metadataFactory->expects($this->any())
|
|
|
|
->method('getMetadataForClass')
|
|
|
|
->will($this->returnValueMap(array(
|
|
|
|
array($input, $metadata),
|
|
|
|
array($nestedInput, $nestedMetadata)
|
|
|
|
)));
|
|
|
|
|
|
|
|
$propertyNamingStrategy = new CamelCaseNamingStrategy();
|
|
|
|
$jmsMetadataParser = new JmsMetadataParser($metadataFactory, $propertyNamingStrategy, $docCommentExtractor);
|
|
|
|
|
|
|
|
// No group specified.
|
|
|
|
$output = $jmsMetadataParser->parse(
|
|
|
|
array(
|
|
|
|
'class' => $input,
|
|
|
|
'groups' => array('hidden'),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
array(
|
|
|
|
'parent' => array(
|
|
|
|
'dataType' => 'object (JmsTest)',
|
|
|
|
'actualType' => DataTypes::MODEL,
|
|
|
|
'subType' => $nestedInput,
|
|
|
|
'default' => null,
|
|
|
|
'required' => false,
|
|
|
|
'description' => null,
|
|
|
|
'readonly' => false,
|
|
|
|
'sinceVersion' => null,
|
|
|
|
'untilVersion' => null,
|
|
|
|
'class' => $nestedInput,
|
|
|
|
'children' => array(
|
|
|
|
'hidden' => array(
|
|
|
|
'dataType' => 'string',
|
|
|
|
'actualType' => 'string',
|
|
|
|
'subType' => null,
|
|
|
|
'required' => false,
|
|
|
|
'default' => null,
|
|
|
|
'description' => null,
|
|
|
|
'readonly' => false,
|
|
|
|
'sinceVersion' => null,
|
|
|
|
'untilVersion' => null
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
$output
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-03-25 12:28:00 +01:00
|
|
|
public function testParserWithVersion()
|
|
|
|
{
|
|
|
|
$metadataFactory = $this->getMock('Metadata\MetadataFactoryInterface');
|
|
|
|
$docCommentExtractor = $this->getMockBuilder('Nelmio\ApiDocBundle\Util\DocCommentExtractor')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$propertyMetadataFoo = new PropertyMetadata('Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsNested', 'foo');
|
|
|
|
$propertyMetadataFoo->type = array('name' => 'string');
|
|
|
|
|
|
|
|
$propertyMetadataBar = new PropertyMetadata('Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsNested', 'bar');
|
|
|
|
$propertyMetadataBar->type = array('name' => 'string');
|
2013-04-24 22:28:46 +02:00
|
|
|
$propertyMetadataBar->sinceVersion = '2.0';
|
|
|
|
|
|
|
|
$propertyMetadataBaz = new PropertyMetadata('Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsNested', 'baz');
|
|
|
|
$propertyMetadataBaz->type = array('name' => 'string');
|
|
|
|
$propertyMetadataBaz->untilVersion = '3.0';
|
2013-03-25 12:28:00 +01:00
|
|
|
|
|
|
|
$input = 'Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsNested';
|
|
|
|
|
|
|
|
$metadata = new ClassMetadata($input);
|
|
|
|
$metadata->addPropertyMetadata($propertyMetadataFoo);
|
|
|
|
$metadata->addPropertyMetadata($propertyMetadataBar);
|
2013-04-24 22:28:46 +02:00
|
|
|
$metadata->addPropertyMetadata($propertyMetadataBaz);
|
2013-03-25 12:28:00 +01:00
|
|
|
|
|
|
|
$metadataFactory->expects($this->any())
|
|
|
|
->method('getMetadataForClass')
|
|
|
|
->with($input)
|
|
|
|
->will($this->returnValue($metadata));
|
|
|
|
|
|
|
|
$propertyNamingStrategy = new CamelCaseNamingStrategy();
|
|
|
|
|
|
|
|
$jmsMetadataParser = new JmsMetadataParser($metadataFactory, $propertyNamingStrategy, $docCommentExtractor);
|
|
|
|
|
2013-04-24 22:28:46 +02:00
|
|
|
// No group specified.
|
2013-03-25 12:28:00 +01:00
|
|
|
$output = $jmsMetadataParser->parse(
|
|
|
|
array(
|
|
|
|
'class' => $input,
|
|
|
|
'groups' => array(),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
array(
|
|
|
|
'foo' => array(
|
Unified data types [actualType and subType]
This is the result of https://github.com/nelmio/NelmioApiDocBundle/issues/410.
This PR aims to provide a uniform way of declaring data-types of parameters for
parsers and handlers to follow. In turn, this would allow formatters to
determine data-types in a cleaner and less volatile manner. (See use-case that
can be improved with this PR:
https://github.com/nelmio/NelmioApiDocBundle/blob/master/Formatter/AbstractFormatter.php#L103)
This is possible by the addition two properties to each property item in
`response`, and `parameters` fields in each API endpoint produced by the
`ApiDocExtractor`:
* `actualType` Contains a value from one of the `DataTypes` class constants.
* `subType` Can contain either `null`, or any other `DataTypes` class constant.
This is relevant when the `actualType` is a `DataTypes::COLLECTION`, wherein
`subType` would specify the type of the collection items. It is also relevant
when `actualType` is a `DataTypes::MODEL`, wherein `subType` would contain an
identifier of the model (the FQCN or anything the parser would wish to specify)
Examples:
```php
array(
'id' => array(
'dataType' => 'integer',
'actualType' => DataTypes::INTEGER,
'subType' => null,
),
'profile' => array(
'dataType' => 'object (Profile)',
'actualType' => DataTypes::MODEL,
'subType' => 'Foo\Entity\Profile',
'children' => array(
'name' => array(
'dataType' => 'string',
'actualType' => DataTypes::STRING,
'subType' => null,
),
'birthDate' => array(
'dataType' => 'date',
'actualType' => DataTypes::DATE,
'subType' => null,
),
)
),
'languages' => array(
'dataType' => 'array of strings',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::STRING,
),
'roles' => array(
'dataType' => 'array of choices',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::ENUM,
),
'groups' => array(
'dataType' => 'array of objects (Group)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Group',
),
'profileRevisions' => array(
'dataType' => 'array of objects (Profile)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Profile',
),
'address' => array(
'dataType' => 'object (a_type_a_custom_JMS_serializer_handler_handles)',
'actualType' => DataTypes::MODEL,
'subType' => 'a_type_a_custom_JMS_serializer_handler_handles',
),
);
```
When a formatter omits the `dataType` property or leaves it blank, it is
inferred within `ApiDocExtractor` before everything is passed to formatters.
2014-06-17 17:05:00 -07:00
|
|
|
'dataType' => 'string',
|
|
|
|
'actualType' => DataTypes::STRING,
|
|
|
|
'subType' => null,
|
2014-06-17 17:05:00 -07:00
|
|
|
'default' => null,
|
Unified data types [actualType and subType]
This is the result of https://github.com/nelmio/NelmioApiDocBundle/issues/410.
This PR aims to provide a uniform way of declaring data-types of parameters for
parsers and handlers to follow. In turn, this would allow formatters to
determine data-types in a cleaner and less volatile manner. (See use-case that
can be improved with this PR:
https://github.com/nelmio/NelmioApiDocBundle/blob/master/Formatter/AbstractFormatter.php#L103)
This is possible by the addition two properties to each property item in
`response`, and `parameters` fields in each API endpoint produced by the
`ApiDocExtractor`:
* `actualType` Contains a value from one of the `DataTypes` class constants.
* `subType` Can contain either `null`, or any other `DataTypes` class constant.
This is relevant when the `actualType` is a `DataTypes::COLLECTION`, wherein
`subType` would specify the type of the collection items. It is also relevant
when `actualType` is a `DataTypes::MODEL`, wherein `subType` would contain an
identifier of the model (the FQCN or anything the parser would wish to specify)
Examples:
```php
array(
'id' => array(
'dataType' => 'integer',
'actualType' => DataTypes::INTEGER,
'subType' => null,
),
'profile' => array(
'dataType' => 'object (Profile)',
'actualType' => DataTypes::MODEL,
'subType' => 'Foo\Entity\Profile',
'children' => array(
'name' => array(
'dataType' => 'string',
'actualType' => DataTypes::STRING,
'subType' => null,
),
'birthDate' => array(
'dataType' => 'date',
'actualType' => DataTypes::DATE,
'subType' => null,
),
)
),
'languages' => array(
'dataType' => 'array of strings',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::STRING,
),
'roles' => array(
'dataType' => 'array of choices',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::ENUM,
),
'groups' => array(
'dataType' => 'array of objects (Group)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Group',
),
'profileRevisions' => array(
'dataType' => 'array of objects (Profile)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Profile',
),
'address' => array(
'dataType' => 'object (a_type_a_custom_JMS_serializer_handler_handles)',
'actualType' => DataTypes::MODEL,
'subType' => 'a_type_a_custom_JMS_serializer_handler_handles',
),
);
```
When a formatter omits the `dataType` property or leaves it blank, it is
inferred within `ApiDocExtractor` before everything is passed to formatters.
2014-06-17 17:05:00 -07:00
|
|
|
'required' => false,
|
|
|
|
'description' => null,
|
|
|
|
'readonly' => false,
|
2013-04-24 22:28:46 +02:00
|
|
|
'sinceVersion' => null,
|
|
|
|
'untilVersion' => null,
|
2013-03-25 12:28:00 +01:00
|
|
|
),
|
|
|
|
'bar' => array(
|
Unified data types [actualType and subType]
This is the result of https://github.com/nelmio/NelmioApiDocBundle/issues/410.
This PR aims to provide a uniform way of declaring data-types of parameters for
parsers and handlers to follow. In turn, this would allow formatters to
determine data-types in a cleaner and less volatile manner. (See use-case that
can be improved with this PR:
https://github.com/nelmio/NelmioApiDocBundle/blob/master/Formatter/AbstractFormatter.php#L103)
This is possible by the addition two properties to each property item in
`response`, and `parameters` fields in each API endpoint produced by the
`ApiDocExtractor`:
* `actualType` Contains a value from one of the `DataTypes` class constants.
* `subType` Can contain either `null`, or any other `DataTypes` class constant.
This is relevant when the `actualType` is a `DataTypes::COLLECTION`, wherein
`subType` would specify the type of the collection items. It is also relevant
when `actualType` is a `DataTypes::MODEL`, wherein `subType` would contain an
identifier of the model (the FQCN or anything the parser would wish to specify)
Examples:
```php
array(
'id' => array(
'dataType' => 'integer',
'actualType' => DataTypes::INTEGER,
'subType' => null,
),
'profile' => array(
'dataType' => 'object (Profile)',
'actualType' => DataTypes::MODEL,
'subType' => 'Foo\Entity\Profile',
'children' => array(
'name' => array(
'dataType' => 'string',
'actualType' => DataTypes::STRING,
'subType' => null,
),
'birthDate' => array(
'dataType' => 'date',
'actualType' => DataTypes::DATE,
'subType' => null,
),
)
),
'languages' => array(
'dataType' => 'array of strings',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::STRING,
),
'roles' => array(
'dataType' => 'array of choices',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::ENUM,
),
'groups' => array(
'dataType' => 'array of objects (Group)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Group',
),
'profileRevisions' => array(
'dataType' => 'array of objects (Profile)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Profile',
),
'address' => array(
'dataType' => 'object (a_type_a_custom_JMS_serializer_handler_handles)',
'actualType' => DataTypes::MODEL,
'subType' => 'a_type_a_custom_JMS_serializer_handler_handles',
),
);
```
When a formatter omits the `dataType` property or leaves it blank, it is
inferred within `ApiDocExtractor` before everything is passed to formatters.
2014-06-17 17:05:00 -07:00
|
|
|
'dataType' => 'string',
|
|
|
|
'actualType' => DataTypes::STRING,
|
|
|
|
'subType' => null,
|
2014-06-26 12:27:47 -07:00
|
|
|
'default' => 'baz',
|
Unified data types [actualType and subType]
This is the result of https://github.com/nelmio/NelmioApiDocBundle/issues/410.
This PR aims to provide a uniform way of declaring data-types of parameters for
parsers and handlers to follow. In turn, this would allow formatters to
determine data-types in a cleaner and less volatile manner. (See use-case that
can be improved with this PR:
https://github.com/nelmio/NelmioApiDocBundle/blob/master/Formatter/AbstractFormatter.php#L103)
This is possible by the addition two properties to each property item in
`response`, and `parameters` fields in each API endpoint produced by the
`ApiDocExtractor`:
* `actualType` Contains a value from one of the `DataTypes` class constants.
* `subType` Can contain either `null`, or any other `DataTypes` class constant.
This is relevant when the `actualType` is a `DataTypes::COLLECTION`, wherein
`subType` would specify the type of the collection items. It is also relevant
when `actualType` is a `DataTypes::MODEL`, wherein `subType` would contain an
identifier of the model (the FQCN or anything the parser would wish to specify)
Examples:
```php
array(
'id' => array(
'dataType' => 'integer',
'actualType' => DataTypes::INTEGER,
'subType' => null,
),
'profile' => array(
'dataType' => 'object (Profile)',
'actualType' => DataTypes::MODEL,
'subType' => 'Foo\Entity\Profile',
'children' => array(
'name' => array(
'dataType' => 'string',
'actualType' => DataTypes::STRING,
'subType' => null,
),
'birthDate' => array(
'dataType' => 'date',
'actualType' => DataTypes::DATE,
'subType' => null,
),
)
),
'languages' => array(
'dataType' => 'array of strings',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::STRING,
),
'roles' => array(
'dataType' => 'array of choices',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::ENUM,
),
'groups' => array(
'dataType' => 'array of objects (Group)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Group',
),
'profileRevisions' => array(
'dataType' => 'array of objects (Profile)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Profile',
),
'address' => array(
'dataType' => 'object (a_type_a_custom_JMS_serializer_handler_handles)',
'actualType' => DataTypes::MODEL,
'subType' => 'a_type_a_custom_JMS_serializer_handler_handles',
),
);
```
When a formatter omits the `dataType` property or leaves it blank, it is
inferred within `ApiDocExtractor` before everything is passed to formatters.
2014-06-17 17:05:00 -07:00
|
|
|
'required' => false,
|
|
|
|
'description' => null,
|
|
|
|
'readonly' => false,
|
2013-04-24 22:28:46 +02:00
|
|
|
'sinceVersion' => '2.0',
|
|
|
|
'untilVersion' => null,
|
2013-03-25 12:28:00 +01:00
|
|
|
),
|
2013-04-24 22:28:46 +02:00
|
|
|
'baz' => array(
|
Unified data types [actualType and subType]
This is the result of https://github.com/nelmio/NelmioApiDocBundle/issues/410.
This PR aims to provide a uniform way of declaring data-types of parameters for
parsers and handlers to follow. In turn, this would allow formatters to
determine data-types in a cleaner and less volatile manner. (See use-case that
can be improved with this PR:
https://github.com/nelmio/NelmioApiDocBundle/blob/master/Formatter/AbstractFormatter.php#L103)
This is possible by the addition two properties to each property item in
`response`, and `parameters` fields in each API endpoint produced by the
`ApiDocExtractor`:
* `actualType` Contains a value from one of the `DataTypes` class constants.
* `subType` Can contain either `null`, or any other `DataTypes` class constant.
This is relevant when the `actualType` is a `DataTypes::COLLECTION`, wherein
`subType` would specify the type of the collection items. It is also relevant
when `actualType` is a `DataTypes::MODEL`, wherein `subType` would contain an
identifier of the model (the FQCN or anything the parser would wish to specify)
Examples:
```php
array(
'id' => array(
'dataType' => 'integer',
'actualType' => DataTypes::INTEGER,
'subType' => null,
),
'profile' => array(
'dataType' => 'object (Profile)',
'actualType' => DataTypes::MODEL,
'subType' => 'Foo\Entity\Profile',
'children' => array(
'name' => array(
'dataType' => 'string',
'actualType' => DataTypes::STRING,
'subType' => null,
),
'birthDate' => array(
'dataType' => 'date',
'actualType' => DataTypes::DATE,
'subType' => null,
),
)
),
'languages' => array(
'dataType' => 'array of strings',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::STRING,
),
'roles' => array(
'dataType' => 'array of choices',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::ENUM,
),
'groups' => array(
'dataType' => 'array of objects (Group)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Group',
),
'profileRevisions' => array(
'dataType' => 'array of objects (Profile)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Profile',
),
'address' => array(
'dataType' => 'object (a_type_a_custom_JMS_serializer_handler_handles)',
'actualType' => DataTypes::MODEL,
'subType' => 'a_type_a_custom_JMS_serializer_handler_handles',
),
);
```
When a formatter omits the `dataType` property or leaves it blank, it is
inferred within `ApiDocExtractor` before everything is passed to formatters.
2014-06-17 17:05:00 -07:00
|
|
|
'dataType' => 'string',
|
|
|
|
'actualType' => DataTypes::STRING,
|
|
|
|
'subType' => null,
|
2014-06-17 17:05:00 -07:00
|
|
|
'default' => null,
|
Unified data types [actualType and subType]
This is the result of https://github.com/nelmio/NelmioApiDocBundle/issues/410.
This PR aims to provide a uniform way of declaring data-types of parameters for
parsers and handlers to follow. In turn, this would allow formatters to
determine data-types in a cleaner and less volatile manner. (See use-case that
can be improved with this PR:
https://github.com/nelmio/NelmioApiDocBundle/blob/master/Formatter/AbstractFormatter.php#L103)
This is possible by the addition two properties to each property item in
`response`, and `parameters` fields in each API endpoint produced by the
`ApiDocExtractor`:
* `actualType` Contains a value from one of the `DataTypes` class constants.
* `subType` Can contain either `null`, or any other `DataTypes` class constant.
This is relevant when the `actualType` is a `DataTypes::COLLECTION`, wherein
`subType` would specify the type of the collection items. It is also relevant
when `actualType` is a `DataTypes::MODEL`, wherein `subType` would contain an
identifier of the model (the FQCN or anything the parser would wish to specify)
Examples:
```php
array(
'id' => array(
'dataType' => 'integer',
'actualType' => DataTypes::INTEGER,
'subType' => null,
),
'profile' => array(
'dataType' => 'object (Profile)',
'actualType' => DataTypes::MODEL,
'subType' => 'Foo\Entity\Profile',
'children' => array(
'name' => array(
'dataType' => 'string',
'actualType' => DataTypes::STRING,
'subType' => null,
),
'birthDate' => array(
'dataType' => 'date',
'actualType' => DataTypes::DATE,
'subType' => null,
),
)
),
'languages' => array(
'dataType' => 'array of strings',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::STRING,
),
'roles' => array(
'dataType' => 'array of choices',
'actualType' => DataTypes::COLLECTION,
'subType' => DataTypes::ENUM,
),
'groups' => array(
'dataType' => 'array of objects (Group)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Group',
),
'profileRevisions' => array(
'dataType' => 'array of objects (Profile)',
'actualType' => DataTypes::COLLECTION,
'subType' => 'Foo\Entity\Profile',
),
'address' => array(
'dataType' => 'object (a_type_a_custom_JMS_serializer_handler_handles)',
'actualType' => DataTypes::MODEL,
'subType' => 'a_type_a_custom_JMS_serializer_handler_handles',
),
);
```
When a formatter omits the `dataType` property or leaves it blank, it is
inferred within `ApiDocExtractor` before everything is passed to formatters.
2014-06-17 17:05:00 -07:00
|
|
|
'required' => false,
|
|
|
|
'description' => null,
|
|
|
|
'readonly' => false,
|
2013-04-24 22:28:46 +02:00
|
|
|
'sinceVersion' => null,
|
|
|
|
'untilVersion' => '3.0',
|
2013-03-25 12:28:00 +01:00
|
|
|
)
|
|
|
|
),
|
|
|
|
$output
|
|
|
|
);
|
2013-02-11 14:42:17 +01:00
|
|
|
}
|
2013-02-26 19:24:14 +01:00
|
|
|
|
2014-07-08 13:20:13 +02:00
|
|
|
public function testParserWithInline()
|
|
|
|
{
|
|
|
|
$metadataFactory = $this->getMock('Metadata\MetadataFactoryInterface');
|
|
|
|
$docCommentExtractor = $this->getMockBuilder('Nelmio\ApiDocBundle\Util\DocCommentExtractor')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$propertyMetadataFoo = new PropertyMetadata('Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsInline', 'foo');
|
|
|
|
$propertyMetadataFoo->type = array('name' => 'string');
|
|
|
|
|
|
|
|
$propertyMetadataInline = new PropertyMetadata('Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsInline', 'inline');
|
|
|
|
$propertyMetadataInline->type = array('name' => 'Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsTest');
|
|
|
|
$propertyMetadataInline->inline = true;
|
|
|
|
|
|
|
|
$input = 'Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsInline';
|
|
|
|
|
|
|
|
$metadata = new ClassMetadata($input);
|
|
|
|
$metadata->addPropertyMetadata($propertyMetadataFoo);
|
|
|
|
$metadata->addPropertyMetadata($propertyMetadataInline);
|
|
|
|
|
|
|
|
$propertyMetadataBar = new PropertyMetadata('Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsTest', 'bar');
|
|
|
|
$propertyMetadataBar->type = array('name' => 'string');
|
|
|
|
|
|
|
|
$subInput = 'Nelmio\ApiDocBundle\Tests\Fixtures\Model\JmsTest';
|
|
|
|
|
|
|
|
$subMetadata = new ClassMetadata($subInput);
|
|
|
|
$subMetadata->addPropertyMetadata($propertyMetadataBar);
|
|
|
|
|
|
|
|
$metadataFactory->expects($this->at(0))
|
|
|
|
->method('getMetadataForClass')
|
|
|
|
->with($input)
|
|
|
|
->will($this->returnValue($metadata));
|
|
|
|
|
|
|
|
$metadataFactory->expects($this->at(1))
|
|
|
|
->method('getMetadataForClass')
|
|
|
|
->with($subInput)
|
|
|
|
->will($this->returnValue($subMetadata));
|
|
|
|
|
|
|
|
$metadataFactory->expects($this->at(2))
|
|
|
|
->method('getMetadataForClass')
|
|
|
|
->with($subInput)
|
|
|
|
->will($this->returnValue($subMetadata));
|
|
|
|
|
|
|
|
$propertyNamingStrategy = new CamelCaseNamingStrategy();
|
|
|
|
|
|
|
|
$jmsMetadataParser = new JmsMetadataParser($metadataFactory, $propertyNamingStrategy, $docCommentExtractor);
|
|
|
|
|
|
|
|
$output = $jmsMetadataParser->parse(
|
|
|
|
array(
|
|
|
|
'class' => $input,
|
|
|
|
'groups' => array(),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
array(
|
|
|
|
'foo' => array(
|
|
|
|
'dataType' => 'string',
|
|
|
|
'actualType' => DataTypes::STRING,
|
|
|
|
'subType' => null,
|
|
|
|
'default' => null,
|
|
|
|
'required' => false,
|
|
|
|
'description' => null,
|
|
|
|
'readonly' => false,
|
|
|
|
'sinceVersion' => null,
|
|
|
|
'untilVersion' => null,
|
|
|
|
),
|
|
|
|
'bar' => array(
|
|
|
|
'dataType' => 'string',
|
|
|
|
'actualType' => DataTypes::STRING,
|
|
|
|
'subType' => null,
|
|
|
|
'default' => null,
|
|
|
|
'required' => false,
|
|
|
|
'description' => null,
|
|
|
|
'readonly' => false,
|
|
|
|
'sinceVersion' => null,
|
|
|
|
'untilVersion' => null,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
$output
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-02-26 19:24:14 +01:00
|
|
|
public function dataTestParserWithNestedType()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array('array'),
|
|
|
|
array('ArrayCollection')
|
|
|
|
);
|
|
|
|
}
|
2013-03-16 18:48:34 +01:00
|
|
|
}
|