mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-03 08:09:25 +03:00
Merge pull request #1236 from nelmio/properties
Allow to change a property name
This commit is contained in:
commit
d4b0382fa2
@ -40,6 +40,11 @@ class AnnotationsReader
|
|||||||
$this->symfonyConstraintAnnotationReader->setSchema($schema);
|
$this->symfonyConstraintAnnotationReader->setSchema($schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPropertyName(\ReflectionProperty $reflectionProperty, string $default): string
|
||||||
|
{
|
||||||
|
return $this->swgAnnotationsReader->getPropertyName($reflectionProperty, $default);
|
||||||
|
}
|
||||||
|
|
||||||
public function updateProperty(\ReflectionProperty $reflectionProperty, Schema $property)
|
public function updateProperty(\ReflectionProperty $reflectionProperty, Schema $property)
|
||||||
{
|
{
|
||||||
$this->phpDocReader->updateProperty($reflectionProperty, $property);
|
$this->phpDocReader->updateProperty($reflectionProperty, $property);
|
||||||
|
@ -40,6 +40,16 @@ class SwgAnnotationsReader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPropertyName(\ReflectionProperty $reflectionProperty, string $default): string
|
||||||
|
{
|
||||||
|
/** @var SwgProperty $swgProperty */
|
||||||
|
if (!$swgProperty = $this->annotationsReader->getPropertyAnnotation($reflectionProperty, SwgProperty::class)) {
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $swgProperty->property ?? $default;
|
||||||
|
}
|
||||||
|
|
||||||
public function updateProperty(\ReflectionProperty $reflectionProperty, Schema $property)
|
public function updateProperty(\ReflectionProperty $reflectionProperty, Schema $property)
|
||||||
{
|
{
|
||||||
/** @var SwgProperty $swgProperty */
|
/** @var SwgProperty $swgProperty */
|
||||||
|
@ -69,11 +69,13 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
|
|||||||
}
|
}
|
||||||
|
|
||||||
$name = $this->namingStrategy->translateName($item);
|
$name = $this->namingStrategy->translateName($item);
|
||||||
$property = $properties->get($name);
|
|
||||||
|
|
||||||
// read property options from Swagger Property annotation if it exists
|
// read property options from Swagger Property annotation if it exists
|
||||||
if (null !== $item->reflection) {
|
if (null !== $item->reflection) {
|
||||||
|
$property = $properties->get($this->annotationsReader->getPropertyName($item->reflection, $name));
|
||||||
$this->annotationsReader->updateProperty($item->reflection, $property);
|
$this->annotationsReader->updateProperty($item->reflection, $property);
|
||||||
|
} else {
|
||||||
|
$property = $properties->get($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null !== $property->getType()) {
|
if (null !== $property->getType()) {
|
||||||
|
@ -55,14 +55,13 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($propertyInfoProperties as $propertyName) {
|
foreach ($propertyInfoProperties as $propertyName) {
|
||||||
$property = $properties->get($propertyName);
|
|
||||||
|
|
||||||
// read property options from Swagger Property annotation if it exists
|
// read property options from Swagger Property annotation if it exists
|
||||||
if (property_exists($class, $propertyName)) {
|
if (property_exists($class, $propertyName)) {
|
||||||
$this->annotationsReader->updateProperty(
|
$reflectionProperty = new \ReflectionProperty($class, $propertyName);
|
||||||
new \ReflectionProperty($class, $propertyName),
|
$property = $properties->get($this->annotationsReader->getPropertyName($reflectionProperty, $propertyName));
|
||||||
$property
|
$this->annotationsReader->updateProperty($reflectionProperty, $property);
|
||||||
);
|
} else {
|
||||||
|
$property = $properties->get($propertyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If type manually defined
|
// If type manually defined
|
||||||
|
@ -62,7 +62,7 @@ class JMSUser
|
|||||||
private $password;
|
private $password;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @SWG\Property(type="date")
|
* @SWG\Property(property="last_update", type="date")
|
||||||
* @Serializer\Expose
|
* @Serializer\Expose
|
||||||
*/
|
*/
|
||||||
private $updatedAt;
|
private $updatedAt;
|
||||||
|
@ -57,6 +57,7 @@ class User
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \DateTime
|
* @var \DateTime
|
||||||
|
* @SWG\Property(property="creationDate")
|
||||||
*/
|
*/
|
||||||
private $createdAt;
|
private $createdAt;
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ class FunctionalTest extends WebTestCase
|
|||||||
'friendsNumber' => [
|
'friendsNumber' => [
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
],
|
],
|
||||||
'createdAt' => [
|
'creationDate' => [
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'format' => 'date-time',
|
'format' => 'date-time',
|
||||||
],
|
],
|
||||||
|
@ -63,7 +63,7 @@ class JMSFunctionalTest extends WebTestCase
|
|||||||
'description' => 'Only enabled users may be used in actions.',
|
'description' => 'Only enabled users may be used in actions.',
|
||||||
'enum' => ['disabled', 'enabled'],
|
'enum' => ['disabled', 'enabled'],
|
||||||
],
|
],
|
||||||
'updated_at' => [
|
'last_update' => [
|
||||||
'type' => 'date',
|
'type' => 'date',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user