From 8e0713be5302da82c76102bf9d5215269cf7a0b3 Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Mon, 22 Jun 2020 16:37:32 +0200 Subject: [PATCH 1/3] Always use the SerializerExtractor (from the PropertyInfo component) (#1665) * Always use the SerializerExtractor (from the PropertyInfo component) * typo --- ModelDescriber/ObjectModelDescriber.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ModelDescriber/ObjectModelDescriber.php b/ModelDescriber/ObjectModelDescriber.php index db373cc..f361151 100644 --- a/ModelDescriber/ObjectModelDescriber.php +++ b/ModelDescriber/ObjectModelDescriber.php @@ -55,9 +55,9 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar $properties = $schema->getProperties(); $class = $model->getType()->getClassName(); - $context = []; + $context = ['serializer_groups' => null]; // Use the SerializerExtractor with no groups check (sf >= 5.1) if (null !== $model->getGroups()) { - $context = ['serializer_groups' => array_filter($model->getGroups(), 'is_string')]; + $context['serializer_groups'] = array_filter($model->getGroups(), 'is_string'); } $annotationsReader = new AnnotationsReader($this->doctrineReader, $this->modelRegistry); From fe39acd6a808fffd3e8ac249afd9837e9b2a00ca Mon Sep 17 00:00:00 2001 From: pratyam <48760495+pratyam@users.noreply.github.com> Date: Sat, 4 Jul 2020 16:27:40 +0200 Subject: [PATCH 2/3] Bugfix/remove pattern from property expression message error (#1670) * remove pattern added from the Expression Violation message. This string confuses the API client showing a violation message instead of having a Regex. Any informatory message for the client should be placed in "description" * fix tests * fix typo --- CHANGELOG.md | 5 +++++ .../Annotations/SymfonyConstraintAnnotationReader.php | 2 -- Tests/Describer/ApiPlatformDescriberTest.php | 2 +- Tests/Functional/FunctionalTest.php | 1 - 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08efefd..5c41e99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +3.8.0 +------ + +* remove pattern added from the Expression Violation message. + 3.7.0 (unreleased) ------------------ diff --git a/ModelDescriber/Annotations/SymfonyConstraintAnnotationReader.php b/ModelDescriber/Annotations/SymfonyConstraintAnnotationReader.php index 73f8449..f944ee0 100644 --- a/ModelDescriber/Annotations/SymfonyConstraintAnnotationReader.php +++ b/ModelDescriber/Annotations/SymfonyConstraintAnnotationReader.php @@ -69,8 +69,6 @@ class SymfonyConstraintAnnotationReader } elseif ($annotation instanceof Assert\Choice) { $values = $annotation->callback ? call_user_func(is_array($annotation->callback) ? $annotation->callback : [$reflectionProperty->class, $annotation->callback]) : $annotation->choices; $property->setEnum(array_values($values)); - } elseif ($annotation instanceof Assert\Expression) { - $this->appendPattern($property, $annotation->message); } elseif ($annotation instanceof Assert\Range) { $property->setMinimum($annotation->min); $property->setMaximum($annotation->max); diff --git a/Tests/Describer/ApiPlatformDescriberTest.php b/Tests/Describer/ApiPlatformDescriberTest.php index 5e83a03..dacfb53 100644 --- a/Tests/Describer/ApiPlatformDescriberTest.php +++ b/Tests/Describer/ApiPlatformDescriberTest.php @@ -45,7 +45,7 @@ class ApiPlatformDescriberTest extends AbstractDescriberTest $this->assertEquals($expectedApi->toArray(), $this->getSwaggerDoc()->toArray()); } - protected function setUp() + protected function setUp(): void { $this->documentation = new Documentation(new ResourceNameCollection(['dummy' => 'dummy'])); diff --git a/Tests/Functional/FunctionalTest.php b/Tests/Functional/FunctionalTest.php index 0e18c3f..7d2db9a 100644 --- a/Tests/Functional/FunctionalTest.php +++ b/Tests/Functional/FunctionalTest.php @@ -366,7 +366,6 @@ class FunctionalTest extends WebTestCase ], 'propertyExpression' => [ 'type' => 'integer', - 'pattern' => 'If this is a tech post, the category should be either php or symfony!', ], 'propertyRange' => [ 'type' => 'integer', From f4205321219704a3a278ef63d59cadf378cf7338 Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Sat, 11 Jul 2020 17:53:09 +0200 Subject: [PATCH 3/3] Support using annotations only at the class level of controllers (#1668) * Support using annotations only at the class level of controllers * Fix dependencies * Bump dependency --- Describer/SwaggerPhpDescriber.php | 2 +- .../Controller/InvokableController.php | 31 +++++++++++++++++++ Tests/Functional/FunctionalTest.php | 6 ++++ Tests/Functional/TestKernel.php | 1 + composer.json | 2 +- 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 Tests/Functional/Controller/InvokableController.php diff --git a/Describer/SwaggerPhpDescriber.php b/Describer/SwaggerPhpDescriber.php index a850273..f011e32 100644 --- a/Describer/SwaggerPhpDescriber.php +++ b/Describer/SwaggerPhpDescriber.php @@ -123,7 +123,7 @@ final class SwaggerPhpDescriber implements ModelRegistryAwareInterface return $v instanceof SWG\AbstractAnnotation; }); - if (0 === count($annotations)) { + if (0 === count($annotations) && 0 === count($classAnnotations[$declaringClass->getName()])) { continue; } diff --git a/Tests/Functional/Controller/InvokableController.php b/Tests/Functional/Controller/InvokableController.php new file mode 100644 index 0000000..5640aa6 --- /dev/null +++ b/Tests/Functional/Controller/InvokableController.php @@ -0,0 +1,31 @@ +assertFalse($modelProperties->has('bar')); $this->assertTrue($modelProperties->has('notwhatyouthink')); } + + public function testInvokableController() + { + $operation = $this->getOperation('/api/invoke', 'get'); + $this->assertSame('Invokable!', $operation->getResponses()->get(200)->getDescription()); + } } diff --git a/Tests/Functional/TestKernel.php b/Tests/Functional/TestKernel.php index d709ac5..32e9399 100644 --- a/Tests/Functional/TestKernel.php +++ b/Tests/Functional/TestKernel.php @@ -81,6 +81,7 @@ class TestKernel extends Kernel $routes->import(__DIR__.'/Controller/ApiController.php', '/', 'annotation'); $routes->import(__DIR__.'/Controller/ClassApiController.php', '/', 'annotation'); $routes->import(__DIR__.'/Controller/UndocumentedController.php', '/', 'annotation'); + $routes->import(__DIR__.'/Controller/InvokableController.php', '/', 'annotation'); $routes->import('', '/api', 'api_platform'); $routes->add('/docs/{area}', 'nelmio_api_doc.controller.swagger_ui')->setDefault('area', 'default'); $routes->add('/docs.json', 'nelmio_api_doc.controller.swagger'); diff --git a/composer.json b/composer.json index 393d2cd..3a77a8c 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ "symfony/cache": "^3.4|^4.0|^5.0", "symfony/phpunit-bridge": "^3.4.24|^4.0|^5.0", "symfony/stopwatch": "^3.4|^4.0|^5.0", - "symfony/routing": "^3.4|^4.0|^5.0", + "symfony/routing": "^3.4.42|^4.0|^5.0", "sensio/framework-extra-bundle": "^3.0.13|^4.0|^5.0", "doctrine/annotations": "^1.2", "doctrine/common": "^2.4",