-
-
Save YaroslavB/5ce0fc88af6d57436fc0656cee8b2dad to your computer and use it in GitHub Desktop.
Rector script to migrate OpenAPI specifications from PHP Annotations to Attributes
This file contains hidden or 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