dawen / api-doc-property-bundle
nelmio api doc bundle 扩展,用于暴露属性
0.1.0
2015-12-19 10:44 UTC
Requires
- php: >=5.5.0
- nelmio/api-doc-bundle: ~2.11
- symfony/framework-bundle: ~2.3|~3.0
Requires (Dev)
- phpunit/phpunit: ~4.8
This package is not auto-updated.
Last update: 2024-09-14 18:26:11 UTC
README
此包允许您暴露那些未被 json、jms 或 validator 解析器处理的 API 文档属性
安装
在您的 composer.json 中添加 dawen/api-doc-property-bundle 包并更新依赖项。
$ composer require dawen/api-doc-property-bundle
// app/AppKernel.php public function registerBundles() { return array( // ... new Dawen\Bundle\ApiDocPropertyBundle\ApiDocPropertyBundle(), ); }
在 app/AppKernel.php 中注册该包
用法与示例
为了定义一个属性,您可以在您的属性中添加一个新的注解
@ApiDocProperty(type="string")
可用的属性设置信息
name
Type: string
Description: Name of the property. If this is not set, then the name of the class property will be taken
description
Type: string
Description: This will be set as description for the property
type
Types: all php types, full qualified class name, array<full qualified class name>
Description: The type property has no strict limitation. you can write whatever you want. But keep in mind,
that it appears in the api documentation. There is only some magic for classes and array of objects. This will be parsed recursively
简单类的示例
namespace Dawen\Bundle\ApiDocPropertyBundle; use Dawen\Bundle\ApiDocPropertyBundle\Component\Annotation\ApiDocProperty; class Dummy { /** * @ApiDocProperty(type="string") * @var string */ private $firstName; /** * @ApiDocProperty(type="string") * @var string */ private $lastName; /** * @ApiDocProperty(type="int") * @var int */ private $age = 0; /** * @ApiDocProperty(type="Dawen\Bundle\ApiDocPropertyBundle\Address") * @var Dawen\Bundle\ApiDocPropertyBundle\Address */ private $address; /** * @ApiDocProperty(type="array<Dawen\Bundle\ApiDocPropertyBundle\Key>") * @var array */ private $keys = []; /** * @return string */ public function getFirstName() { return $this->firstName; } /** * @param string $firstName */ public function setFirstName($firstName) { $this->firstName = $firstName; } /** * @return string */ public function getLastName() { return $this->lastName; } /** * @param string $lastName */ public function setLastName($lastName) { $this->lastName = $lastName; } /** * @return int */ public function getAge() { return $this->age; } /** * @param int $age */ public function setAge($age) { $this->age = $age; } /** * @return Dawen\Bundle\ApiDocPropertyBundle\Address */ public function getAddress() { return $this->address; } /** * @param Dawen\Bundle\ApiDocPropertyBundle\Address $address */ public function setAddress($address) { $this->address = $address; } /** * @return array */ public function getKeys() { return $this->keys; } /** * @param array $keys */ public function setKeys($keys) { $this->keys = $keys; } }