376 lines
10 KiB
PHP
Raw Normal View History

<?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\Controller;
use Functional\Entity\ArticleInterface;
use Nelmio\ApiDocBundle\Annotation\Areas;
use Nelmio\ApiDocBundle\Annotation\Model;
use Nelmio\ApiDocBundle\Annotation\Operation;
use Nelmio\ApiDocBundle\Annotation\Security;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\Article;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\CompoundEntity;
Stop Model Property Description When a Schema Type or Ref is Already Defined (#1978) * Return a Result Object from AnnotationsReader::updateDefinition This is so we can make a decision on whether or not a schema's type or ref has been manually defined by a user via an `@OA\Schema` annotation as something other than an object. If it has been defined, this bundle should not read model properties any further as it causes errors. I put this in AnnotationReader as it seemed the most flexible in the long run. It could have gone in `OpenApiAnnotationsReader`, but then any additional things added to `updateDefinition` could be left out of the decision down the road. This is also a convenient place to decide this once for `ObjectModelDescriber` and `JMSModelDescriber`. * Stop Model Describer if a Schema Type or Ref Has Been Defined Via the result object added in the previous commit. This lets user "short circuit" the model describers by manually defining the schema type or ref on a plain PHP object or form. For example, a collection class could be defined like this: /** * @OA\Schema(type="array", @OA\Items(ref=@Model(type=SomeEntity::class))) */ class SomeCollection implements \IteratorAggregate { } Previously the model describer would error as it tries to merge the `array` schema with the already defiend `object` schema. Now it will prefer the array schema and skip reading all the properties of the object. * Add a Documentation Bit on Stopping Property Description * Mark UpdateClassDefinitionResult as Internal
2022-04-30 13:28:05 -05:00
use Nelmio\ApiDocBundle\Tests\Functional\Entity\EntityWithAlternateType;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\EntityWithObjectType;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\EntityWithRef;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\SymfonyConstraints;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\SymfonyConstraintsWithValidationGroups;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\SymfonyDiscriminator;
use Nelmio\ApiDocBundle\Tests\Functional\Entity\User;
use Nelmio\ApiDocBundle\Tests\Functional\Form\DummyType;
Stop Model Property Description When a Schema Type or Ref is Already Defined (#1978) * Return a Result Object from AnnotationsReader::updateDefinition This is so we can make a decision on whether or not a schema's type or ref has been manually defined by a user via an `@OA\Schema` annotation as something other than an object. If it has been defined, this bundle should not read model properties any further as it causes errors. I put this in AnnotationReader as it seemed the most flexible in the long run. It could have gone in `OpenApiAnnotationsReader`, but then any additional things added to `updateDefinition` could be left out of the decision down the road. This is also a convenient place to decide this once for `ObjectModelDescriber` and `JMSModelDescriber`. * Stop Model Describer if a Schema Type or Ref Has Been Defined Via the result object added in the previous commit. This lets user "short circuit" the model describers by manually defining the schema type or ref on a plain PHP object or form. For example, a collection class could be defined like this: /** * @OA\Schema(type="array", @OA\Items(ref=@Model(type=SomeEntity::class))) */ class SomeCollection implements \IteratorAggregate { } Previously the model describer would error as it tries to merge the `array` schema with the already defiend `object` schema. Now it will prefer the array schema and skip reading all the properties of the object. * Add a Documentation Bit on Stopping Property Description * Mark UpdateClassDefinitionResult as Internal
2022-04-30 13:28:05 -05:00
use Nelmio\ApiDocBundle\Tests\Functional\Form\FormWithAlternateSchemaType;
use Nelmio\ApiDocBundle\Tests\Functional\Form\FormWithModel;
Stop Model Property Description When a Schema Type or Ref is Already Defined (#1978) * Return a Result Object from AnnotationsReader::updateDefinition This is so we can make a decision on whether or not a schema's type or ref has been manually defined by a user via an `@OA\Schema` annotation as something other than an object. If it has been defined, this bundle should not read model properties any further as it causes errors. I put this in AnnotationReader as it seemed the most flexible in the long run. It could have gone in `OpenApiAnnotationsReader`, but then any additional things added to `updateDefinition` could be left out of the decision down the road. This is also a convenient place to decide this once for `ObjectModelDescriber` and `JMSModelDescriber`. * Stop Model Describer if a Schema Type or Ref Has Been Defined Via the result object added in the previous commit. This lets user "short circuit" the model describers by manually defining the schema type or ref on a plain PHP object or form. For example, a collection class could be defined like this: /** * @OA\Schema(type="array", @OA\Items(ref=@Model(type=SomeEntity::class))) */ class SomeCollection implements \IteratorAggregate { } Previously the model describer would error as it tries to merge the `array` schema with the already defiend `object` schema. Now it will prefer the array schema and skip reading all the properties of the object. * Add a Documentation Bit on Stopping Property Description * Mark UpdateClassDefinitionResult as Internal
2022-04-30 13:28:05 -05:00
use Nelmio\ApiDocBundle\Tests\Functional\Form\FormWithRefType;
use Nelmio\ApiDocBundle\Tests\Functional\Form\UserType;
use OpenApi\Annotations as OA;
use Symfony\Component\Routing\Annotation\Route;
class ApiController80
{
/**
* @OA\Get(
* @OA\Response(
* response="200",
* description="Success",
* @Model(type=Article::class, groups={"light"}))
* )
* )
* @OA\Parameter(ref="#/components/parameters/test")
* @Route("/article/{id}", methods={"GET"})
* @OA\Parameter(name="Accept-Version", in="header", @OA\Schema(type="string"))
* @OA\Parameter(name="Application-Name", in="header", @OA\Schema(type="string"))
*/
public function fetchArticleAction()
{
}
/**
* @OA\Get(
* @OA\Response(
* response="200",
* description="Success",
* @Model(type=ArticleInterface::class, groups={"light"}))
* )
* )
* @OA\Parameter(ref="#/components/parameters/test")
* @Route("/article-interface/{id}", methods={"GET"})
* @OA\Parameter(name="Accept-Version", in="header", @OA\Schema(type="string"))
* @OA\Parameter(name="Application-Name", in="header", @OA\Schema(type="string"))
*/
public function fetchArticleInterfaceAction()
{
}
/**
* The method LINK is not supported by OpenAPI so the method will be ignored.
*
* @Route("/swagger", methods={"GET", "LINK"})
* @Route("/swagger2", methods={"GET"})
* @Operation(
* @OA\Response(response="201", description="An example resource")
* )
* @OA\Get(
* path="/api/swagger2",
* @OA\Parameter(name="Accept-Version", in="header", @OA\Schema(type="string"))
* )
* @OA\Post(
* path="/api/swagger2",
* @OA\Response(response="203", description="but 203 is not actually allowed (wrong method)")
* )
*/
public function swaggerAction()
{
}
/**
* @Route("/swagger/implicit", methods={"GET", "POST"})
* @OA\Response(
* response="201",
* description="Operation automatically detected",
* @Model(type=User::class)
* ),
* @OA\RequestBody(
* description="This is a request body",
* @OA\JsonContent(
* type="array",
* @OA\Items(ref=@Model(type=User::class))
* )
* )
* @OA\Tag(name="implicit")
*/
public function implicitSwaggerAction()
{
}
/**
* @Route("/test/users/{user}", methods={"POST"}, schemes={"https"}, requirements={"user"="/foo/"})
* @OA\Response(
* response="201",
* description="Operation automatically detected",
* @Model(type=User::class)
* ),
* @OA\RequestBody(
* description="This is a request body",
* @Model(type=UserType::class, options={"bar": "baz"}))
* )
*/
public function submitUserTypeAction()
{
}
/**
* @Route("/test/{user}", methods={"GET"}, schemes={"https"}, requirements={"user"="/foo/"})
* @OA\Response(response=200, description="sucessful")
*/
public function userAction()
{
}
/**
* This action is deprecated.
*
* Please do not use this action.
*
* @Route("/deprecated", methods={"GET"})
*
* @deprecated
*/
public function deprecatedAction()
{
}
/**
* This action is not documented. It is excluded by the config.
*
* @Route("/admin", methods={"GET"})
*/
public function adminAction()
{
}
/**
* @OA\Get(
* path="/filtered",
* @OA\Response(response="201", description="")
* )
*/
public function filteredAction()
{
}
/**
* @Route("/form", methods={"POST"})
* @OA\RequestBody(
* description="Request content",
* @Model(type=DummyType::class))
* )
* @OA\Response(response="201", description="")
*/
public function formAction()
{
}
/**
* @Route("/form-model", methods={"POST"})
* @OA\RequestBody(
* description="Request content",
* @Model(type=FormWithModel::class))
* )
* @OA\Response(response="201", description="")
*/
public function formWithModelAction()
{
}
/**
* @Route("/security")
* @OA\Response(response="201", description="")
* @Security(name="api_key")
* @Security(name="basic")
* @Security(name="oauth2", scopes={"scope_1"})
*/
public function securityAction()
{
}
/**
* @Route("/securityOverride")
* @OA\Response(response="201", description="")
* @Security(name="api_key")
* @Security(name=null)
*/
public function securityActionOverride()
{
}
/**
* @Route("/swagger/symfonyConstraints", methods={"GET"})
* @OA\Response(
* response="201",
* description="Used for symfony constraints test",
* @Model(type=SymfonyConstraints::class)
* )
*/
public function symfonyConstraintsAction()
{
}
/**
* @OA\Response(
* response="200",
* description="Success",
* ref="#/components/schemas/Test"
* ),
* @OA\Response(
* response="201",
* ref="#/components/responses/201"
* )
* @Route("/configReference", methods={"GET"})
*/
public function configReferenceAction()
{
}
/**
* @Route("/multi-annotations", methods={"GET", "POST"})
* @OA\Get(description="This is the get operation")
* @OA\Post(description="This is post")
*
* @OA\Response(response=200, description="Worked well!", @Model(type=DummyType::class))
*/
public function operationsWithOtherAnnotations()
{
}
/**
* @Route("/areas/new", methods={"GET", "POST"})
*
* @Areas({"area", "area2"})
*/
public function newAreaAction()
{
}
/**
* @Route("/compound", methods={"GET", "POST"})
*
* @OA\Response(response=200, description="Worked well!", @Model(type=CompoundEntity::class))
*/
public function compoundEntityAction()
{
}
/**
* @Route("/discriminator-mapping", methods={"GET", "POST"})
*
* @OA\Response(response=200, description="Worked well!", @Model(type=SymfonyDiscriminator::class))
*/
public function discriminatorMappingAction()
{
}
/**
* @Route("/named_route-operation-id", name="named_route_operation_id", methods={"GET", "POST"})
*
* @OA\Response(response=200, description="success")
*/
public function namedRouteOperationIdAction()
{
}
/**
* @Route("/custom-operation-id", methods={"GET", "POST"})
*
2022-03-21 17:03:16 +01:00
* @OA\Get(operationId="get-custom-operation-id")
* @OA\Post(operationId="post-custom-operation-id")
* @OA\Response(response=200, description="success")
*/
public function customOperationIdAction()
{
}
Stop Model Property Description When a Schema Type or Ref is Already Defined (#1978) * Return a Result Object from AnnotationsReader::updateDefinition This is so we can make a decision on whether or not a schema's type or ref has been manually defined by a user via an `@OA\Schema` annotation as something other than an object. If it has been defined, this bundle should not read model properties any further as it causes errors. I put this in AnnotationReader as it seemed the most flexible in the long run. It could have gone in `OpenApiAnnotationsReader`, but then any additional things added to `updateDefinition` could be left out of the decision down the road. This is also a convenient place to decide this once for `ObjectModelDescriber` and `JMSModelDescriber`. * Stop Model Describer if a Schema Type or Ref Has Been Defined Via the result object added in the previous commit. This lets user "short circuit" the model describers by manually defining the schema type or ref on a plain PHP object or form. For example, a collection class could be defined like this: /** * @OA\Schema(type="array", @OA\Items(ref=@Model(type=SomeEntity::class))) */ class SomeCollection implements \IteratorAggregate { } Previously the model describer would error as it tries to merge the `array` schema with the already defiend `object` schema. Now it will prefer the array schema and skip reading all the properties of the object. * Add a Documentation Bit on Stopping Property Description * Mark UpdateClassDefinitionResult as Internal
2022-04-30 13:28:05 -05:00
/**
* @Route("/swagger/symfonyConstraintsWithValidationGroups", methods={"GET"})
* @OA\Response(
* response="201",
* description="Used for symfony constraints with validation groups test",
* @Model(type=SymfonyConstraintsWithValidationGroups::class, groups={"test"})
* )
*/
public function symfonyConstraintsWithGroupsAction()
{
}
Stop Model Property Description When a Schema Type or Ref is Already Defined (#1978) * Return a Result Object from AnnotationsReader::updateDefinition This is so we can make a decision on whether or not a schema's type or ref has been manually defined by a user via an `@OA\Schema` annotation as something other than an object. If it has been defined, this bundle should not read model properties any further as it causes errors. I put this in AnnotationReader as it seemed the most flexible in the long run. It could have gone in `OpenApiAnnotationsReader`, but then any additional things added to `updateDefinition` could be left out of the decision down the road. This is also a convenient place to decide this once for `ObjectModelDescriber` and `JMSModelDescriber`. * Stop Model Describer if a Schema Type or Ref Has Been Defined Via the result object added in the previous commit. This lets user "short circuit" the model describers by manually defining the schema type or ref on a plain PHP object or form. For example, a collection class could be defined like this: /** * @OA\Schema(type="array", @OA\Items(ref=@Model(type=SomeEntity::class))) */ class SomeCollection implements \IteratorAggregate { } Previously the model describer would error as it tries to merge the `array` schema with the already defiend `object` schema. Now it will prefer the array schema and skip reading all the properties of the object. * Add a Documentation Bit on Stopping Property Description * Mark UpdateClassDefinitionResult as Internal
2022-04-30 13:28:05 -05:00
/**
* @Route("/alternate-entity-type", methods={"GET", "POST"})
*
* @OA\Get(operationId="alternate-entity-type")
* @OA\Response(response=200, description="success", @OA\JsonContent(
* ref=@Model(type=EntityWithAlternateType::class),
* ))
*/
public function alternateEntityType()
{
}
/**
* @Route("/entity-with-ref", methods={"GET", "POST"})
*
* @OA\Get(operationId="entity-with-ref")
* @OA\Response(response=200, description="success", @OA\JsonContent(
* ref=@Model(type=EntityWithRef::class),
* ))
*/
public function entityWithRef()
{
}
/**
* @Route("/entity-with-object-type", methods={"GET", "POST"})
*
* @OA\Get(operationId="entity-with-object-type")
* @OA\Response(response=200, description="success", @OA\JsonContent(
* ref=@Model(type=EntityWithObjectType::class),
* ))
*/
public function entityWithObjectType()
{
}
/**
* @Route("/form-with-alternate-type", methods={"POST"})
* @OA\Response(
* response="204",
* description="Operation automatically detected",
* ),
* @OA\RequestBody(
* @Model(type=FormWithAlternateSchemaType::class))
* )
*/
public function formWithAlternateSchemaType()
{
}
/**
* @Route("/form-with-ref-type", methods={"POST"})
* @OA\Response(
* response="204",
* description="Operation automatically detected",
* ),
* @OA\RequestBody(
* @Model(type=FormWithRefType::class))
* )
*/
public function formWithRefSchemaType()
{
}
}