Merge pull request #21 from retailcrm/fos-rest-remove

Remove the support of FosRestBundle, DunglasApiBundle and JmsSecurityExtra
This commit is contained in:
Ilyas Salikhov 2024-10-01 17:35:38 +03:00 committed by GitHub
commit 49f4161b23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 50 additions and 4537 deletions

View File

@ -1,41 +0,0 @@
dist: trusty
language: php
sudo: false
cache:
directories:
- $HOME/.composer/cache
matrix:
include:
- php: 5.4
env: SYMFONY_VERSION=2.3.*
- php: 5.5
env: SYMFONY_DEPRECATIONS_HELPER=weak
- php: 5.6
env: SYMFONY_VERSION=2.7.* COVERAGE=true
- php: 5.6
env: SYMFONY_VERSION=2.8.*
- php: 5.6
env: SYMFONY_VERSION=3.0.*
- php: 7.0
env: SYMFONY_DEPRECATIONS_HELPER=weak
- php: hhvm
env: SYMFONY_DEPRECATIONS_HELPER=weak
fast_finish: true
before_install:
- if [ "$COVERAGE" != "true" ] && [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then phpenv config-rm xdebug.ini; fi
- if [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]]; then echo "memory_limit=4096M" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; fi;
before_script:
- composer self-update
- if [ "$DEPENDENCIES" = "dev" ]; then perl -pi -e 's/^}$/,"minimum-stability":"dev"}/' composer.json; fi;
- if [ "$SYMFONY_VERSION" != "3.0.*" ] && [ "$SYMFONY_VERSION" != "2.8.*" ] && [ "$SYMFONY_VERSION" != "2.7.*" ]; then sed -i "/dunglas\/api-bundle/d;/symfony\/serializer/d" composer.json; fi;
- if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi;
- composer update $COMPOSER_FLAGS
script:
- if [ "$COVERAGE" == "true" ]; then phpunit --coverage-text; else phpunit; fi

View File

@ -32,10 +32,5 @@ class LoadExtractorParsersPass implements CompilerPassInterface
if ($container->hasDefinition('jms_serializer.serializer')) {
$loader->load('services.jms.xml');
}
// DunglasJsonLdApiBundle may or may not be installed, if it is, load that config as well
if ($container->hasDefinition('api.resource_collection')) {
$loader->load('services.dunglas_api.xml');
}
}
}

View File

@ -1,125 +0,0 @@
<?php
/*
* This file is part of the NelmioApiDocBundle.
*
* (c) Nelmio <hello@nelm.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nelmio\ApiDocBundle\Extractor\Handler;
use FOS\RestBundle\Controller\Annotations\QueryParam;
use FOS\RestBundle\Controller\Annotations\RequestParam;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Nelmio\ApiDocBundle\DataTypes;
use Nelmio\ApiDocBundle\Extractor\HandlerInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\Regex;
class FosRestHandler implements HandlerInterface
{
public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method): void
{
foreach ($annotations as $annot) {
if ($annot instanceof RequestParam) {
$requirements = $this->handleRequirements($annot->requirements);
$data = [
'required' => $annot->strict && false === $annot->nullable && null === $annot->default,
'dataType' => $requirements . ((property_exists($annot, 'map') ? $annot->map : $annot->array) ? '[]' : ''),
'actualType' => $this->inferType($requirements),
'subType' => null,
'description' => $annot->description,
'readonly' => false,
];
if (false === $annot->strict) {
$data['default'] = $annot->default;
}
$annotation->addParameter($annot->name, $data);
} elseif ($annot instanceof QueryParam) {
if ($annot->strict && false === $annot->nullable && null === $annot->default) {
$annotation->addRequirement($annot->name, [
'requirement' => $this->handleRequirements($annot->requirements) . ((property_exists($annot, 'map') ? $annot->map : $annot->array) ? '[]' : ''),
'dataType' => '',
'description' => $annot->description,
]);
} elseif (null !== $annot->default) {
$annotation->addFilter($annot->name, [
'requirement' => $this->handleRequirements($annot->requirements) . ((property_exists($annot, 'map') ? $annot->map : $annot->array) ? '[]' : ''),
'description' => $annot->description,
'default' => $annot->default,
]);
} elseif (null !== $annot->requirements) {
$annotation->addFilter($annot->name, [
'requirement' => $this->handleRequirements($annot->requirements) . ((property_exists($annot, 'map') ? $annot->map : $annot->array) ? '[]' : ''),
'description' => $annot->description,
]);
} else {
$annotation->addFilter($annot->name, [
'description' => $annot->description,
]);
}
}
}
}
/**
* Handle FOSRestBundle requirements in order to return a string.
*
* @return string
*/
private function handleRequirements($requirements)
{
if (is_object($requirements) && $requirements instanceof Constraint) {
if ($requirements instanceof Regex) {
return $requirements->getHtmlPattern();
}
$class = $requirements::class;
return substr($class, strrpos($class, '\\') + 1);
}
if (is_array($requirements) && isset($requirements['rule'])) {
return (string) $requirements['rule'];
}
if (is_array($requirements) && array_key_exists(0, $requirements)) {
$output = [];
foreach ($requirements as $req) {
if (is_object($req) && $req instanceof Constraint) {
if ($req instanceof Regex) {
$output[] = $req->getHtmlPattern();
} else {
$class = $req::class;
$output[] = substr($class, strrpos($class, '\\') + 1);
}
}
if (is_array($req)) {
if (array_key_exists('_format', $req)) {
$output[] = 'Format: ' . $req['_format'];
} elseif (isset($req['rule'])) {
$output[] = $req['rule'];
}
}
}
return implode(', ', $output);
}
return (string) $requirements;
}
public function inferType($requirement)
{
if (DataTypes::isPrimitive($requirement)) {
return $requirement;
}
return DataTypes::STRING;
}
}

View File

@ -1,33 +0,0 @@
<?php
/*
* This file is part of the NelmioApiDocBundle.
*
* (c) Nelmio <hello@nelm.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nelmio\ApiDocBundle\Extractor\Handler;
use JMS\SecurityExtraBundle\Annotation\PreAuthorize;
use JMS\SecurityExtraBundle\Annotation\Secure;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Nelmio\ApiDocBundle\Extractor\HandlerInterface;
use Symfony\Component\Routing\Route;
class JmsSecurityExtraHandler implements HandlerInterface
{
public function handle(ApiDoc $annotation, array $annotations, Route $route, \ReflectionMethod $method): void
{
foreach ($annotations as $annot) {
if ($annot instanceof PreAuthorize) {
$annotation->setAuthentication(true);
} elseif ($annot instanceof Secure) {
$annotation->setAuthentication(true);
$annotation->setAuthenticationRoles(is_array($annot->roles) ? $annot->roles : explode(',', $annot->roles));
}
}
}
}

View File

@ -1,12 +1,6 @@
NelmioApiDocBundle
==================
[![Build
Status](https://secure.travis-ci.org/nelmio/NelmioApiDocBundle.png?branch=master)](http://travis-ci.org/nelmio/NelmioApiDocBundle)
[![Total Downloads](https://poser.pugx.org/nelmio/api-doc-bundle/downloads)](https://packagist.org/packages/nelmio/api-doc-bundle)
[![Latest Stable
Version](https://poser.pugx.org/nelmio/api-doc-bundle/v/stable)](https://packagist.org/packages/nelmio/api-doc-bundle)
The **NelmioApiDocBundle** bundle allows you to generate a decent documentation
for your APIs.

View File

@ -9,8 +9,6 @@
<parameter key="nelmio_api_doc.twig.extension.extra_markdown.class">Nelmio\ApiDocBundle\Twig\Extension\MarkdownExtension</parameter>
<parameter key="nelmio_api_doc.doc_comment_extractor.class">Nelmio\ApiDocBundle\Util\DocCommentExtractor</parameter>
<parameter key="nelmio_api_doc.extractor.handler.fos_rest.class">Nelmio\ApiDocBundle\Extractor\Handler\FosRestHandler</parameter>
<parameter key="nelmio_api_doc.extractor.handler.jms_security.class">Nelmio\ApiDocBundle\Extractor\Handler\JmsSecurityExtraHandler</parameter>
<parameter key="nelmio_api_doc.extractor.handler.phpdoc.class">Nelmio\ApiDocBundle\Extractor\Handler\PhpDocHandler</parameter>
<parameter key="nelmio_api_doc.parser.collection_parser.class">Nelmio\ApiDocBundle\Parser\CollectionParser</parameter>
@ -43,14 +41,6 @@
<!-- Extractor Annotation Handlers -->
<service id="nelmio_api_doc.extractor.handler.fos_rest" class="%nelmio_api_doc.extractor.handler.fos_rest.class%" public="false">
<tag name="nelmio_api_doc.extractor.handler"/>
</service>
<service id="nelmio_api_doc.extractor.handler.jms_security" class="%nelmio_api_doc.extractor.handler.jms_security.class%" public="false">
<tag name="nelmio_api_doc.extractor.handler"/>
</service>
<service id="nelmio_api_doc.extractor.handler.phpdoc" class="%nelmio_api_doc.extractor.handler.phpdoc.class%" public="false">
<argument type="service" id="nelmio_api_doc.doc_comment_extractor" />
<tag name="nelmio_api_doc.extractor.handler"/>

View File

@ -1,23 +0,0 @@
DunglasApiBundle Support
========================
This bundle recognizes and documents resources exposed with
`DunglasApiBundle`_.
Install NelmioApiDocBundle and the documentation will be automatically
available. To enable the sandbox, use the following configuration:
.. code-block:: yaml
# app/config/config.yml
nelmio_api_doc:
sandbox:
accept_type: "application/json"
body_format:
formats: [ "json" ]
default_format: "json"
request_format:
formats:
json: "application/json"
.. _`DunglasApiBundle`: https://github.com/dunglas/DunglasApiBundle

View File

@ -94,7 +94,6 @@ setup your API documentation:
multiple-api-doc
other-bundle-annotations
swagger-support
dunglasapibundle
sandbox
commands
configuration-in-depth

View File

@ -1,14 +1,6 @@
Other Bundle Annotations
========================
This bundle will get information from the following other annotations:
* ``@FOS\RestBundle\Controller\Annotations\RequestParam`` - use as ``parameters``
* ``@FOS\RestBundle\Controller\Annotations\QueryParam`` - use as ``requirements``
(when strict parameter is true), ``filters`` (when strict is false)
* ``@JMS\SecurityExtraBundle\Annotation\Secure`` - set ``authentication`` to true,
``authenticationRoles`` to the given roles
PHPDoc
------

View File

@ -1,44 +0,0 @@
<?php
/*
* This file is part of the NelmioApiDocBundle.
*
* (c) Nelmio <hello@nelm.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nelmio\ApiDocBundle\Tests\Extractor\AnnotationsProvider;
use Nelmio\ApiDocBundle\Tests\WebTestCase;
/**
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class DunglasApiProviderTest extends WebTestCase
{
protected function setUp(): void
{
if (!class_exists('Dunglas\ApiBundle\DunglasApiBundle')) {
$this->markTestSkipped(
'DunglasApiBundle is not available.'
);
}
}
public function testGetAnnotations(): void
{
$container = $this->getContainer();
$provider = $container->get('nelmio_api_doc.annotations_provider.dunglas_api_annotation_provider');
$annotations = $provider->getAnnotations();
$this->assertCount(5, $annotations);
foreach ($annotations as $annotation) {
$this->assertInstanceOf('Nelmio\ApiDocBundle\Annotation\ApiDoc', $annotation);
$this->assertInstanceOf('Symfony\Component\Routing\Route', $annotation->getRoute());
$this->assertTrue('' != $annotation->getDescription());
}
}
}

View File

@ -17,21 +17,10 @@ use Nelmio\ApiDocBundle\Tests\WebTestCase;
class ApiDocExtractorTest extends WebTestCase
{
public const NB_ROUTES_ADDED_BY_DUNGLAS_API_BUNDLE = 5;
private static $ROUTES_QUANTITY_DEFAULT = 36; // Routes in the default view
private static $ROUTES_QUANTITY_DEFAULT = 28; // Routes in the default view
private static $ROUTES_QUANTITY_PREMIUM = 5; // Routes in the premium view
private static $ROUTES_QUANTITY_TEST = 2; // Routes in the test view
public static function setUpBeforeClass(): void
{
if (class_exists('Dunglas\ApiBundle\DunglasApiBundle')) {
self::$ROUTES_QUANTITY_DEFAULT += self::NB_ROUTES_ADDED_BY_DUNGLAS_API_BUNDLE;
self::$ROUTES_QUANTITY_PREMIUM += self::NB_ROUTES_ADDED_BY_DUNGLAS_API_BUNDLE;
self::$ROUTES_QUANTITY_TEST += self::NB_ROUTES_ADDED_BY_DUNGLAS_API_BUNDLE;
}
}
public function testAll(): void
{
$container = $this->getContainer();
@ -40,11 +29,6 @@ class ApiDocExtractorTest extends WebTestCase
$data = $extractor->all();
restore_error_handler();
$httpsKey = 21;
if (class_exists('Dunglas\ApiBundle\DunglasApiBundle')) {
$httpsKey += self::NB_ROUTES_ADDED_BY_DUNGLAS_API_BUNDLE;
}
$this->assertTrue(is_array($data));
$this->assertCount(self::$ROUTES_QUANTITY_DEFAULT, $data);
@ -61,39 +45,6 @@ class ApiDocExtractorTest extends WebTestCase
$this->assertInstanceOf('Symfony\Component\Routing\Route', $d['annotation']->getRoute());
$this->assertNotNull($d['resource']);
}
// $a1 = $data[7]['annotation'];
// $array1 = $a1->toArray();
// $this->assertTrue($a1->isResource());
// $this->assertEquals('index action', $a1->getDescription());
// $this->assertTrue(is_array($array1['filters']));
// $this->assertNull($a1->getInput());
//
// $a2 = $data[8]['annotation'];
// $array2 = $a2->toArray();
// $this->assertFalse($a2->isResource());
// $this->assertEquals('create test', $a2->getDescription());
// $this->assertFalse(isset($array2['filters']));
// $this->assertEquals('Nelmio\ApiDocBundle\Tests\Fixtures\Form\TestType', $a2->getInput());
//
// $a2 = $data[9]['annotation'];
// $array2 = $a2->toArray();
// $this->assertFalse($a2->isResource());
// $this->assertEquals('create test', $a2->getDescription());
// $this->assertFalse(isset($array2['filters']));
// $this->assertEquals('Nelmio\ApiDocBundle\Tests\Fixtures\Form\TestType', $a2->getInput());
//
// $a3 = $data[$httpsKey]['annotation'];
// $this->assertTrue($a3->getHttps());
//
// $a4 = $data[11]['annotation'];
// $this->assertTrue($a4->isResource());
// $this->assertEquals('TestResource', $a4->getResource());
//
// $a5 = $data[$httpsKey - 1]['annotation'];
// $a5requirements = $a5->getRequirements();
// $this->assertEquals('api.test.dev', $a5->getHost());
// $this->assertEquals('test.dev|test.com', $a5requirements['domain']['requirement']);
}
public function testRouteVersionChecking(): void
@ -298,12 +249,9 @@ class ApiDocExtractorTest extends WebTestCase
$this->assertFalse($parameters['required_field']['required']);
}
public static function dataProviderForViews()
public static function dataProviderForViews(): array
{
$offset = 0;
if (class_exists('Dunglas\ApiBundle\DunglasApiBundle')) {
$offset = self::NB_ROUTES_ADDED_BY_DUNGLAS_API_BUNDLE;
}
return [
['default', self::$ROUTES_QUANTITY_DEFAULT + $offset],

View File

@ -1,205 +0,0 @@
<?php
/*
* This file is part of the NelmioApiDocBundle.
*
* (c) Nelmio <hello@nelm.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nelmio\ApiDocBundle\Tests\Extractor;
use Nelmio\ApiDocBundle\Tests\WebTestCase;
class FosRestHandlerTest extends WebTestCase
{
public function testGetWithQueryParamStrict(): void
{
$container = $this->getContainer();
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithQueryParamStrictAction', 'test_route_15');
$this->assertNotNull($annotation);
$requirements = $annotation->getRequirements();
$this->assertCount(1, $requirements);
$this->assertArrayHasKey('page', $requirements);
$requirement = $requirements['page'];
$this->assertArrayHasKey('requirement', $requirement);
$this->assertEquals($requirement['requirement'], '\d+');
$this->assertArrayHasKey('description', $requirement);
$this->assertEquals($requirement['description'], 'Page of the overview.');
$this->assertArrayHasKey('dataType', $requirement);
$this->assertArrayNotHasKey('default', $requirement);
}
public function testGetWithQueryParam(): void
{
$container = $this->getContainer();
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithQueryParamAction', 'test_route_8');
$this->assertNotNull($annotation);
$filters = $annotation->getFilters();
$this->assertCount(1, $filters);
$this->assertArrayHasKey('page', $filters);
$filter = $filters['page'];
$this->assertArrayHasKey('requirement', $filter);
$this->assertEquals($filter['requirement'], '\d+');
$this->assertArrayHasKey('description', $filter);
$this->assertEquals($filter['description'], 'Page of the overview.');
$this->assertArrayHasKey('default', $filter);
$this->assertEquals($filter['default'], '1');
}
public function testGetWithQueryParamNoDefault(): void
{
$container = $this->getContainer();
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithQueryParamNoDefaultAction', 'test_route_16');
$this->assertNotNull($annotation);
$filters = $annotation->getFilters();
$this->assertCount(1, $filters);
$this->assertArrayHasKey('page', $filters);
$filter = $filters['page'];
$this->assertArrayHasKey('requirement', $filter);
$this->assertEquals($filter['requirement'], '\d+');
$this->assertArrayHasKey('description', $filter);
$this->assertEquals($filter['description'], 'Page of the overview.');
$this->assertArrayNotHasKey('default', $filter);
}
public function testGetWithConstraintAsRequirements(): void
{
$container = $this->getContainer();
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithConstraintAsRequirements', 'test_route_21');
$this->assertNotNull($annotation);
$filters = $annotation->getFilters();
$this->assertCount(1, $filters);
$this->assertArrayHasKey('mail', $filters);
$filter = $filters['mail'];
$this->assertArrayHasKey('requirement', $filter);
$this->assertEquals($filter['requirement'], 'Email');
}
public function testGetWithRequestParam(): void
{
$container = $this->getContainer();
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithRequestParamAction', 'test_route_11');
$this->assertNotNull($annotation);
$parameters = $annotation->getParameters();
$this->assertCount(1, $parameters);
$this->assertArrayHasKey('param1', $parameters);
$parameter = $parameters['param1'];
$this->assertArrayHasKey('dataType', $parameter);
$this->assertEquals($parameter['dataType'], 'string');
$this->assertArrayHasKey('description', $parameter);
$this->assertEquals($parameter['description'], 'Param1 description.');
$this->assertArrayHasKey('required', $parameter);
$this->assertEquals($parameter['required'], true);
$this->assertArrayNotHasKey('default', $parameter);
}
public function testGetWithRequestParamNullable(): void
{
$container = $this->getContainer();
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithNullableRequestParamAction', 'test_route_22');
$this->assertNotNull($annotation);
$parameters = $annotation->getParameters();
$this->assertCount(1, $parameters);
$this->assertArrayHasKey('param1', $parameters);
$parameter = $parameters['param1'];
$this->assertArrayHasKey('dataType', $parameter);
$this->assertEquals($parameter['dataType'], 'string');
$this->assertArrayHasKey('description', $parameter);
$this->assertEquals($parameter['description'], 'Param1 description.');
$this->assertArrayHasKey('required', $parameter);
$this->assertEquals($parameter['required'], false);
$this->assertArrayNotHasKey('default', $parameter);
}
public function testWithRequestParamArrayRequirements(): void
{
$container = $this->getContainer();
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::routeWithQueryParamArrayRequirementsAction', 'test_route_29');
$this->assertNotNull($annotation);
$filters = $annotation->getFilters();
$this->assertArrayHasKey('param1', $filters);
$this->assertArrayHasKey('requirement', $filters['param1']);
$this->assertEquals('regexp', $filters['param1']['requirement']);
}
public function testWithRequestParamPlainArrayRequirements(): void
{
$container = $this->getContainer();
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::routeWithQueryParamPlainArrayRequirementsAction', 'test_route_30');
$this->assertNotNull($annotation);
$filters = $annotation->getFilters();
$this->assertArrayHasKey('param1', $filters);
$this->assertArrayHasKey('requirement', $filters['param1']);
$this->assertEquals('NotNull, NotBlank', $filters['param1']['requirement']);
}
public function testWithRequirementParamNotSet(): void
{
$container = $this->getContainer();
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithRequirementParamNotSet', 'test_route_31');
$this->assertNotNull($annotation);
$filters = $annotation->getFilters();
$this->assertCount(1, $filters);
$this->assertArrayHasKey('param1', $filters);
$filter = $filters['param1'];
$this->assertArrayNotHasKey('requirement', $filter);
$this->assertArrayHasKey('description', $filter);
$this->assertEquals($filter['description'], 'Param1 description.');
}
}

View File

@ -11,12 +11,9 @@
namespace Nelmio\ApiDocBundle\Tests\Fixtures\Controller;
use FOS\RestBundle\Controller\Annotations\QueryParam;
use FOS\RestBundle\Controller\Annotations\RequestParam;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Nelmio\ApiDocBundle\Tests\Fixtures\DependencyTypePath;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
class TestController
{
@ -128,42 +125,6 @@ class TestController
{
}
/**
* @ApiDoc()
*
* @QueryParam(strict=true, name="page", requirements="\d+", description="Page of the overview.")
*/
public function zActionWithQueryParamStrictAction(): void
{
}
/**
* @ApiDoc()
*
* @QueryParam(name="page", requirements="\d+", default="1", description="Page of the overview.")
*/
public function zActionWithQueryParamAction(): void
{
}
/**
* @ApiDoc()
*
* @QueryParam(name="page", requirements="\d+", description="Page of the overview.")
*/
public function zActionWithQueryParamNoDefaultAction(): void
{
}
/**
* @ApiDoc()
*
* @QueryParam(name="mail", requirements=@Assert\Email, description="Email of someone.")
*/
public function zActionWithConstraintAsRequirements(): void
{
}
/**
* @ApiDoc(
* description="Testing JMS",
@ -184,24 +145,6 @@ class TestController
{
}
/**
* @ApiDoc()
*
* @RequestParam(name="param1", requirements="string", description="Param1 description.")
*/
public function zActionWithRequestParamAction(): void
{
}
/**
* @ApiDoc()
*
* @RequestParam(name="param1", requirements="string", description="Param1 description.", nullable=true)
*/
public function zActionWithNullableRequestParamAction(): void
{
}
/**
* @ApiDoc()
*/
@ -400,31 +343,4 @@ class TestController
public function routeWithHostAction(): void
{
}
/**
* @ApiDoc()
*
* @QueryParam(name="param1", requirements={"rule": "regexp", "error_message": "warning"}, description="Param1 description.")
*/
public function routeWithQueryParamArrayRequirementsAction(): void
{
}
/**
* @ApiDoc()
*
* @QueryParam(name="param1", requirements={@Assert\NotNull(), @Assert\NotBlank()}, description="Param1 description.")
*/
public function routeWithQueryParamPlainArrayRequirementsAction(): void
{
}
/**
* @ApiDoc()
*
* @QueryParam(name="param1", description="Param1 description.")
*/
public function zActionWithRequirementParamNotSet(): void
{
}
}

View File

@ -11,9 +11,6 @@
namespace Nelmio\ApiDocBundle\Tests\Fixtures\Model;
/**
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class Popo
{
/**

View File

@ -29,11 +29,6 @@ class AppKernel extends Kernel
new \Nelmio\ApiDocBundle\Tests\Fixtures\NelmioApiDocTestBundle(),
];
if (class_exists('Dunglas\ApiBundle\DunglasApiBundle')) {
$bundles[] = new \Doctrine\Bundle\DoctrineBundle\DoctrineBundle();
$bundles[] = new \Dunglas\ApiBundle\DunglasApiBundle();
}
return $bundles;
}
@ -56,10 +51,6 @@ class AppKernel extends Kernel
{
$loader->load(__DIR__ . '/config/' . $this->environment . '.yml');
if (class_exists('Dunglas\ApiBundle\DunglasApiBundle')) {
$loader->load(__DIR__ . '/config/dunglas_api.yml');
}
// If symfony/framework-bundle > 3.0
if (!class_exists('Symfony\Bundle\FrameworkBundle\Command\RouterApacheDumperCommand')) {
$loader->load(__DIR__ . '/config/twig_assets.yml');

View File

@ -1,22 +0,0 @@
doctrine:
dbal:
driver: "pdo_sqlite"
path: "%kernel.cache_dir%/db.sqlite"
charset: "UTF8"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
framework:
router: { resource: "%kernel.project_dir%/config/dunglas_api_routing.yml" }
dunglas_api:
title: API
description: Test API
services:
dunglas_api.popo:
parent: api.resource
arguments: [ Nelmio\ApiDocBundle\Tests\Fixtures\Model\Popo ]
tags: [ { name: api.resource } ]

View File

@ -1,6 +0,0 @@
main:
resource: "routing.yml"
dunglas_api:
resource: "."
type: "api"

View File

@ -32,11 +32,6 @@ test_route_7:
methods: [POST]
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::anotherPostAction, _format: json }
test_route_8:
path: /z-action-with-query-param
methods: [GET]
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithQueryParamAction }
test_route_9:
path: /jms-input-test
methods: [POST]
@ -47,11 +42,6 @@ test_route_10:
methods: [GET]
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::jmsReturnTestAction }
test_route_11:
path: /z-action-with-request-param
methods: [POST]
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithRequestParamAction }
test_route_12:
path: /secure-route
schemes: [https]
@ -89,16 +79,6 @@ test_route_14:
methods: [POST]
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::postTest2Action, _format: json }
test_route_15:
path: /z-action-with-query-param-strict
methods: [GET]
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithQueryParamStrictAction }
test_route_16:
path: /z-action-with-query-param-no-default
methods: [GET]
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithQueryParamNoDefaultAction }
test_route_17:
path: /z-action-with-deprecated-indicator
methods: [GET]
@ -136,16 +116,6 @@ test_route_exclusive:
path: /exclusive
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::exclusiveAction }
test_route_21:
path: /z-action-with-constraint-requirements
methods: [GET]
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithConstraintAsRequirementsAction }
test_route_22:
path: /z-action-with-nullable-request-param
methods: [POST]
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithNullableRequestParamAction }
test_route_list_resource:
path: /api/resources.{_format}
methods: [GET]
@ -239,21 +209,6 @@ test_route_28:
domain: "%domain_dev%|%domain_prod%"
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::routeWithHostAction, domain: "%domain_dev%", _format: json }
test_route_29:
path: /z-query-param-array-requirements
methods: [GET]
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::routeWithQueryParamArrayRequirementsAction }
test_route_30:
path: /z-query-param-plain-array-requirements
methods: [GET]
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::routeWithQueryParamPlainArrayRequirementsAction }
test_route_31:
path: /z-query-requirement-param-not-set
methods: [GET]
defaults: { _controller: Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithRequirementParamNotSet }
test_route_version_checking:
path: /zz-tests-route-version.{_format}
methods: [GET]

View File

@ -26,13 +26,13 @@ class MarkdownFormatterTest extends WebTestCase
restore_error_handler();
$result = $container->get('nelmio_api_doc.formatter.markdown_formatter')->format($data);
$suffix = class_exists('Dunglas\ApiBundle\DunglasApiBundle') ? '' : '_1';
$suffix = '_1';
$expected = file_get_contents(__DIR__ . '/testFormat-result' . $suffix . '.markdown');
if (LegacyFormHelper::isLegacy()) {
$expected = str_replace('DependencyType', 'dependency_type', $expected);
}
$this->assertEquals($expected, $result . "\n");
$this->assertEquals($expected, $result . "\n", 'file ' . __DIR__ . '/testFormat-result' . $suffix . '.markdown');
}
public function testFormatOne(): void

View File

@ -25,10 +25,10 @@ class SimpleFormatterTest extends WebTestCase
restore_error_handler();
$result = $container->get('nelmio_api_doc.formatter.simple_formatter')->format($data);
$suffix = class_exists('Dunglas\ApiBundle\DunglasApiBundle') ? '' : '_1';
$suffix = '_1';
$expected = require __DIR__ . '/testFormat-result' . $suffix . '.php';
$this->assertEquals($expected, $result);
$this->assertEquals($expected, $result, 'file ' . __DIR__ . '/testFormat-result' . $suffix . '.php');
}
public function testFormatOne(): void

View File

@ -41,119 +41,51 @@ class SwaggerFormatterTest extends WebTestCase
/** @var $formatter SwaggerFormatter */
$actual = $this->formatter->format($data, null);
if (class_exists('Dunglas\ApiBundle\DunglasApiBundle')) {
$expected = [
'swaggerVersion' => '1.2',
'apis' => [
0 => [
'path' => '/other-resources',
'description' => 'Operations on another resource.',
],
1 => [
'path' => '/resources',
'description' => 'Operations on resource.',
],
2 => [
'path' => '/tests',
'description' => null,
],
3 => [
'path' => '/tests',
'description' => null,
],
4 => [
'path' => '/tests2',
'description' => null,
],
5 => [
'path' => '/TestResource',
'description' => null,
],
6 => [
'path' => '/others',
'description' => 'Popo',
],
7 => [
'path' => '/others',
'description' => 'Popo',
],
8 => [
'path' => '/others',
'description' => 'Popo',
],
9 => [
'path' => '/others',
'description' => 'Popo',
],
10 => [
'path' => '/others',
'description' => 'Popo',
],
$expected = [
'swaggerVersion' => '1.2',
'apiVersion' => '3.14',
'info' => [
'title' => 'Nelmio Swagger',
'description' => 'Testing Swagger integration.',
'TermsOfServiceUrl' => 'https://github.com',
'contact' => 'user@domain.tld',
'license' => 'MIT',
'licenseUrl' => 'http://opensource.org/licenses/MIT',
],
'authorizations' => [
'apiKey' => [
'type' => 'apiKey',
'passAs' => 'header',
'keyname' => 'access_token',
],
'apiVersion' => '3.14',
'info' => [
'title' => 'Nelmio Swagger',
'description' => 'Testing Swagger integration.',
'TermsOfServiceUrl' => 'https://github.com',
'contact' => 'user@domain.tld',
'license' => 'MIT',
'licenseUrl' => 'http://opensource.org/licenses/MIT',
],
'apis' => [
[
'path' => '/other-resources',
'description' => 'Operations on another resource.',
],
'authorizations' => [
'apiKey' => [
'type' => 'apiKey',
'passAs' => 'header',
'keyname' => 'access_token',
],
[
'path' => '/resources',
'description' => 'Operations on resource.',
],
];
} else {
$expected = [
'swaggerVersion' => '1.2',
'apiVersion' => '3.14',
'info' => [
'title' => 'Nelmio Swagger',
'description' => 'Testing Swagger integration.',
'TermsOfServiceUrl' => 'https://github.com',
'contact' => 'user@domain.tld',
'license' => 'MIT',
'licenseUrl' => 'http://opensource.org/licenses/MIT',
[
'path' => '/tests',
'description' => null,
],
'authorizations' => [
'apiKey' => [
'type' => 'apiKey',
'passAs' => 'header',
'keyname' => 'access_token',
],
[
'path' => '/tests',
'description' => null,
],
'apis' => [
[
'path' => '/other-resources',
'description' => 'Operations on another resource.',
],
[
'path' => '/resources',
'description' => 'Operations on resource.',
],
[
'path' => '/tests',
'description' => null,
],
[
'path' => '/tests',
'description' => null,
],
[
'path' => '/tests2',
'description' => null,
],
[
'path' => '/TestResource',
'description' => null,
],
[
'path' => '/tests2',
'description' => null,
],
];
}
[
'path' => '/TestResource',
'description' => null,
],
],
];
$this->assertEquals($expected, $actual);
}

View File

@ -1816,91 +1816,6 @@ With multiple lines.',
],
'deprecated' => true,
],
12 => [
'method' => 'POST',
'uri' => '/z-action-with-nullable-request-param',
'parameters' => [
'param1' => [
'required' => false,
'dataType' => 'string',
'actualType' => 'string',
'subType' => null,
'description' => 'Param1 description.',
'readonly' => false,
],
],
'https' => false,
'authentication' => false,
'authenticationRoles' => [
],
'deprecated' => false,
],
13 => [
'method' => 'GET',
'uri' => '/z-action-with-query-param',
'filters' => [
'page' => [
'requirement' => '\\d+',
'description' => 'Page of the overview.',
'default' => '1',
],
],
'https' => false,
'authentication' => false,
'authenticationRoles' => [
],
'deprecated' => false,
],
14 => [
'method' => 'GET',
'uri' => '/z-action-with-query-param-no-default',
'filters' => [
'page' => [
'requirement' => '\\d+',
'description' => 'Page of the overview.',
],
],
'https' => false,
'authentication' => false,
'authenticationRoles' => [
],
'deprecated' => false,
],
15 => [
'method' => 'GET',
'uri' => '/z-action-with-query-param-strict',
'requirements' => [
'page' => [
'requirement' => '\\d+',
'dataType' => '',
'description' => 'Page of the overview.',
],
],
'https' => false,
'authentication' => false,
'authenticationRoles' => [
],
'deprecated' => false,
],
16 => [
'method' => 'POST',
'uri' => '/z-action-with-request-param',
'parameters' => [
'param1' => [
'required' => true,
'dataType' => 'string',
'actualType' => 'string',
'subType' => null,
'description' => 'Param1 description.',
'readonly' => false,
],
],
'https' => false,
'authentication' => false,
'authenticationRoles' => [
],
'deprecated' => false,
],
17 => [
'method' => 'ANY',
'uri' => '/z-return-jms-and-validator-output',

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -710,96 +710,6 @@ _Route with host placeholder_
### `POST` /z-action-with-nullable-request-param ###
#### Parameters ####
param1:
* type: string
* required: false
* description: Param1 description.
### `GET` /z-action-with-query-param ###
#### Filters ####
page:
* Requirement: \d+
* Description: Page of the overview.
* Default: 1
### `GET` /z-action-with-query-param-no-default ###
#### Filters ####
page:
* Requirement: \d+
* Description: Page of the overview.
### `GET` /z-action-with-query-param-strict ###
#### Requirements ####
**page**
- Requirement: \d+
- Description: Page of the overview.
### `POST` /z-action-with-request-param ###
#### Parameters ####
param1:
* type: string
* required: true
* description: Param1 description.
### `GET` /z-query-param-array-requirements ###
#### Filters ####
param1:
* Requirement: regexp
* Description: Param1 description.
### `GET` /z-query-param-plain-array-requirements ###
#### Filters ####
param1:
* Requirement: NotNull, NotBlank
* Description: Param1 description.
### `GET` /z-query-requirement-param-not-set ###
#### Filters ####
param1:
* Description: Param1 description.
### `ANY` /z-return-jms-and-validator-output ###

View File

@ -1750,143 +1750,6 @@ With multiple lines.',
'scope' => null,
],
12 => [
'method' => 'POST',
'uri' => '/z-action-with-nullable-request-param',
'parameters' => [
'param1' => [
'required' => false,
'dataType' => 'string',
'actualType' => 'string',
'subType' => null,
'description' => 'Param1 description.',
'readonly' => false,
],
],
'https' => false,
'authentication' => false,
'authenticationRoles' => [
],
'deprecated' => false,
'scope' => null,
],
13 => [
'method' => 'GET',
'uri' => '/z-action-with-query-param',
'filters' => [
'page' => [
'requirement' => '\\d+',
'description' => 'Page of the overview.',
'default' => '1',
],
],
'https' => false,
'authentication' => false,
'authenticationRoles' => [
],
'deprecated' => false,
'scope' => null,
],
14 => [
'method' => 'GET',
'uri' => '/z-action-with-query-param-no-default',
'filters' => [
'page' => [
'requirement' => '\\d+',
'description' => 'Page of the overview.',
],
],
'https' => false,
'authentication' => false,
'authenticationRoles' => [
],
'deprecated' => false,
'scope' => null,
],
15 => [
'method' => 'GET',
'uri' => '/z-action-with-query-param-strict',
'requirements' => [
'page' => [
'requirement' => '\\d+',
'dataType' => '',
'description' => 'Page of the overview.',
],
],
'https' => false,
'authentication' => false,
'authenticationRoles' => [
],
'deprecated' => false,
'scope' => null,
],
16 => [
'method' => 'POST',
'uri' => '/z-action-with-request-param',
'parameters' => [
'param1' => [
'required' => true,
'dataType' => 'string',
'actualType' => 'string',
'subType' => null,
'description' => 'Param1 description.',
'readonly' => false,
],
],
'https' => false,
'authentication' => false,
'authenticationRoles' => [
],
'deprecated' => false,
'scope' => null,
],
17 => [
'method' => 'GET',
'uri' => '/z-query-param-array-requirements',
'filters' => [
'param1' => [
'requirement' => 'regexp',
'description' => 'Param1 description.',
],
],
'https' => false,
'authentication' => false,
'authenticationRoles' => [
],
'deprecated' => false,
'scope' => null,
],
18 => [
'method' => 'GET',
'uri' => '/z-query-param-plain-array-requirements',
'filters' => [
'param1' => [
'requirement' => 'NotNull, NotBlank',
'description' => 'Param1 description.',
],
],
'https' => false,
'authentication' => false,
'authenticationRoles' => [
],
'deprecated' => false,
'scope' => null,
],
19 => [
'method' => 'GET',
'uri' => '/z-query-requirement-param-not-set',
'filters' => [
'param1' => [
'description' => 'Param1 description.',
],
],
'https' => false,
'authentication' => false,
'authenticationRoles' => [
],
'deprecated' => false,
'scope' => null,
],
20 => [
'method' => 'ANY',
'uri' => '/z-return-jms-and-validator-output',
'response' => [
@ -2006,7 +1869,7 @@ With multiple lines.',
'deprecated' => false,
'scope' => null,
],
21 => [
13 => [
'method' => 'ANY',
'uri' => '/z-return-selected-parsers-input',
'parameters' => [
@ -2054,7 +1917,7 @@ With multiple lines.',
'deprecated' => false,
'scope' => null,
],
22 => [
14 => [
'method' => 'ANY',
'uri' => '/z-return-selected-parsers-output',
'response' => [
@ -2174,7 +2037,7 @@ With multiple lines.',
'deprecated' => false,
'scope' => null,
],
23 => [
15 => [
'method' => 'POST',
'uri' => '/zcached',
'https' => false,
@ -2184,7 +2047,7 @@ With multiple lines.',
'deprecated' => false,
'scope' => null,
],
24 => [
16 => [
'method' => 'POST',
'uri' => '/zsecured',
'https' => false,
@ -2194,7 +2057,7 @@ With multiple lines.',
'deprecated' => false,
'scope' => null,
],
25 => [
17 => [
'method' => 'GET',
'uri' => '/zz-tests-route-version.{_format}',
'requirements' => [

View File

@ -13,9 +13,5 @@ if ((!$loader = includeIfExists(__DIR__ . '/../vendor/autoload.php')) && (!$load
'php composer.phar install' . PHP_EOL);
}
if (class_exists('Doctrine\Common\Annotations\AnnotationRegistry')) {
Doctrine\Common\Annotations\AnnotationRegistry::registerLoader([$loader, 'loadClass']);
}
// force loading the ApiDoc annotation since the composer target-dir autoloader does not run through $loader::loadClass
class_exists('Nelmio\ApiDocBundle\Annotation\ApiDoc');

View File

@ -25,7 +25,6 @@
"require-dev": {
"doctrine/annotations": "^1.0",
"friendsofphp/php-cs-fixer": "^3",
"friendsofsymfony/rest-bundle": "^3.7",
"jms/serializer": "^3.15",
"jms/serializer-bundle": "^4.1|^5.4",
"phpunit/phpunit": "~9.5",
@ -45,7 +44,6 @@
"suggest": {
"symfony/form": "For using form definitions as input.",
"symfony/validator": "For making use of validator information in the doc.",
"friendsofsymfony/rest-bundle": "For making use of REST information in the doc.",
"jms/serializer": "For making use of serializer information in the doc."
},
"autoload": {