Skip to content

Instantly share code, notes, and snippets.

@chrisguitarguy
Created March 28, 2022 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisguitarguy/077790c508cd2ebae575763fc6dcc598 to your computer and use it in GitHub Desktop.
Save chrisguitarguy/077790c508cd2ebae575763fc6dcc598 to your computer and use it in GitHub Desktop.
Use rector Replace OpenAPI PHP annotations with Attributes, but note that you'll need to change the namespace from `OpenApi\Annotations` to `OpenApi\Attributes` after this is done.
<?php declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Php80\Rector\Class_\AnnotationToAttributeRector;
use Rector\Php80\ValueObject\AnnotationToAttribute;
use Rector\Symfony\Set\SymfonySetList;
use OpenApi\Annotations as OA;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\Serializer\Annotation as Serializer;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$parameters = $containerConfigurator->parameters();
// catch all the serializer annotations too
$services->set(AnnotationToAttributeRector::class)->configure([
new AnnotationToAttribute(Serializer\DiscriminatorMap::class),
new AnnotationToAttribute(Serializer\Context::class),
new AnnotationToAttribute(Serializer\Groups::class),
new AnnotationToAttribute(Serializer\Ignore::class),
new AnnotationToAttribute(Serializer\MaxDepth::class),
new AnnotationToAttribute(Serializer\SerializedName::class),
]);
$services->set(AnnotationToAttributeRector::class)->configure([
new AnnotationToAttribute(OA\AdditionalProperties::class),
new AnnotationToAttribute(OA\Attachable::class),
new AnnotationToAttribute(OA\Components::class),
new AnnotationToAttribute(OA\Contact::class),
new AnnotationToAttribute(OA\Delete::class),
new AnnotationToAttribute(OA\Discriminator::class),
new AnnotationToAttribute(OA\Examples::class),
new AnnotationToAttribute(OA\ExternalDocumentation::class),
new AnnotationToAttribute(OA\Flow::class),
new AnnotationToAttribute(OA\Get::class),
new AnnotationToAttribute(OA\Head::class),
new AnnotationToAttribute(OA\Header::class),
new AnnotationToAttribute(OA\Info::class),
new AnnotationToAttribute(OA\Items::class),
new AnnotationToAttribute(OA\JsonContent::class),
new AnnotationToAttribute(OA\License::class),
new AnnotationToAttribute(OA\Link::class),
new AnnotationToAttribute(OA\MediaType::class),
new AnnotationToAttribute(OA\OpenApi::class),
new AnnotationToAttribute(OA\Operation::class),
new AnnotationToAttribute(OA\Options::class),
new AnnotationToAttribute(OA\Parameter::class),
new AnnotationToAttribute(OA\Patch::class),
new AnnotationToAttribute(OA\PathItem::class),
new AnnotationToAttribute(OA\PathParameter::class),
new AnnotationToAttribute(OA\Post::class),
new AnnotationToAttribute(OA\Property::class),
new AnnotationToAttribute(OA\Put::class),
new AnnotationToAttribute(OA\RequestBody::class),
new AnnotationToAttribute(OA\Response::class),
new AnnotationToAttribute(OA\Schema::class),
new AnnotationToAttribute(OA\SecurityScheme::class),
new AnnotationToAttribute(OA\Server::class),
new AnnotationToAttribute(OA\ServerVariable::class),
new AnnotationToAttribute(OA\Tag::class),
new AnnotationToAttribute(OA\Trace::class),
new AnnotationToAttribute(OA\Xml::class),
new AnnotationToAttribute(OA\XmlContent::class)
]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment