mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 23:59:26 +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);
|
||||
}
|
||||
|
||||
public function getPropertyName(\ReflectionProperty $reflectionProperty, string $default): string
|
||||
{
|
||||
return $this->swgAnnotationsReader->getPropertyName($reflectionProperty, $default);
|
||||
}
|
||||
|
||||
public function updateProperty(\ReflectionProperty $reflectionProperty, Schema $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)
|
||||
{
|
||||
/** @var SwgProperty $swgProperty */
|
||||
|
@ -69,11 +69,13 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
|
||||
}
|
||||
|
||||
$name = $this->namingStrategy->translateName($item);
|
||||
$property = $properties->get($name);
|
||||
|
||||
// read property options from Swagger Property annotation if it exists
|
||||
if (null !== $item->reflection) {
|
||||
$property = $properties->get($this->annotationsReader->getPropertyName($item->reflection, $name));
|
||||
$this->annotationsReader->updateProperty($item->reflection, $property);
|
||||
} else {
|
||||
$property = $properties->get($name);
|
||||
}
|
||||
|
||||
if (null !== $property->getType()) {
|
||||
|
@ -55,14 +55,13 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar
|
||||
}
|
||||
|
||||
foreach ($propertyInfoProperties as $propertyName) {
|
||||
$property = $properties->get($propertyName);
|
||||
|
||||
// read property options from Swagger Property annotation if it exists
|
||||
if (property_exists($class, $propertyName)) {
|
||||
$this->annotationsReader->updateProperty(
|
||||
new \ReflectionProperty($class, $propertyName),
|
||||
$property
|
||||
);
|
||||
$reflectionProperty = new \ReflectionProperty($class, $propertyName);
|
||||
$property = $properties->get($this->annotationsReader->getPropertyName($reflectionProperty, $propertyName));
|
||||
$this->annotationsReader->updateProperty($reflectionProperty, $property);
|
||||
} else {
|
||||
$property = $properties->get($propertyName);
|
||||
}
|
||||
|
||||
// If type manually defined
|
||||
|
@ -62,7 +62,7 @@ class JMSUser
|
||||
private $password;
|
||||
|
||||
/**
|
||||
* @SWG\Property(type="date")
|
||||
* @SWG\Property(property="last_update", type="date")
|
||||
* @Serializer\Expose
|
||||
*/
|
||||
private $updatedAt;
|
||||
|
@ -57,6 +57,7 @@ class User
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
* @SWG\Property(property="creationDate")
|
||||
*/
|
||||
private $createdAt;
|
||||
|
||||
|
@ -179,7 +179,7 @@ class FunctionalTest extends WebTestCase
|
||||
'friendsNumber' => [
|
||||
'type' => 'string',
|
||||
],
|
||||
'createdAt' => [
|
||||
'creationDate' => [
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
],
|
||||
|
@ -63,7 +63,7 @@ class JMSFunctionalTest extends WebTestCase
|
||||
'description' => 'Only enabled users may be used in actions.',
|
||||
'enum' => ['disabled', 'enabled'],
|
||||
],
|
||||
'updated_at' => [
|
||||
'last_update' => [
|
||||
'type' => 'date',
|
||||
],
|
||||
],
|
||||
|
Loading…
x
Reference in New Issue
Block a user