Created
December 28, 2021 21:09
-
-
Save BusterNeece/230f1bf619740b0564b88a69978de82c to your computer and use it in GitHub Desktop.
Rector script to migrate OpenAPI specifications from PHP Annotations to Attributes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Rector\Php80\Rector\Class_\AnnotationToAttributeRector; | |
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | |
return static function (ContainerConfigurator $containerConfigurator): void { | |
$services = $containerConfigurator->services(); | |
$openApiAnnotationsRaw = [ | |
'AdditionalProperties', | |
'Attachable', | |
'Components', | |
'Contact', | |
'Delete', | |
'Discriminator', | |
'Examples', | |
'ExternalDocumentation', | |
'Flow', | |
'Get', | |
'Head', | |
'Header', | |
'Info', | |
'Items', | |
'JsonContent', | |
'License', | |
'Link', | |
'MediaType', | |
'OpenApi', | |
'Operation', | |
'Options', | |
'Parameter', | |
'Patch', | |
'PatchItem', | |
'PathParameter', | |
'Post', | |
'Property', | |
'Put', | |
'RequestBody', | |
'Response', | |
'Schema', | |
'SecurityScheme', | |
'Server', | |
'ServerVariable', | |
'Tag', | |
'Trace', | |
'Xml', | |
'XmlContent', | |
]; | |
$openApiAnnotations = []; | |
foreach ($openApiAnnotationsRaw as $className) { | |
$openApiAnnotations[] = new \Rector\Php80\ValueObject\AnnotationToAttribute( | |
'OpenApi\\Annotations\\' . $className, | |
'OpenApi\\Attributes\\' . $className | |
); | |
} | |
$services->set(AnnotationToAttributeRector::class) | |
->configure($openApiAnnotations); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment