This commit is contained in:
Guilhem Niot 2017-12-17 10:44:07 +01:00
parent a07e3bfe75
commit a4fe1f8078
13 changed files with 43 additions and 42 deletions

View File

@ -168,7 +168,7 @@ final class SwaggerPhpDescriber extends ExternalDocDescriber implements ModelReg
private function normalizePath(string $path): string
{
if (substr($path, -10) === '.{_format}') {
if ('.{_format}' === substr($path, -10)) {
$path = substr($path, 0, -10);
}

View File

@ -39,8 +39,7 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
MetadataFactoryInterface $factory,
PropertyNamingStrategyInterface $namingStrategy,
SwaggerPropertyAnnotationReader $swaggerPropertyAnnotationReader
)
{
) {
$this->factory = $factory;
$this->namingStrategy = $namingStrategy;
$this->swaggerPropertyAnnotationReader = $swaggerPropertyAnnotationReader;
@ -101,8 +100,9 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
}
// read property options from Swagger Property annotation if it exists
if($item->reflection !== null)
if (null !== $item->reflection) {
$this->swaggerPropertyAnnotationReader->updateWithSwaggerPropertyAnnotation($item->reflection, $realProp);
}
}
}

View File

@ -29,8 +29,7 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar
public function __construct(
PropertyInfoExtractorInterface $propertyInfo,
SwaggerPropertyAnnotationReader $swaggerPropertyAnnotationReader
)
{
) {
$this->propertyInfo = $propertyInfo;
$this->swaggerPropertyAnnotationReader = $swaggerPropertyAnnotationReader;
}
@ -69,16 +68,16 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar
$property = $property->getItems();
}
if ($type->getBuiltinType() === Type::BUILTIN_TYPE_STRING) {
if (Type::BUILTIN_TYPE_STRING === $type->getBuiltinType()) {
$property->setType('string');
} elseif ($type->getBuiltinType() === Type::BUILTIN_TYPE_BOOL) {
} elseif (Type::BUILTIN_TYPE_BOOL === $type->getBuiltinType()) {
$property->setType('boolean');
} elseif ($type->getBuiltinType() === Type::BUILTIN_TYPE_INT) {
} elseif (Type::BUILTIN_TYPE_INT === $type->getBuiltinType()) {
$property->setType('integer');
} elseif ($type->getBuiltinType() === Type::BUILTIN_TYPE_FLOAT) {
} elseif (Type::BUILTIN_TYPE_FLOAT === $type->getBuiltinType()) {
$property->setType('number');
$property->setFormat('float');
} elseif ($type->getBuiltinType() === Type::BUILTIN_TYPE_OBJECT) {
} elseif (Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType()) {
if (in_array($type->getClassName(), ['DateTime', 'DateTimeImmutable'])) {
$property->setType('string');
$property->setFormat('date-time');
@ -88,7 +87,7 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar
);
}
} else {
throw new \Exception(sprintf("Unknown type: %s", $type->getBuiltinType()));
throw new \Exception(sprintf('Unknown type: %s', $type->getBuiltinType()));
}
// read property options from Swagger Property annotation if it exists

View File

@ -11,10 +11,10 @@
namespace Nelmio\ApiDocBundle\ModelDescriber;
use EXSyst\Component\Swagger\Schema;
use EXSyst\Component\Swagger\Items;
use Swagger\Annotations\Property as SwgProperty;
use Doctrine\Common\Annotations\Reader;
use EXSyst\Component\Swagger\Items;
use EXSyst\Component\Swagger\Schema;
use Swagger\Annotations\Property as SwgProperty;
/**
* @internal
@ -36,20 +36,20 @@ class SwaggerPropertyAnnotationReader
{
$swgProperty = $this->annotationsReader->getPropertyAnnotation($reflectionProperty, SwgProperty::class);
if ($swgProperty instanceof SwgProperty) {
if ($swgProperty->type !== null) {
if (null !== $swgProperty->type) {
$property->setType($swgProperty->type);
}
if ($swgProperty->readOnly !== null) {
if (null !== $swgProperty->readOnly) {
$property->setReadOnly($swgProperty->readOnly);
}
if ($property instanceof Schema) {
if ($swgProperty->description !== null) {
if (null !== $swgProperty->description) {
$property->setDescription($swgProperty->description);
}
if ($swgProperty->title !== null) {
if (null !== $swgProperty->title) {
$property->setTitle($swgProperty->title);
}
if ($swgProperty->example !== null) {
if (null !== $swgProperty->example) {
$property->setExample((string) $swgProperty->example);
}
}

View File

@ -43,7 +43,7 @@ trait RouteDescriberTrait
private function normalizePath(string $path): string
{
if (substr($path, -10) === '.{_format}') {
if ('.{_format}' === substr($path, -10)) {
$path = substr($path, 0, -10);
}

View File

@ -41,6 +41,5 @@ class JMSController
*/
public function yamlAction()
{
}
}

View File

@ -19,7 +19,7 @@ use Swagger\Annotations as SWG;
class User
{
/**
* @var integer
* @var int
*
* @SWG\Property(description = "User id", required = true, readOnly = true, title = "userid", example=1)
*/

View File

@ -1,13 +1,20 @@
<?php
/*
* This file is part of the NelmioApiDocBundle package.
*
* (c) Nelmio
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nelmio\ApiDocBundle\Tests\Functional\Entity;
use JMS\Serializer\Annotation as Serializer;
/**
* Class VirtualProperty
* @package Nelmio\ApiDocBundle\Tests\Functional\Entity
* Class VirtualProperty.
*
* @Serializer\ExclusionPolicy("all")
* @Serializer\VirtualProperty(
@ -18,7 +25,6 @@ use JMS\Serializer\Annotation as Serializer;
*/
class VirtualProperty
{
/**
* @var int
* @Serializer\Type("integer")
@ -34,6 +40,6 @@ class VirtualProperty
public function __construct()
{
$this->user = new User();
$this->user->setEmail("dummy@test.com");
$this->user->setEmail('dummy@test.com');
}
}

View File

@ -12,8 +12,8 @@
namespace Nelmio\ApiDocBundle\Tests\Functional\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;

View File

@ -24,7 +24,7 @@ class UserType extends AbstractType
$builder
->add('dummy', DummyType::class)
->add('dummies', CollectionType::class, [
'entry_type' => DummyType::class
'entry_type' => DummyType::class,
]);
}

View File

@ -159,9 +159,9 @@ class FunctionalTest extends WebTestCase
],
'id' => [
'type' => 'integer',
'description' => "User id",
'description' => 'User id',
'readOnly' => true,
'title' => "userid",
'title' => 'userid',
'example' => 1,
],
'email' => [
@ -206,8 +206,8 @@ class FunctionalTest extends WebTestCase
'dummies' => [
'items' => ['$ref' => '#/definitions/DummyType'],
'type' => 'array',
'example' => sprintf('[{%s}]', DummyType::class)
]
'example' => sprintf('[{%s}]', DummyType::class),
],
],
'required' => ['dummy', 'dummies'],
], $this->getModel('UserType')->toArray());
@ -223,8 +223,8 @@ class FunctionalTest extends WebTestCase
'enum' => ['male', 'female'],
],
'baz' => [
'type' => 'boolean'
]
'type' => 'boolean',
],
],
'required' => ['foo'],
], $this->getModel('DummyType')->toArray());

View File

@ -20,9 +20,9 @@ class JMSFunctionalTest extends WebTestCase
'properties' => [
'id' => [
'type' => 'integer',
'description' => "User id",
'description' => 'User id',
'readOnly' => true,
'title' => "userid",
'title' => 'userid',
'example' => 1,
],
'email' => [
@ -32,7 +32,7 @@ class JMSFunctionalTest extends WebTestCase
'roles' => [
'type' => 'array',
'description' => 'User roles',
'title' => "roles",
'title' => 'roles',
'example' => '["ADMIN","SUPERUSER"]',
'items' => ['type' => 'string'],
],
@ -61,7 +61,7 @@ class JMSFunctionalTest extends WebTestCase
'type' => 'integer',
],
'email' => [
'type' => 'string'
'type' => 'string',
],
],
], $this->getModel('VirtualProperty')->toArray());

View File

@ -22,9 +22,6 @@
"zircote/swagger-php": "^2.0.9"
},
"require-dev": {
"symfony/yaml": "Temporary: see https://github.com/symfony/symfony/pull/24634/files#r153192689",
"symfony/yaml": "^2.8|^3.0|^4.0",
"symfony/templating": "^2.8|^3.0|^4.0",
"symfony/twig-bundle": "^3.0|^4.0",
"symfony/asset": "^2.8|^3.0|^4.0",