mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 23:59:26 +03:00
Read more properties from swagger property annotation (#1146)
* read default property from swagger property annotation * read enum from swagger property annotation * a small fixes
This commit is contained in:
parent
a6ff145195
commit
ac7b924129
@ -80,8 +80,10 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
|
||||
$type = $item->type['name'];
|
||||
}
|
||||
|
||||
if (in_array($type, ['boolean', 'integer', 'string', 'array'])) {
|
||||
if (in_array($type, ['boolean', 'string', 'array'])) {
|
||||
$property->setType($type);
|
||||
} elseif (in_array($type, ['int', 'integer'])) {
|
||||
$property->setType('integer');
|
||||
} elseif (in_array($type, ['double', 'float'])) {
|
||||
$property->setType('number');
|
||||
$property->setFormat($type);
|
||||
|
@ -15,6 +15,7 @@ use Doctrine\Common\Annotations\Reader;
|
||||
use EXSyst\Component\Swagger\Items;
|
||||
use EXSyst\Component\Swagger\Schema;
|
||||
use Swagger\Annotations\Property as SwgProperty;
|
||||
use const Swagger\Annotations\UNDEFINED;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@ -36,21 +37,27 @@ class SwaggerPropertyAnnotationReader
|
||||
{
|
||||
$swgProperty = $this->annotationsReader->getPropertyAnnotation($reflectionProperty, SwgProperty::class);
|
||||
if ($swgProperty instanceof SwgProperty) {
|
||||
if (null !== $swgProperty->type) {
|
||||
if ($swgProperty->type !== null) {
|
||||
$property->setType($swgProperty->type);
|
||||
}
|
||||
if (null !== $swgProperty->readOnly) {
|
||||
$property->setReadOnly($swgProperty->readOnly);
|
||||
if ($swgProperty->default !== UNDEFINED) {
|
||||
$property->setDefault($swgProperty->default);
|
||||
}
|
||||
if ($swgProperty->enum !== null) {
|
||||
$property->setEnum($swgProperty->enum);
|
||||
}
|
||||
if ($property instanceof Schema) {
|
||||
if (null !== $swgProperty->description) {
|
||||
if ($swgProperty->description !== null) {
|
||||
$property->setDescription($swgProperty->description);
|
||||
}
|
||||
if (null !== $swgProperty->title) {
|
||||
if ($swgProperty->title !== null) {
|
||||
$property->setTitle($swgProperty->title);
|
||||
}
|
||||
if (null !== $swgProperty->example) {
|
||||
$property->setExample((string) $swgProperty->example);
|
||||
if ($swgProperty->example !== null) {
|
||||
$property->setExample($swgProperty->example);
|
||||
}
|
||||
if ($swgProperty->readOnly !== null) {
|
||||
$property->setReadOnly($swgProperty->readOnly);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,10 +25,19 @@ class JMSUser
|
||||
* @Serializer\Type("integer")
|
||||
* @Serializer\Expose
|
||||
*
|
||||
* @SWG\Property(description = "User id", required = true, readOnly = true, title = "userid", example=1)
|
||||
* @SWG\Property(description = "User id", required = true, readOnly = true, title = "userid", example=1, default = null)
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @Serializer\Type("int")
|
||||
* @Serializer\Expose
|
||||
* @Serializer\SerializedName("daysOnline")
|
||||
*
|
||||
* @SWG\Property(default = 0)
|
||||
*/
|
||||
private $daysOnline;
|
||||
|
||||
/**
|
||||
* @Serializer\Type("string")
|
||||
* @Serializer\Expose
|
||||
@ -41,7 +50,8 @@ class JMSUser
|
||||
* @Serializer\Type("array<string>")
|
||||
* @Serializer\Accessor(getter="getRoles", setter="setRoles")
|
||||
* @Serializer\Expose
|
||||
* @SWG\Property(description = "User roles", required = true, title = "roles", example="[""ADMIN"",""SUPERUSER""]")
|
||||
*
|
||||
* @SWG\Property(default = {"user"}, description = "Roles list", example="[""ADMIN"",""SUPERUSER""]", title="roles")
|
||||
*/
|
||||
private $roles;
|
||||
|
||||
@ -78,6 +88,14 @@ class JMSUser
|
||||
*/
|
||||
private $bestFriend;
|
||||
|
||||
/**
|
||||
* @Serializer\Type("string")
|
||||
* @Serializer\Expose
|
||||
*
|
||||
* @SWG\Property(enum = {"disabled", "enabled"})
|
||||
*/
|
||||
private $status;
|
||||
|
||||
public function setRoles($roles)
|
||||
{
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ class User
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* @SWG\Property(description = "User id", required = true, readOnly = true, title = "userid", example=1)
|
||||
* @SWG\Property(description = "User id", required = true, readOnly = true, title = "userid", example=1, default = null)
|
||||
*/
|
||||
private $id;
|
||||
|
||||
@ -37,11 +37,10 @@ class User
|
||||
*
|
||||
* @SWG\Property(
|
||||
* description = "User roles",
|
||||
* type = "array",
|
||||
* items=@SWG\Items(type="string"),
|
||||
* required = true,
|
||||
* title = "roles",
|
||||
* example="[""ADMIN"",""SUPERUSER""]")
|
||||
* example="[""ADMIN"",""SUPERUSER""]",
|
||||
* default = {"user"},
|
||||
* )
|
||||
*/
|
||||
private $roles;
|
||||
@ -55,6 +54,7 @@ class User
|
||||
|
||||
/**
|
||||
* @var float
|
||||
* @SWG\Property(default = 0.0)
|
||||
*/
|
||||
private $money;
|
||||
|
||||
@ -68,6 +68,13 @@ class User
|
||||
*/
|
||||
private $users;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @SWG\Property(enum = {"disabled", "enabled"})
|
||||
*/
|
||||
private $status;
|
||||
|
||||
/**
|
||||
* @param float $money
|
||||
*/
|
||||
@ -119,4 +126,8 @@ class User
|
||||
public function setDummy(Dummy $dummy)
|
||||
{
|
||||
}
|
||||
|
||||
public function setStatus(string $status)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -156,6 +156,7 @@ class FunctionalTest extends WebTestCase
|
||||
'money' => [
|
||||
'type' => 'number',
|
||||
'format' => 'float',
|
||||
'default' => 0.0
|
||||
],
|
||||
'id' => [
|
||||
'type' => 'integer',
|
||||
@ -169,11 +170,12 @@ class FunctionalTest extends WebTestCase
|
||||
'readOnly' => false,
|
||||
],
|
||||
'roles' => [
|
||||
'title' => 'roles',
|
||||
'type' => 'array',
|
||||
'description' => 'User roles',
|
||||
'title' => 'roles',
|
||||
'example' => '["ADMIN","SUPERUSER"]',
|
||||
'items' => ['type' => 'string'],
|
||||
'default' => ['user'],
|
||||
],
|
||||
'friendsNumber' => [
|
||||
'type' => 'string',
|
||||
@ -191,6 +193,10 @@ class FunctionalTest extends WebTestCase
|
||||
'dummy' => [
|
||||
'$ref' => '#/definitions/Dummy2',
|
||||
],
|
||||
'status' => [
|
||||
'type' => 'string',
|
||||
'enum' => ["disabled", "enabled"],
|
||||
],
|
||||
],
|
||||
],
|
||||
$this->getModel('User')->toArray()
|
||||
|
@ -25,16 +25,21 @@ class JMSFunctionalTest extends WebTestCase
|
||||
'title' => 'userid',
|
||||
'example' => 1,
|
||||
],
|
||||
'daysOnline' => [
|
||||
'type' => 'integer',
|
||||
'default' => 0,
|
||||
],
|
||||
'email' => [
|
||||
'type' => 'string',
|
||||
'readOnly' => false,
|
||||
],
|
||||
'roles' => [
|
||||
'type' => 'array',
|
||||
'description' => 'User roles',
|
||||
'title' => 'roles',
|
||||
'example' => '["ADMIN","SUPERUSER"]',
|
||||
'items' => ['type' => 'string'],
|
||||
'default' => ['user'],
|
||||
'description' => 'Roles list',
|
||||
],
|
||||
'friendsNumber' => [
|
||||
'type' => 'string',
|
||||
@ -48,6 +53,10 @@ class JMSFunctionalTest extends WebTestCase
|
||||
'best_friend' => [
|
||||
'$ref' => '#/definitions/User',
|
||||
],
|
||||
'status' => [
|
||||
'type' => 'string',
|
||||
'enum' => ["disabled", "enabled"],
|
||||
],
|
||||
],
|
||||
], $this->getModel('JMSUser')->toArray());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user