diff --git a/README.md b/README.md index 9aec877..969fe60 100644 --- a/README.md +++ b/README.md @@ -208,6 +208,11 @@ The following events are available: This event allows you to modify the definitions of the generated Parameters DTO's customizing the generated code. The parametersType() method returns either "path" or "query" and indicates what part of the RequestDTO is the ParameterDTO generated for. +- `OnMoon\OpenApiServerBundle\Event\CodeGenerator\PropertyDtoGenerationEvent` + + The PropertyDtoGenerationEvent event occurs before any of the DTOs nested in the Request Body or Response are generated. + This event allows you to modify the definitions of the generated nested DTOs that are used in the Request Body + and Response DTOs, customizing the generated code. - `OnMoon\OpenApiServerBundle\Event\CodeGenerator\RequestBodyDtoGenerationEvent` The RequestBodyDtoGenerationEvent event occurs before the request body dto is generated. diff --git a/src/CodeGenerator/Dto/PhpParserDtoFactory.php b/src/CodeGenerator/Dto/PhpParserDtoFactory.php index 0d51600..d80c07b 100644 --- a/src/CodeGenerator/Dto/PhpParserDtoFactory.php +++ b/src/CodeGenerator/Dto/PhpParserDtoFactory.php @@ -23,6 +23,7 @@ use OnMoon\OpenApiServerBundle\Event\CodeGenerator\ClassPropertyGenerationEvent; use OnMoon\OpenApiServerBundle\Event\CodeGenerator\ConstructorParameterGenerationEvent; use OnMoon\OpenApiServerBundle\Event\CodeGenerator\GetterMethodGenerationEvent; +use OnMoon\OpenApiServerBundle\Event\CodeGenerator\PropertyDtoGenerationEvent; use OnMoon\OpenApiServerBundle\Event\CodeGenerator\SetterMethodGenerationEvent; use OnMoon\OpenApiServerBundle\Interfaces\Dto; use OnMoon\OpenApiServerBundle\Interfaces\ResponseDto; @@ -287,6 +288,7 @@ public function generateDtoClassGraph(SchemaBasedDtoDefinition $definition) : ar $propertyDtoDefinition->makeImmutable() : $propertyDtoDefinition->makeMutable(); + $this->eventDispatcher->dispatch(new PropertyDtoGenerationEvent($propertyDtoDefinition)); $generatedClassGraph = $this->generatePropertyDto($propertyDtoDefinition); $generatedClasses = array_merge($generatedClasses, $generatedClassGraph->getClassGraph()); @@ -318,6 +320,7 @@ public function generateDtoClassGraph(SchemaBasedDtoDefinition $definition) : ar $propertyDtoDefinition->makeImmutable() : $propertyDtoDefinition->makeMutable(); + $this->eventDispatcher->dispatch(new PropertyDtoGenerationEvent($propertyDtoDefinition)); $generatedClassGraph = $this->generatePropertyDto($propertyDtoDefinition); $generatedClasses = array_merge($generatedClasses, $generatedClassGraph->getClassGraph()); diff --git a/src/Event/CodeGenerator/PropertyDtoGenerationEvent.php b/src/Event/CodeGenerator/PropertyDtoGenerationEvent.php new file mode 100644 index 0000000..da7de92 --- /dev/null +++ b/src/Event/CodeGenerator/PropertyDtoGenerationEvent.php @@ -0,0 +1,31 @@ +definition = $definition; + } + + public function definition() : PropertyDtoDefinition + { + return $this->definition; + } +}