From cc7a3fdefeeb68d4e7630f7d8ee27c6d66d7de1e Mon Sep 17 00:00:00 2001 From: Chris Nizzardini Date: Sun, 25 Oct 2020 09:39:28 -0400 Subject: [PATCH] Version 1.6 (#216) * Resolves not locating singular table names and other refactors #171 Uses MixerApi/Core to locate models, entities, etc... * csfix * Updates SwaggerBake.Schema.created to use ModelDecorator * cs fix * Removes EntityDecorator and PropertyDecorator, now uses MixerApi/Core classes. * set mixerapi/core version * Support DTOs for XML and JSON request types #204 - Adds support for XML/JSON DTO via SwagDtoRequestBody annotation - Deprecates SwagDtoForm in favor of SwagDtoRequestBody * Updates composer and fixes CS issues - Removes minimum-stability and prefer-stable - Sets CakePHP version constraint to `~4.0` - Sets MixerApi/Core to `~1.0` --- composer.json | 5 +- src/Command/ModelCommand.php | 17 +- src/Command/RouteCommand.php | 2 +- src/Lib/Annotation/SwagDtoForm.php | 11 + src/Lib/Annotation/SwagDtoRequestBody.php | 42 ++++ src/Lib/AnnotationLoader.php | 1 + src/Lib/Decorator/EntityDecorator.php | 124 ----------- src/Lib/Decorator/PropertyDecorator.php | 110 ---------- src/Lib/EntityScanner.php | 207 ------------------ src/Lib/Factory/SwaggerFactory.php | 10 +- src/Lib/Model/ModelDecorator.php | 46 ++++ src/Lib/Model/ModelScanner.php | 153 +++++++++++++ src/Lib/OpenApi/SchemaProperty.php | 2 - src/Lib/Operation/DtoParser.php | 18 +- .../Operation/OperationFromRouteFactory.php | 10 +- src/Lib/Operation/OperationPath.php | 6 +- src/Lib/Operation/OperationRequestBody.php | 60 +++-- src/Lib/Operation/OperationResponse.php | 6 +- src/Lib/Operation/OperationSecurity.php | 6 +- src/Lib/Path/PathFromRouteFactory.php | 6 +- .../{Decorator => Route}/RouteDecorator.php | 2 +- src/Lib/{ => Route}/RouteScanner.php | 14 +- src/Lib/Schema/SchemaFactory.php | 122 ++++------- src/Lib/Schema/SchemaPropertyFactory.php | 10 +- src/Lib/Schema/SchemaPropertyFormat.php | 8 +- src/Lib/Schema/SchemaPropertyValidation.php | 8 +- src/Lib/Swagger.php | 42 ++-- src/Lib/TableScanner.php | 113 ---------- .../TestCase/Lib/Annotations/SwagDtoTest.php | 8 +- .../Annotations/SwagEntityAttributeTest.php | 6 +- .../Lib/Annotations/SwagEntityTest.php | 10 +- .../TestCase/Lib/Annotations/SwagFormTest.php | 6 +- .../Lib/Annotations/SwagHeaderTest.php | 6 +- .../Lib/Annotations/SwagOperationTest.php | 6 +- .../Lib/Annotations/SwagPaginatorTest.php | 6 +- .../Lib/Annotations/SwagPathParameterTest.php | 6 +- .../TestCase/Lib/Annotations/SwagPathTest.php | 8 +- .../Lib/Annotations/SwagQueryTest.php | 6 +- .../SwagRequestBodyContentTest.php | 10 +- .../Lib/Annotations/SwagRequestBodyTest.php | 8 +- .../Annotations/SwagResponseSchemaTest.php | 6 +- .../Lib/Annotations/SwagSecurityTest.php | 6 +- .../Lib/Decorator/EntityDecoratorTest.php | 29 --- .../Extension/CakeSearch/ExtensionTest.php | 6 +- .../OperationFromRouteFactoryTest.php | 2 +- .../Lib/Operation/OperationPathTest.php | 2 +- .../Operation/OperationRequestBodyTest.php | 10 +- .../Lib/Operation/OperationResponseTest.php | 2 +- .../Lib/Operation/OperationSecurityTest.php | 7 +- .../Lib/Path/PathFromRouteFactoryTest.php | 2 +- .../TestCase/Lib/Schema/SchemaFactoryTest.php | 32 ++- .../Lib/Schema/SchemaPropertyFormatTest.php | 4 +- .../Schema/SchemaPropertyValidationTest.php | 25 +-- tests/TestCase/Lib/SwaggerOperationTest.php | 12 +- tests/TestCase/Lib/SwaggerSchemaTest.php | 8 +- tests/TestCase/Lib/SwaggerTest.php | 8 +- tests/test_app/src/Dto/EmployeeData.php | 6 +- 57 files changed, 534 insertions(+), 880 deletions(-) create mode 100644 src/Lib/Annotation/SwagDtoRequestBody.php delete mode 100644 src/Lib/Decorator/EntityDecorator.php delete mode 100644 src/Lib/Decorator/PropertyDecorator.php delete mode 100644 src/Lib/EntityScanner.php create mode 100644 src/Lib/Model/ModelDecorator.php create mode 100644 src/Lib/Model/ModelScanner.php rename src/Lib/{Decorator => Route}/RouteDecorator.php (99%) rename src/Lib/{ => Route}/RouteScanner.php (88%) delete mode 100644 src/Lib/TableScanner.php delete mode 100644 tests/TestCase/Lib/Decorator/EntityDecoratorTest.php diff --git a/composer.json b/composer.json index 9659a4ae..b975f5bf 100644 --- a/composer.json +++ b/composer.json @@ -7,11 +7,12 @@ "require": { "php": ">=7.2", "ext-json": "*", - "cakephp/cakephp": ">=4.0 <4.2", + "cakephp/cakephp": "~4.0", "symfony/yaml": "^5.0", "phpdocumentor/reflection-docblock": "^5.1", "doctrine/annotations": "^1.10", - "thecodingmachine/class-explorer": "^1.1" + "thecodingmachine/class-explorer": "^1.1", + "mixerapi/core": "~1.0" }, "suggest": { "friendsofcake/search": "Easy model searching with @SwagSearch", diff --git a/src/Command/ModelCommand.php b/src/Command/ModelCommand.php index 6778b781..f224b6b5 100644 --- a/src/Command/ModelCommand.php +++ b/src/Command/ModelCommand.php @@ -8,9 +8,10 @@ use Cake\Console\ConsoleIo; use Cake\Console\ConsoleOptionParser; use Cake\Routing\Router; +use ReflectionClass; use SwaggerBake\Lib\Configuration; -use SwaggerBake\Lib\EntityScanner; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Model\ModelScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Utility\DataTypeConversion; use SwaggerBake\Lib\Utility\ValidateConfiguration; @@ -61,10 +62,10 @@ public function execute(Arguments $args, ConsoleIo $io) } $routeScanner = new RouteScanner(new Router(), $config); - $entityScanner = new EntityScanner($routeScanner, $config); - $entities = $entityScanner->getEntityDecorators(); + $modelScanner = new ModelScanner($routeScanner, $config); + $models = $modelScanner->getModelDecorators(); - if (empty($entities)) { + if (empty($models)) { $io->out(); $io->warning('No models were found that are associated with: ' . $config->getPrefix()); $io->out('Have you added RESTful routes? Do you have models associated with those routes?'); @@ -74,10 +75,10 @@ public function execute(Arguments $args, ConsoleIo $io) $header = ['Attribute','Data Type', 'Swagger Type','Default','Primary Key']; - foreach ($entities as $entity) { - $io->out('- ' . $entity->getName()); + foreach ($models as $model) { + $io->out('- ' . (new ReflectionClass($model->getModel()->getEntity()))->getShortName()); $output = [$header]; - foreach ($entity->getProperties() as $property) { + foreach ($model->getModel()->getProperties() as $property) { $output[] = [ $property->getName(), $property->getType(), diff --git a/src/Command/RouteCommand.php b/src/Command/RouteCommand.php index 2afa2b4a..5de0b42c 100644 --- a/src/Command/RouteCommand.php +++ b/src/Command/RouteCommand.php @@ -9,7 +9,7 @@ use Cake\Console\ConsoleOptionParser; use Cake\Routing\Router; use SwaggerBake\Lib\Configuration; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Utility\ValidateConfiguration; /** diff --git a/src/Lib/Annotation/SwagDtoForm.php b/src/Lib/Annotation/SwagDtoForm.php index 4d7ae04c..0d12207c 100644 --- a/src/Lib/Annotation/SwagDtoForm.php +++ b/src/Lib/Annotation/SwagDtoForm.php @@ -38,7 +38,18 @@ * @see https://swagger.io/specification/ search for "Schema Object" * @see https://swagger.io/docs/specification/data-models/data-types/?sbsearch=Data%20Format search for "data format" * @see AbstractSchemaProperty + * @deprecated */ class SwagDtoForm extends AbstractSchemaProperty { + /** + * @param array $values Annotation values + */ + public function __construct(array $values) + { + parent::__construct($values); + deprecationWarning( + 'This class annotation will be deprecated in a future version, please use SwagDtoRequestBody' + ); + } } diff --git a/src/Lib/Annotation/SwagDtoRequestBody.php b/src/Lib/Annotation/SwagDtoRequestBody.php new file mode 100644 index 00000000..ff74949e --- /dev/null +++ b/src/Lib/Annotation/SwagDtoRequestBody.php @@ -0,0 +1,42 @@ +entity = $entity; - $this->fqns = get_class($entity); - $this->name = (new ReflectionClass($entity))->getShortName(); - } - - /** - * @return string - */ - public function getName(): string - { - return $this->name; - } - - /** - * @param string $name Name of the entity - * @return $this - */ - public function setName(string $name) - { - $this->name = $name; - - return $this; - } - - /** - * @return \SwaggerBake\Lib\Decorator\PropertyDecorator[] - */ - public function getProperties(): array - { - return $this->properties; - } - - /** - * @param \SwaggerBake\Lib\Decorator\PropertyDecorator[] $properties Array of PropertyDecorator objects - * @return $this - */ - public function setProperties(array $properties) - { - $this->properties = $properties; - - return $this; - } - - /** - * @return \Cake\ORM\Entity - */ - public function getEntity(): Entity - { - return $this->entity; - } - - /** - * @param \Cake\ORM\Entity $entity Entity - * @return $this - */ - public function setEntity(Entity $entity) - { - $this->entity = $entity; - - return $this; - } - - /** - * @return string - */ - public function getFqns(): string - { - return $this->fqns; - } - - /** - * @param string $fqns Fully Qualified Namespace of the Entity - * @return $this - */ - public function setFqns(string $fqns) - { - $this->fqns = $fqns; - - return $this; - } -} diff --git a/src/Lib/Decorator/PropertyDecorator.php b/src/Lib/Decorator/PropertyDecorator.php deleted file mode 100644 index 175c34e7..00000000 --- a/src/Lib/Decorator/PropertyDecorator.php +++ /dev/null @@ -1,110 +0,0 @@ -name; - } - - /** - * @param string $name Property name - * @return $this - */ - public function setName(string $name) - { - $this->name = $name; - - return $this; - } - - /** - * @return string - */ - public function getType(): string - { - return $this->type; - } - - /** - * @param string $type Property data type (string, integer, etc.) - * @return $this - */ - public function setType(string $type) - { - $this->type = $type; - - return $this; - } - - /** - * @return string - */ - public function getDefault(): string - { - return $this->default; - } - - /** - * @param string|int $default Default value for the property - * @return $this - */ - public function setDefault($default) - { - $this->default = $default; - - return $this; - } - - /** - * @return bool - */ - public function isPrimaryKey(): bool - { - return $this->isPrimaryKey; - } - - /** - * @param bool $isPrimaryKey Is this property a primary key? - * @return $this - */ - public function setIsPrimaryKey(bool $isPrimaryKey) - { - $this->isPrimaryKey = $isPrimaryKey; - - return $this; - } -} diff --git a/src/Lib/EntityScanner.php b/src/Lib/EntityScanner.php deleted file mode 100644 index af2f987d..00000000 --- a/src/Lib/EntityScanner.php +++ /dev/null @@ -1,207 +0,0 @@ -routeScanner = $routeScanner; - $this->prefix = $config->getPrefix(); - $this->config = $config; - } - - /** - * Gets an array of EntityDecorator - * - * @return \SwaggerBake\Lib\Decorator\EntityDecorator[] - */ - public function getEntityDecorators(): array - { - $return = []; - - $connection = ConnectionManager::get('default'); - - if (!$connection instanceof Connection) { - throw new SwaggerBakeRunTimeException('Unable to get Database Connection instance'); - } - - $scanner = new TableScanner($connection); - $tables = $scanner->listUnskipped(); - $collection = $connection->getSchemaCollection(); - $routes = $this->routeScanner->getRoutes(); - $tabularRoutes = $this->getTablesFromRoutes($routes); - - foreach ($tables as $tableName) { - $classShortName = Inflector::classify($tableName); - $entityFqns = NamespaceUtility::getEntityFullyQualifiedNameSpace($classShortName, $this->config); - - if (empty($entityFqns)) { - continue; - } - - if (!in_array($tableName, $tabularRoutes) && !$this->entityHasVisibility($entityFqns)) { - continue; - } - - $entityInstance = new $entityFqns(); - $schema = $collection->describe($tableName); - - if (!$schema instanceof TableSchema) { - throw new SwaggerBakeRunTimeException('Unable to get TableSchema instance'); - } - - $properties = $this->getPropertyDecorators($entityInstance, $schema); - - $return[] = (new EntityDecorator($entityInstance))->setProperties($properties); - } - - return $return; - } - - /** - * @return \SwaggerBake\Lib\RouteScanner - */ - public function getRouteScanner(): RouteScanner - { - return $this->routeScanner; - } - - /** - * @return string - */ - public function getPrefix(): string - { - return $this->prefix; - } - - /** - * @return \SwaggerBake\Lib\Configuration - */ - public function getConfig(): Configuration - { - return $this->config; - } - - /** - * @param \SwaggerBake\Lib\Decorator\RouteDecorator[] $routes An array of RouteDecorator objects - * @return string[] - */ - private function getTablesFromRoutes(array $routes): array - { - $return = []; - foreach ($routes as $route) { - if (empty($route->getController())) { - continue; - } - $return[] = Inflector::underscore($route->getController()); - } - - return array_unique($return); - } - - /** - * @param \Cake\Datasource\EntityInterface $entity EntityInterface - * @param \Cake\Database\Schema\TableSchema $schema TableSchema - * @return \SwaggerBake\Lib\Decorator\PropertyDecorator[] - */ - private function getPropertyDecorators(EntityInterface $entity, TableSchema $schema): array - { - $return = []; - - $hiddenAttributes = $entity->getHidden(); - - $columns = array_filter($schema->columns(), function ($column) use ($hiddenAttributes) { - return !in_array($column, $hiddenAttributes) ? true : null; - }); - - foreach ($columns as $columnName) { - $vars = $schema->__debugInfo(); - $default = $vars['columns'][$columnName]['default'] ?? ''; - - $PropertyDecorator = new PropertyDecorator(); - $PropertyDecorator - ->setName($columnName) - ->setType($schema->getColumnType($columnName)) - ->setDefault($default) - ->setIsPrimaryKey($this->isPrimaryKey($vars, $columnName)); - $return[] = $PropertyDecorator; - } - - return $return; - } - - /** - * @param array $schemaDebugInfo Debug array from TableSchema - * @param string $columnName Column name - * @return bool - */ - private function isPrimaryKey(array $schemaDebugInfo, string $columnName): bool - { - if (!isset($schemaDebugInfo['constraints']['primary']['columns'])) { - return false; - } - - return in_array($columnName, $schemaDebugInfo['constraints']['primary']['columns']); - } - - /** - * @param string $fqns Fully Qualified Namespace of the entity - * @return bool - */ - private function entityHasVisibility(string $fqns): bool - { - if (empty($fqns)) { - return false; - } - - $annotations = AnnotationUtility::getClassAnnotationsFromFqns($fqns); - - $swagEntities = array_filter($annotations, function ($annotation) { - return $annotation instanceof SwagEntity; - }); - - if (empty($swagEntities)) { - return false; - } - - $swagEntity = reset($swagEntities); - - return $swagEntity->isVisible; - } -} diff --git a/src/Lib/Factory/SwaggerFactory.php b/src/Lib/Factory/SwaggerFactory.php index 177d1cd9..382ca230 100644 --- a/src/Lib/Factory/SwaggerFactory.php +++ b/src/Lib/Factory/SwaggerFactory.php @@ -5,9 +5,9 @@ use Cake\Routing\Router; use SwaggerBake\Lib\Configuration; -use SwaggerBake\Lib\EntityScanner; use SwaggerBake\Lib\Exception\SwaggerBakeRunTimeException; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Model\ModelScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Swagger; use SwaggerBake\Lib\Utility\ValidateConfiguration; @@ -26,13 +26,13 @@ class SwaggerFactory private $config; /** - * @var \SwaggerBake\Lib\RouteScanner + * @var \SwaggerBake\Lib\Route\RouteScanner */ private $routeScanner; /** * @param \SwaggerBake\Lib\Configuration|null $config Configuration - * @param \SwaggerBake\Lib\RouteScanner|null $routeScanner RouteScanner + * @param \SwaggerBake\Lib\Route\RouteScanner|null $routeScanner RouteScanner */ public function __construct(?Configuration $config = null, ?RouteScanner $routeScanner = null) { @@ -58,6 +58,6 @@ public function create(): Swagger ); } - return new Swagger(new EntityScanner($this->routeScanner, $this->config)); + return new Swagger(new ModelScanner($this->routeScanner, $this->config)); } } diff --git a/src/Lib/Model/ModelDecorator.php b/src/Lib/Model/ModelDecorator.php new file mode 100644 index 00000000..0a2fcb15 --- /dev/null +++ b/src/Lib/Model/ModelDecorator.php @@ -0,0 +1,46 @@ +model = $model; + $this->controller = $controller; + } + + /** + * @return \MixerApi\Core\Model\Model + */ + public function getModel(): Model + { + return $this->model; + } + + /** + * @return \Cake\Controller\Controller|null + */ + public function getController(): ?Controller + { + return $this->controller; + } +} diff --git a/src/Lib/Model/ModelScanner.php b/src/Lib/Model/ModelScanner.php new file mode 100644 index 00000000..166bd2d4 --- /dev/null +++ b/src/Lib/Model/ModelScanner.php @@ -0,0 +1,153 @@ +routeScanner = $routeScanner; + $this->prefix = $config->getPrefix(); + $this->config = $config; + } + + /** + * Gets an array of ModelDecorator instances + * + * @return \SwaggerBake\Lib\Model\ModelDecorator[] + */ + public function getModelDecorators(): array + { + $return = []; + + $connection = ConnectionManager::get('default'); + + if (!$connection instanceof Connection) { + throw new SwaggerBakeRunTimeException('Unable to get Database Connection instance'); + } + + $tables = NamespaceUtility::findClasses(Configure::read('App.namespace') . '\Model\Table'); + + foreach ($tables as $table) { + try { + $model = (new ModelFactory($connection, new $table()))->create(); + } catch (\Exception $e) { + continue; + } + + if ($model === null) { + continue; + } + + $routeDecorator = $this->getRouteDecorator($model); + if (!$this->hasVisibility($model, $routeDecorator)) { + continue; + } + + $controllerFqn = $routeDecorator->getControllerFqn(); + $controller = $controllerFqn ? new $controllerFqn() : null; + + $return[] = new ModelDecorator($model, $controller); + } + + return $return; + } + + /** + * @return \SwaggerBake\Lib\Route\RouteScanner + */ + public function getRouteScanner(): RouteScanner + { + return $this->routeScanner; + } + + /** + * @return string + */ + public function getPrefix(): string + { + return $this->prefix; + } + + /** + * @return \SwaggerBake\Lib\Configuration + */ + public function getConfig(): Configuration + { + return $this->config; + } + + /** + * @param \MixerApi\Core\Model\Model $model Model instance + * @return \SwaggerBake\Lib\Route\RouteDecorator + */ + private function getRouteDecorator(Model $model): ?RouteDecorator + { + $routes = $this->routeScanner->getRoutes(); + + $result = (new Collection($routes))->filter(function (RouteDecorator $route) use ($model) { + return $route->getController() == $model->getTable()->getAlias(); + }); + + return $result->first(); + } + + /** + * @param \MixerApi\Core\Model\Model $model Model instance + * @param \SwaggerBake\Lib\Route\RouteDecorator|null $routeDecorator RouteDecorator instance + * @return bool + */ + private function hasVisibility(Model $model, ?RouteDecorator $routeDecorator): bool + { + $annotations = AnnotationUtility::getClassAnnotationsFromFqns(get_class($model->getEntity())); + + $swagEntities = array_filter($annotations, function ($annotation) { + return $annotation instanceof SwagEntity; + }); + + if (empty($swagEntities)) { + return $routeDecorator !== null; + } + + $swagEntity = reset($swagEntities); + + return $swagEntity->isVisible; + } +} diff --git a/src/Lib/OpenApi/SchemaProperty.php b/src/Lib/OpenApi/SchemaProperty.php index 4a9d1640..0c6988aa 100644 --- a/src/Lib/OpenApi/SchemaProperty.php +++ b/src/Lib/OpenApi/SchemaProperty.php @@ -371,6 +371,4 @@ public function setItems(array $items) return $this; } - - } diff --git a/src/Lib/Operation/DtoParser.php b/src/Lib/Operation/DtoParser.php index 3786aeda..b8bee72e 100644 --- a/src/Lib/Operation/DtoParser.php +++ b/src/Lib/Operation/DtoParser.php @@ -10,6 +10,7 @@ use ReflectionProperty; use SwaggerBake\Lib\Annotation\SwagDtoForm; use SwaggerBake\Lib\Annotation\SwagDtoQuery; +use SwaggerBake\Lib\Annotation\SwagDtoRequestBody; use SwaggerBake\Lib\Factory\ParameterFromAnnotationFactory; use SwaggerBake\Lib\OpenApi\Parameter; use SwaggerBake\Lib\OpenApi\Schema; @@ -96,9 +97,9 @@ public function getSchemaProperties(): array $factory = new SchemaPropertyFromAnnotationFactory(); foreach ($properties as $name => $reflectionProperty) { - $swagDtoForm = $this->getSwagDtoProperty($reflectionProperty); - if ($swagDtoForm instanceof SwagDtoForm) { - $schemaProperties[] = $factory->create($swagDtoForm); + $dto = $this->getSwagDtoProperty($reflectionProperty); + if ($dto instanceof SwagDtoForm || $dto instanceof SwagDtoRequestBody) { + $schemaProperties[] = $factory->create($dto); continue; } @@ -120,7 +121,7 @@ public function getSchemaProperties(): array * Gets an instance of SwagDtoProperty, null otherwise * * @param \ReflectionProperty $reflectionProperty ReflectionProperty - * @return \SwaggerBake\Lib\Annotation\SwagDtoQuery|\SwaggerBake\Lib\Annotation\SwagDtoForm|null + * @return mixed */ private function getSwagDtoProperty(ReflectionProperty $reflectionProperty) { @@ -132,6 +133,7 @@ private function getSwagDtoProperty(ReflectionProperty $reflectionProperty) if ($annotation instanceof SwagDtoQuery && !empty($annotation->name)) { return $annotation; } + $annotation = $this->annotationReader->getPropertyAnnotation( $reflectionProperty, SwagDtoForm::class @@ -139,6 +141,14 @@ private function getSwagDtoProperty(ReflectionProperty $reflectionProperty) if ($annotation instanceof SwagDtoForm && !empty($annotation->name)) { return $annotation; } + + $annotation = $this->annotationReader->getPropertyAnnotation( + $reflectionProperty, + SwagDtoRequestBody::class + ); + if ($annotation instanceof SwagDtoRequestBody && !empty($annotation->name)) { + return $annotation; + } } catch (\Exception $e) { return null; } diff --git a/src/Lib/Operation/OperationFromRouteFactory.php b/src/Lib/Operation/OperationFromRouteFactory.php index eb1ac6b3..65f3c80f 100644 --- a/src/Lib/Operation/OperationFromRouteFactory.php +++ b/src/Lib/Operation/OperationFromRouteFactory.php @@ -10,9 +10,9 @@ use phpDocumentor\Reflection\DocBlock; use phpDocumentor\Reflection\DocBlockFactory; use SwaggerBake\Lib\Annotation\SwagOperation; -use SwaggerBake\Lib\Decorator\RouteDecorator; use SwaggerBake\Lib\OpenApi\Operation; use SwaggerBake\Lib\OpenApi\Schema; +use SwaggerBake\Lib\Route\RouteDecorator; use SwaggerBake\Lib\Swagger; use SwaggerBake\Lib\Utility\AnnotationUtility; use SwaggerBake\Lib\Utility\DocBlockUtility; @@ -40,7 +40,7 @@ public function __construct(Swagger $swagger) /** * Creates an instance of Operation * - * @param \SwaggerBake\Lib\Decorator\RouteDecorator $route RouteDecorator + * @param \SwaggerBake\Lib\Route\RouteDecorator $route RouteDecorator * @param string $httpMethod Http method such i.e. PUT, POST, PATCH, GET, and DELETE * @param null|\SwaggerBake\Lib\OpenApi\Schema $schema Schema * @return \SwaggerBake\Lib\OpenApi\Operation|null @@ -107,7 +107,7 @@ public function create(RouteDecorator $route, string $httpMethod, ?Schema $schem /** * Gets an instance of DocBlock from the controllers method * - * @param \SwaggerBake\Lib\Decorator\RouteDecorator $route RouteDecorator + * @param \SwaggerBake\Lib\Route\RouteDecorator $route RouteDecorator * @return \phpDocumentor\Reflection\DocBlock */ private function getDocBlock(RouteDecorator $route): DocBlock @@ -152,7 +152,7 @@ private function isVisible(array $annotations): bool * Is the route, http method, and annotation combination allowed? This primarily prevents HTTP PUT methods on * controller `edit()` actions from appearing in OpenAPI schema by default. * - * @param \SwaggerBake\Lib\Decorator\RouteDecorator $route instance of RouteDecorator + * @param \SwaggerBake\Lib\Route\RouteDecorator $route instance of RouteDecorator * @param string $httpMethod http method (PUT, POST, PATCH etc..) * @param array $annotations an array of annotation objects * @return bool @@ -180,7 +180,7 @@ private function isAllowed(RouteDecorator $route, string $httpMethod, array $ann * Applies Operation::tags to the Operation * * @param \SwaggerBake\Lib\OpenApi\Operation $operation Operation - * @param \SwaggerBake\Lib\Decorator\RouteDecorator $route RouteDecorator + * @param \SwaggerBake\Lib\Route\RouteDecorator $route RouteDecorator * @param array $annotations An array of annotation objects * @return \SwaggerBake\Lib\OpenApi\Operation ] */ diff --git a/src/Lib/Operation/OperationPath.php b/src/Lib/Operation/OperationPath.php index 4ecff197..63175e0d 100644 --- a/src/Lib/Operation/OperationPath.php +++ b/src/Lib/Operation/OperationPath.php @@ -4,10 +4,10 @@ namespace SwaggerBake\Lib\Operation; use SwaggerBake\Lib\Annotation\SwagPathParameter; -use SwaggerBake\Lib\Decorator\RouteDecorator; use SwaggerBake\Lib\OpenApi\Operation; use SwaggerBake\Lib\OpenApi\Parameter; use SwaggerBake\Lib\OpenApi\Schema; +use SwaggerBake\Lib\Route\RouteDecorator; /** * Class OperationPath @@ -22,7 +22,7 @@ class OperationPath private $operation; /** - * @var \SwaggerBake\Lib\Decorator\RouteDecorator + * @var \SwaggerBake\Lib\Route\RouteDecorator */ private $route; @@ -38,7 +38,7 @@ class OperationPath /** * @param \SwaggerBake\Lib\OpenApi\Operation $operation instance of Operation - * @param \SwaggerBake\Lib\Decorator\RouteDecorator $route instance of RouteDecorator + * @param \SwaggerBake\Lib\Route\RouteDecorator $route instance of RouteDecorator * @param array $annotations array of annotation objects or empty array * @param \SwaggerBake\Lib\OpenApi\Schema|null $schema instance of Schema or null */ diff --git a/src/Lib/Operation/OperationRequestBody.php b/src/Lib/Operation/OperationRequestBody.php index 99f27a7f..0f6a7c60 100644 --- a/src/Lib/Operation/OperationRequestBody.php +++ b/src/Lib/Operation/OperationRequestBody.php @@ -7,13 +7,13 @@ use SwaggerBake\Lib\Annotation\SwagForm; use SwaggerBake\Lib\Annotation\SwagRequestBody; use SwaggerBake\Lib\Annotation\SwagRequestBodyContent; -use SwaggerBake\Lib\Decorator\RouteDecorator; use SwaggerBake\Lib\OpenApi\Content; use SwaggerBake\Lib\OpenApi\Operation; use SwaggerBake\Lib\OpenApi\RequestBody; use SwaggerBake\Lib\OpenApi\Schema; use SwaggerBake\Lib\OpenApi\SchemaProperty; use SwaggerBake\Lib\OpenApi\Xml; +use SwaggerBake\Lib\Route\RouteDecorator; use SwaggerBake\Lib\Swagger; /** @@ -34,7 +34,7 @@ class OperationRequestBody private $operation; /** - * @var \SwaggerBake\Lib\Decorator\RouteDecorator + * @var \SwaggerBake\Lib\Route\RouteDecorator */ private $route; @@ -57,7 +57,7 @@ class OperationRequestBody * @param \SwaggerBake\Lib\Swagger $swagger Swagger * @param \SwaggerBake\Lib\OpenApi\Operation $operation Operation * @param array $annotations Array of annotation objects - * @param \SwaggerBake\Lib\Decorator\RouteDecorator $route RouteDecorator + * @param \SwaggerBake\Lib\Route\RouteDecorator $route RouteDecorator * @param \SwaggerBake\Lib\OpenApi\Schema|null $schema Schema */ public function __construct( @@ -199,11 +199,13 @@ private function assignSwagFormAnnotations(): void $requestBody = $this->operation->getRequestBody() ?? new RequestBody(); - $requestBody->pushContent( - (new Content()) - ->setMimeType('application/x-www-form-urlencoded') - ->setSchema($schema) - ); + foreach ($this->config->getRequestAccepts() as $mimeType) { + $requestBody->pushContent( + (new Content()) + ->setMimeType($mimeType) + ->setSchema($schema) + ); + } $this->operation->setRequestBody($requestBody); } @@ -225,27 +227,29 @@ private function assignSwagDto(): void } $dto = reset($swagDtos); - $fqns = $dto->class; + $fqn = $dto->class; - if (!class_exists($fqns)) { + if (!class_exists($fqn)) { return; } $requestBody = new RequestBody(); $schema = (new Schema())->setType('object'); - $properties = (new DtoParser($fqns))->getSchemaProperties(); + $properties = (new DtoParser($fqn))->getSchemaProperties(); foreach ($properties as $property) { $schema->pushProperty($property); } - $this->operation->setRequestBody( + foreach ($this->config->getRequestAccepts() as $mimeType) { $requestBody->pushContent( (new Content()) - ->setMimeType('application/x-www-form-urlencoded') - ->setSchema($schema) - ) - ); + ->setMimeType($mimeType) + ->setSchema($this->applyRootNodeToXmlSchema($schema, $mimeType)) + ); + } + + $this->operation->setRequestBody($requestBody); } /** @@ -272,12 +276,7 @@ private function assignSchema(): void } $schema = clone $this->schema; - - if ($mimeType == 'application/xml') { - $schema->setXml( - (new Xml())->setName(strtolower($schema->getName())) - ); - } + $schema = $this->applyRootNodeToXmlSchema($schema, $mimeType, $schema->getName()); $content = (new Content())->setMimeType($mimeType); @@ -334,4 +333,21 @@ private function isCrudAction(): bool { return in_array($this->route->getAction(), ['add','edit','view','delete','index']); } + + /** + * Applies a root node to XML schemas (required for XML example in Swagger) + * + * @param \SwaggerBake\Lib\OpenApi\Schema $schema Schema instance + * @param string $mimeType A mimetype such as application/xml + * @param string|null $name Name for the XML root node + * @return \SwaggerBake\Lib\OpenApi\Schema + */ + private function applyRootNodeToXmlSchema(Schema $schema, string $mimeType, ?string $name = 'request') + { + if ($mimeType !== 'application/xml') { + return $schema; + } + + return $schema->setXml((new Xml())->setName($name)); + } } diff --git a/src/Lib/Operation/OperationResponse.php b/src/Lib/Operation/OperationResponse.php index 599fd243..2b2a172e 100644 --- a/src/Lib/Operation/OperationResponse.php +++ b/src/Lib/Operation/OperationResponse.php @@ -6,7 +6,6 @@ use phpDocumentor\Reflection\DocBlock; use SwaggerBake\Lib\Annotation\SwagResponseSchema; use SwaggerBake\Lib\Configuration; -use SwaggerBake\Lib\Decorator\RouteDecorator; use SwaggerBake\Lib\MediaType\Generic; use SwaggerBake\Lib\MediaType\HalJson; use SwaggerBake\Lib\MediaType\JsonLd; @@ -16,6 +15,7 @@ use SwaggerBake\Lib\OpenApi\Response; use SwaggerBake\Lib\OpenApi\Schema; use SwaggerBake\Lib\OpenApi\Xml; +use SwaggerBake\Lib\Route\RouteDecorator; /** * Class OperationResponse @@ -40,7 +40,7 @@ class OperationResponse private $doc; /** - * @var \SwaggerBake\Lib\Decorator\RouteDecorator + * @var \SwaggerBake\Lib\Route\RouteDecorator */ private $route; @@ -59,7 +59,7 @@ class OperationResponse * @param \SwaggerBake\Lib\OpenApi\Operation $operation Operation * @param \phpDocumentor\Reflection\DocBlock $doc DocBlock * @param array $annotations An array of annotation objects - * @param \SwaggerBake\Lib\Decorator\RouteDecorator $route RouteDecorator + * @param \SwaggerBake\Lib\Route\RouteDecorator $route RouteDecorator * @param \SwaggerBake\Lib\OpenApi\Schema|null $schema Schema */ public function __construct( diff --git a/src/Lib/Operation/OperationSecurity.php b/src/Lib/Operation/OperationSecurity.php index 547f31d1..77960b93 100644 --- a/src/Lib/Operation/OperationSecurity.php +++ b/src/Lib/Operation/OperationSecurity.php @@ -5,9 +5,9 @@ use Cake\Controller\Controller; use SwaggerBake\Lib\Annotation\SwagSecurity; -use SwaggerBake\Lib\Decorator\RouteDecorator; use SwaggerBake\Lib\OpenApi\Operation; use SwaggerBake\Lib\OpenApi\PathSecurity; +use SwaggerBake\Lib\Route\RouteDecorator; use SwaggerBake\Lib\Swagger; /** @@ -28,7 +28,7 @@ class OperationSecurity private $annotations; /** - * @var \SwaggerBake\Lib\Decorator\RouteDecorator + * @var \SwaggerBake\Lib\Route\RouteDecorator */ private $route; @@ -45,7 +45,7 @@ class OperationSecurity /** * @param \SwaggerBake\Lib\OpenApi\Operation $operation Operation * @param array $annotations Array of annotation objects - * @param \SwaggerBake\Lib\Decorator\RouteDecorator $route RouteDecorator + * @param \SwaggerBake\Lib\Route\RouteDecorator $route RouteDecorator * @param \Cake\Controller\Controller $controller Controller * @param \SwaggerBake\Lib\Swagger $swagger Swagger */ diff --git a/src/Lib/Path/PathFromRouteFactory.php b/src/Lib/Path/PathFromRouteFactory.php index 6df8de06..124b52f0 100644 --- a/src/Lib/Path/PathFromRouteFactory.php +++ b/src/Lib/Path/PathFromRouteFactory.php @@ -5,8 +5,8 @@ use SwaggerBake\Lib\Annotation\SwagPath; use SwaggerBake\Lib\Configuration; -use SwaggerBake\Lib\Decorator\RouteDecorator; use SwaggerBake\Lib\OpenApi\Path; +use SwaggerBake\Lib\Route\RouteDecorator; use SwaggerBake\Lib\Utility\AnnotationUtility; /** @@ -17,7 +17,7 @@ class PathFromRouteFactory { /** - * @var \SwaggerBake\Lib\Decorator\RouteDecorator + * @var \SwaggerBake\Lib\Route\RouteDecorator */ private $route; @@ -27,7 +27,7 @@ class PathFromRouteFactory private $config; /** - * @param \SwaggerBake\Lib\Decorator\RouteDecorator $route RouteDecorator + * @param \SwaggerBake\Lib\Route\RouteDecorator $route RouteDecorator * @param \SwaggerBake\Lib\Configuration $config Configuration */ public function __construct(RouteDecorator $route, Configuration $config) diff --git a/src/Lib/Decorator/RouteDecorator.php b/src/Lib/Route/RouteDecorator.php similarity index 99% rename from src/Lib/Decorator/RouteDecorator.php rename to src/Lib/Route/RouteDecorator.php index 74f4cfa2..da626224 100644 --- a/src/Lib/Decorator/RouteDecorator.php +++ b/src/Lib/Route/RouteDecorator.php @@ -1,7 +1,7 @@ getController(); - $results = array_filter($classes, function ($fqn) use ($controller) { - return strstr($fqn, '\\' . $controller . 'Controller'); + $results = array_filter($classes, function ($fqn) use ($controller, $route) { + $prefix = !empty($route->defaults['prefix']) ? $route->defaults['prefix'] . '\\' : ''; + + return strstr($fqn, '\\' . $prefix . $controller . 'Controller'); }); if (count($results) == 1) { diff --git a/src/Lib/Schema/SchemaFactory.php b/src/Lib/Schema/SchemaFactory.php index c9854dae..9782a3b1 100644 --- a/src/Lib/Schema/SchemaFactory.php +++ b/src/Lib/Schema/SchemaFactory.php @@ -3,18 +3,17 @@ namespace SwaggerBake\Lib\Schema; +use Cake\Datasource\EntityInterface; use Cake\Event\Event; use Cake\Event\EventManager; -use Cake\Utility\Inflector; use Cake\Validation\Validator; +use MixerApi\Core\Model\Model; use phpDocumentor\Reflection\DocBlock; use phpDocumentor\Reflection\DocBlockFactory; use ReflectionClass; use SwaggerBake\Lib\Annotation\SwagEntity; use SwaggerBake\Lib\Annotation\SwagEntityAttribute; -use SwaggerBake\Lib\Configuration; -use SwaggerBake\Lib\Decorator\EntityDecorator; -use SwaggerBake\Lib\Exception\SwaggerBakeRunTimeException; +use SwaggerBake\Lib\Model\ModelDecorator; use SwaggerBake\Lib\OpenApi\Schema; use SwaggerBake\Lib\OpenApi\SchemaProperty; use SwaggerBake\Lib\Utility\AnnotationUtility; @@ -33,11 +32,6 @@ class SchemaFactory */ private $validator; - /** - * @var \SwaggerBake\Lib\Configuration - */ - private $config; - /** * @var string */ @@ -54,36 +48,30 @@ class SchemaFactory public const ALL_PROPERTIES = 6; /** - * @param \SwaggerBake\Lib\Configuration $config Configuration - */ - public function __construct(Configuration $config) - { - $this->config = $config; - } - - /** - * Creates an instance of Schema for an EntityDecorator, returns null if the Entity is set to invisible + * Creates an instance of Schema for an ModelDecorator, returns null if the Entity is set to invisible * - * @param \SwaggerBake\Lib\Decorator\EntityDecorator $entity EntityDecorator - * @param int $propertyType see public constants for options + * @param \SwaggerBake\Lib\Model\ModelDecorator $modelDecorator ModelDecorator + * @param int $propertyType see public constants for o * @return \SwaggerBake\Lib\OpenApi\Schema|null + * @throws \ReflectionException */ - public function create(EntityDecorator $entity, int $propertyType = 6): ?Schema + public function create(ModelDecorator $modelDecorator, int $propertyType = 6): ?Schema { - $swagEntity = $this->getSwagEntityAnnotation($entity); + $model = $modelDecorator->getModel(); + $swagEntity = $this->getSwagEntityAnnotation($model->getEntity()); if ($swagEntity !== null && $swagEntity->isVisible === false) { return null; } - $this->validator = $this->getValidator($entity->getName()); + $this->validator = $this->getValidator($model); - $docBlock = $this->getDocBlock($entity); + $docBlock = $this->getDocBlock($model->getEntity()); - $properties = $this->getProperties($entity, $propertyType); + $properties = $this->getProperties($model, $propertyType); $schema = (new Schema()) - ->setName($entity->getName()) + ->setName((new ReflectionClass($model->getEntity()))->getShortName()) ->setTitle($swagEntity !== null ? $swagEntity->description : null) ->setType('object') ->setProperties($properties); @@ -104,7 +92,7 @@ public function create(EntityDecorator $entity, int $propertyType = 6): ?Schema EventManager::instance()->dispatch( new Event('SwaggerBake.Schema.created', $schema, [ - 'entity' => $entity, + 'modelDecorator' => $modelDecorator, ]) ); @@ -112,47 +100,43 @@ public function create(EntityDecorator $entity, int $propertyType = 6): ?Schema } /** - * @param \SwaggerBake\Lib\Decorator\EntityDecorator $entity EntityDecorator + * @param \MixerApi\Core\Model\Model $model Model * @param int $propertyType see public constants for options * @return array */ - private function getProperties(EntityDecorator $entity, int $propertyType): array + private function getProperties(Model $model, int $propertyType): array { $return = []; $factory = new SchemaPropertyFactory($this->validator); - foreach ($entity->getProperties() as $attribute) { - $return[$attribute->getName()] = $factory->create($attribute); + foreach ($model->getProperties() as $property) { + $return[$property->getName()] = $factory->create($property); } - $return = array_merge($return, $this->getSwagPropertyAnnotations($entity)); + $return = array_merge($return, $this->getSwagPropertyAnnotations($model)); if ($propertyType === self::ALL_PROPERTIES) { return $return; } - return array_filter( - $return, - function (SchemaProperty $property) use ($propertyType) { - if ($propertyType == self::READABLE_PROPERTIES && !$property->isWriteOnly()) { - return true; - } - if ($propertyType == self::WRITEABLE_PROPERTIES && !$property->isReadOnly()) { - return true; - } + return array_filter($return, function (SchemaProperty $property) use ($propertyType) { + if ($propertyType == self::READABLE_PROPERTIES && !$property->isWriteOnly()) { + return true; } - ); + if ($propertyType == self::WRITEABLE_PROPERTIES && !$property->isReadOnly()) { + return true; + } + }); } /** - * @param \SwaggerBake\Lib\Decorator\EntityDecorator $entity EntityDecorator + * @param \Cake\Datasource\EntityInterface $entity EntityInterface * @return \phpDocumentor\Reflection\DocBlock|null */ - private function getDocBlock(EntityDecorator $entity): ?DocBlock + private function getDocBlock(EntityInterface $entity): ?DocBlock { try { - $instance = $entity->getEntity(); - $reflectionClass = new ReflectionClass(get_class($instance)); + $reflectionClass = new ReflectionClass($entity); } catch (\Exception $e) { return null; } @@ -168,41 +152,17 @@ private function getDocBlock(EntityDecorator $entity): ?DocBlock return $docFactory->create($comments); } - /** - * @param string $className Name of the Table class - * @return string|null - */ - private function getTableFromNamespaces(string $className): ?string - { - $namespaces = $this->config->getNamespaces(); - - if (!isset($namespaces['tables']) || !is_array($namespaces['tables'])) { - throw new SwaggerBakeRunTimeException( - 'Invalid configuration, missing SwaggerBake.namespaces.tables' - ); - } - - foreach ($namespaces['tables'] as $namespace) { - $table = $namespace . 'Model\Table\\' . $className; - if (class_exists($table, true)) { - return $table; - } - } - - return null; - } - /** * Returns key-value pair of property name => SchemaProperty * - * @param \SwaggerBake\Lib\Decorator\EntityDecorator $entity EntityDecorator + * @param \MixerApi\Core\Model\Model $model Model * @return \SwaggerBake\Lib\OpenApi\SchemaProperty[] */ - private function getSwagPropertyAnnotations(EntityDecorator $entity): array + private function getSwagPropertyAnnotations(Model $model): array { $return = []; - $annotations = AnnotationUtility::getClassAnnotationsFromInstance($entity->getEntity()); + $annotations = AnnotationUtility::getClassAnnotationsFromInstance($model->getEntity()); $swagEntityAttributes = array_filter($annotations, function ($annotation) { return $annotation instanceof SwagEntityAttribute; @@ -220,12 +180,12 @@ private function getSwagPropertyAnnotations(EntityDecorator $entity): array /** * Returns instance of SwagEntity annotation, otherwise null * - * @param \SwaggerBake\Lib\Decorator\EntityDecorator $entity EntityDecorator + * @param \Cake\Datasource\EntityInterface $entity EntityInterface * @return \SwaggerBake\Lib\Annotation\SwagEntity|null */ - private function getSwagEntityAnnotation(EntityDecorator $entity): ?SwagEntity + private function getSwagEntityAnnotation(EntityInterface $entity): ?SwagEntity { - $annotations = AnnotationUtility::getClassAnnotationsFromInstance($entity->getEntity()); + $annotations = AnnotationUtility::getClassAnnotationsFromInstance($entity); foreach ($annotations as $annotation) { if ($annotation instanceof SwagEntity) { @@ -239,15 +199,13 @@ private function getSwagEntityAnnotation(EntityDecorator $entity): ?SwagEntity /** * Gets the Table classes Validator * - * @param string $className Name of the Table class - * @return \Cake\Validation\Validator|null + * @param \MixerApi\Core\Model\Model $model Model + * @return \Cake\Validation\Validator */ - private function getValidator(string $className): ?Validator + private function getValidator(Model $model): Validator { try { - $table = $this->getTableFromNamespaces(Inflector::pluralize($className) . 'Table'); - $instance = new $table(); - $validator = $instance->validationDefault(new Validator()); + $validator = $model->getTable()->validationDefault(new Validator()); } catch (\Exception $e) { return new Validator(); } diff --git a/src/Lib/Schema/SchemaPropertyFactory.php b/src/Lib/Schema/SchemaPropertyFactory.php index 5d135417..f9ecba8a 100644 --- a/src/Lib/Schema/SchemaPropertyFactory.php +++ b/src/Lib/Schema/SchemaPropertyFactory.php @@ -4,7 +4,7 @@ namespace SwaggerBake\Lib\Schema; use Cake\Validation\Validator; -use SwaggerBake\Lib\Decorator\PropertyDecorator; +use MixerApi\Core\Model\ModelProperty; use SwaggerBake\Lib\OpenApi\SchemaProperty; use SwaggerBake\Lib\Utility\DataTypeConversion; @@ -33,10 +33,10 @@ public function __construct(Validator $validator) /** * Creates an instance of SchemaProperty * - * @param \SwaggerBake\Lib\Decorator\PropertyDecorator $property PropertyDecorator + * @param \MixerApi\Core\Model\ModelProperty $property ModelProperty * @return \SwaggerBake\Lib\OpenApi\SchemaProperty */ - public function create(PropertyDecorator $property): SchemaProperty + public function create(ModelProperty $property): SchemaProperty { $schemaProperty = new SchemaProperty(); $schemaProperty @@ -55,10 +55,10 @@ public function create(PropertyDecorator $property): SchemaProperty } /** - * @param \SwaggerBake\Lib\Decorator\PropertyDecorator $property PropertyDecorator + * @param \MixerApi\Core\Model\ModelProperty $property ModelProperty * @return bool */ - private function isReadOnly(PropertyDecorator $property): bool + private function isReadOnly(ModelProperty $property): bool { if ($property->isPrimaryKey()) { return true; diff --git a/src/Lib/Schema/SchemaPropertyFormat.php b/src/Lib/Schema/SchemaPropertyFormat.php index 05f7d614..a1ad777b 100644 --- a/src/Lib/Schema/SchemaPropertyFormat.php +++ b/src/Lib/Schema/SchemaPropertyFormat.php @@ -5,7 +5,7 @@ use Cake\Validation\ValidationRule; use Cake\Validation\Validator; -use SwaggerBake\Lib\Decorator\PropertyDecorator; +use MixerApi\Core\Model\ModelProperty; use SwaggerBake\Lib\OpenApi\SchemaProperty; /** @@ -51,16 +51,16 @@ class SchemaPropertyFormat /** * @param \Cake\Validation\Validator $validator Validator * @param \SwaggerBake\Lib\OpenApi\SchemaProperty $schemaProperty SchemaProperty - * @param \SwaggerBake\Lib\Decorator\PropertyDecorator $propertyDecorator PropertyDecorator + * @param \MixerApi\Core\Model\ModelProperty $property Property */ public function __construct( Validator $validator, SchemaProperty $schemaProperty, - PropertyDecorator $propertyDecorator + ModelProperty $property ) { $this->validator = $validator; $this->schemaProperty = $schemaProperty; - $this->propertyName = $propertyDecorator->getName(); + $this->propertyName = $property->getName(); } /** diff --git a/src/Lib/Schema/SchemaPropertyValidation.php b/src/Lib/Schema/SchemaPropertyValidation.php index ba5f132d..ff7bfadb 100644 --- a/src/Lib/Schema/SchemaPropertyValidation.php +++ b/src/Lib/Schema/SchemaPropertyValidation.php @@ -5,8 +5,8 @@ use Cake\Validation\ValidationRule; use Cake\Validation\Validator; +use MixerApi\Core\Model\ModelProperty; use ReflectionFunction; -use SwaggerBake\Lib\Decorator\PropertyDecorator; use SwaggerBake\Lib\OpenApi\SchemaProperty; /** @@ -34,16 +34,16 @@ class SchemaPropertyValidation /** * @param \Cake\Validation\Validator $validator Validator * @param \SwaggerBake\Lib\OpenApi\SchemaProperty $schemaProperty SchemaProperty - * @param \SwaggerBake\Lib\Decorator\PropertyDecorator $propertyDecorator PropertyDecorator + * @param \MixerApi\Core\Model\ModelProperty $property Property */ public function __construct( Validator $validator, SchemaProperty $schemaProperty, - PropertyDecorator $propertyDecorator + ModelProperty $property ) { $this->validator = $validator; $this->schemaProperty = $schemaProperty; - $this->propertyName = $propertyDecorator->getName(); + $this->propertyName = $property->getName(); } /** diff --git a/src/Lib/Swagger.php b/src/Lib/Swagger.php index 28bca447..8ae4ce3c 100644 --- a/src/Lib/Swagger.php +++ b/src/Lib/Swagger.php @@ -6,17 +6,23 @@ use Cake\Event\Event; use Cake\Event\EventManager; use Cake\Utility\Inflector; -use SwaggerBake\Lib\Decorator\RouteDecorator; use SwaggerBake\Lib\Exception\SwaggerBakeRunTimeException; +use SwaggerBake\Lib\Model\ModelScanner; use SwaggerBake\Lib\OpenApi\Operation; use SwaggerBake\Lib\OpenApi\Path; use SwaggerBake\Lib\OpenApi\Schema; use SwaggerBake\Lib\Operation\OperationFromRouteFactory; use SwaggerBake\Lib\Path\PathFromRouteFactory; +use SwaggerBake\Lib\Route\RouteDecorator; use SwaggerBake\Lib\Schema\SchemaFactory; use SwaggerBake\Lib\Schema\SchemaFromYamlFactory; use Symfony\Component\Yaml\Yaml; +/** + * Class Swagger + * + * @package SwaggerBake\Lib + */ class Swagger { /** @@ -27,12 +33,12 @@ class Swagger private $array = []; /** - * @var \SwaggerBake\Lib\EntityScanner + * @var \SwaggerBake\Lib\Model\ModelScanner */ - private $entityScanner; + private $modelScanner; /** - * @var \SwaggerBake\Lib\RouteScanner + * @var \SwaggerBake\Lib\Route\RouteScanner */ private $routeScanner; @@ -42,13 +48,13 @@ class Swagger private $config; /** - * @param \SwaggerBake\Lib\EntityScanner $entityScanner EntityScanner + * @param \SwaggerBake\Lib\Model\ModelScanner $modelScanner ModelScanner instance */ - public function __construct(EntityScanner $entityScanner) + public function __construct(ModelScanner $modelScanner) { - $this->entityScanner = $entityScanner; - $this->routeScanner = $entityScanner->getRouteScanner(); - $this->config = $entityScanner->getConfig(); + $this->modelScanner = $modelScanner; + $this->routeScanner = $modelScanner->getRouteScanner(); + $this->config = $modelScanner->getConfig(); $this->array = Yaml::parseFile($this->config->getYml()); @@ -222,29 +228,31 @@ public function getConfig(): Configuration * Builds schemas from cake models * * @return void + * @throws \ReflectionException */ private function buildSchemasFromModels(): void { - $schemaFactory = new SchemaFactory($this->config); - $entities = $this->entityScanner->getEntityDecorators(); + $schemaFactory = new SchemaFactory(); + $models = $this->modelScanner->getModelDecorators(); - foreach ($entities as $entity) { - if ($this->getSchemaByName($entity->getName())) { + foreach ($models as $model) { + $entityName = (new \ReflectionClass($model->getModel()->getEntity()))->getShortName(); + if ($this->getSchemaByName($entityName)) { continue; } - $schema = $schemaFactory->create($entity); + $schema = $schemaFactory->create($model); if (!$schema) { continue; } $this->pushSchema($schema); - $readSchema = $schemaFactory->create($entity, $schemaFactory::READABLE_PROPERTIES); + $readSchema = $schemaFactory->create($model, $schemaFactory::READABLE_PROPERTIES); $this->pushVendorSchema( $readSchema->setName($readSchema->getReadSchemaName()) ); - $writeSchema = $schemaFactory->create($entity, $schemaFactory::WRITEABLE_PROPERTIES); + $writeSchema = $schemaFactory->create($model, $schemaFactory::WRITEABLE_PROPERTIES); $this->pushVendorSchema( $writeSchema->setName($writeSchema->getWriteSchemaName()) ); @@ -327,7 +335,7 @@ private function buildPathsFromRoutes(): void /** * Gets the Schema associated with a Route * - * @param \SwaggerBake\Lib\Decorator\RouteDecorator $route RouteDecorator + * @param \SwaggerBake\Lib\Route\RouteDecorator $route RouteDecorator * @return \SwaggerBake\Lib\OpenApi\Schema|null */ private function getSchemaFromRoute(RouteDecorator $route): ?Schema diff --git a/src/Lib/TableScanner.php b/src/Lib/TableScanner.php deleted file mode 100644 index 207a29df..00000000 --- a/src/Lib/TableScanner.php +++ /dev/null @@ -1,113 +0,0 @@ -connection = $connection; - if ($ignore === null) { - $ignore = ['i18n', 'cake_sessions', 'sessions', '/phinxlog/']; - } - $this->ignore = $ignore; - } - - /** - * Get all tables in the connection without applying ignores. - * - * @return string[] - */ - public function listAll(): array - { - $schema = $this->connection->getSchemaCollection(); - $tables = $schema->listTables(); - if (empty($tables)) { - throw new RuntimeException('Your database does not have any tables.'); - } - sort($tables); - - return array_combine($tables, $tables); - } - - /** - * Get all tables in the connection that aren't ignored. - * - * @return string[] - */ - public function listUnskipped(): array - { - $tables = $this->listAll(); - - foreach ($tables as $key => $table) { - if ($this->shouldSkip($table)) { - unset($tables[$key]); - } - } - - return $tables; - } - - /** - * @param string $table Table name. - * @return bool - */ - protected function shouldSkip(string $table): bool - { - foreach ($this->ignore as $ignore) { - if (strpos($ignore, '/') === 0) { - if ((bool)preg_match($ignore, $table)) { - return true; - } - } - - if ($ignore === $table) { - return true; - } - } - - return false; - } -} diff --git a/tests/TestCase/Lib/Annotations/SwagDtoTest.php b/tests/TestCase/Lib/Annotations/SwagDtoTest.php index 86a81f4c..7915aa1b 100644 --- a/tests/TestCase/Lib/Annotations/SwagDtoTest.php +++ b/tests/TestCase/Lib/Annotations/SwagDtoTest.php @@ -7,8 +7,8 @@ use Cake\Routing\RouteBuilder; use Cake\TestSuite\TestCase; use SwaggerBake\Lib\AnnotationLoader; -use SwaggerBake\Lib\EntityScanner; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Model\ModelScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Configuration; use SwaggerBake\Lib\Swagger; @@ -67,7 +67,7 @@ public function testSwagDtoQuery() { $cakeRoute = new RouteScanner($this->router, $this->config); - $swagger = new Swagger(new EntityScanner($cakeRoute, $this->config)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $this->config)); $arr = json_decode($swagger->toString(), true); $operation = $arr['paths']['/employees/dto-query']['get']; @@ -83,7 +83,7 @@ public function testSwagDtoPost() { $cakeRoute = new RouteScanner($this->router, $this->config); - $swagger = new Swagger(new EntityScanner($cakeRoute, $this->config)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $this->config)); $arr = json_decode($swagger->toString(), true); $operation = $arr['paths']['/employees/dto-post']['post']; diff --git a/tests/TestCase/Lib/Annotations/SwagEntityAttributeTest.php b/tests/TestCase/Lib/Annotations/SwagEntityAttributeTest.php index d0e6dd05..b1eeccb6 100644 --- a/tests/TestCase/Lib/Annotations/SwagEntityAttributeTest.php +++ b/tests/TestCase/Lib/Annotations/SwagEntityAttributeTest.php @@ -9,8 +9,8 @@ use Cake\Routing\RouteBuilder; use Cake\TestSuite\TestCase; use SwaggerBake\Lib\AnnotationLoader; -use SwaggerBake\Lib\EntityScanner; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Model\ModelScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Configuration; use SwaggerBake\Lib\Swagger; @@ -55,7 +55,7 @@ public function testEntityAttribute() { $cakeRoute = new RouteScanner($this->router, $this->config); - $swagger = new Swagger(new EntityScanner($cakeRoute, $this->config)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $this->config)); $arr = json_decode($swagger->toString(), true); diff --git a/tests/TestCase/Lib/Annotations/SwagEntityTest.php b/tests/TestCase/Lib/Annotations/SwagEntityTest.php index 7489385a..dcd00f7c 100644 --- a/tests/TestCase/Lib/Annotations/SwagEntityTest.php +++ b/tests/TestCase/Lib/Annotations/SwagEntityTest.php @@ -9,8 +9,8 @@ use Cake\Routing\RouteBuilder; use Cake\TestSuite\TestCase; use SwaggerBake\Lib\AnnotationLoader; -use SwaggerBake\Lib\EntityScanner; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Model\ModelScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Configuration; use SwaggerBake\Lib\Swagger; @@ -58,7 +58,7 @@ public function testEntityExists() { $cakeRoute = new RouteScanner($this->router, $this->config); - $swagger = new Swagger(new EntityScanner($cakeRoute, $this->config)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $this->config)); $arr = json_decode($swagger->toString(), true); @@ -69,7 +69,7 @@ public function testEntityInvisible() { $cakeRoute = new RouteScanner($this->router, $this->config); - $swagger = new Swagger(new EntityScanner($cakeRoute, $this->config)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $this->config)); $arr = json_decode($swagger->toString(), true); @@ -80,7 +80,7 @@ public function testEntityAttribute() { $cakeRoute = new RouteScanner($this->router, $this->config); - $swagger = new Swagger(new EntityScanner($cakeRoute, $this->config)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $this->config)); $arr = json_decode($swagger->toString(), true); diff --git a/tests/TestCase/Lib/Annotations/SwagFormTest.php b/tests/TestCase/Lib/Annotations/SwagFormTest.php index 817c23ee..0320a1df 100644 --- a/tests/TestCase/Lib/Annotations/SwagFormTest.php +++ b/tests/TestCase/Lib/Annotations/SwagFormTest.php @@ -7,8 +7,8 @@ use Cake\Routing\RouteBuilder; use Cake\TestSuite\TestCase; use SwaggerBake\Lib\AnnotationLoader; -use SwaggerBake\Lib\EntityScanner; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Model\ModelScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Configuration; use SwaggerBake\Lib\Swagger; @@ -61,7 +61,7 @@ public function testSwagForm() { $cakeRoute = new RouteScanner($this->router, $this->config); - $swagger = new Swagger(new EntityScanner($cakeRoute, $this->config)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $this->config)); $arr = json_decode($swagger->toString(), true); $operation = $arr['paths']['/employees/custom-post']['post']; diff --git a/tests/TestCase/Lib/Annotations/SwagHeaderTest.php b/tests/TestCase/Lib/Annotations/SwagHeaderTest.php index 6a5743dd..f0edceb9 100644 --- a/tests/TestCase/Lib/Annotations/SwagHeaderTest.php +++ b/tests/TestCase/Lib/Annotations/SwagHeaderTest.php @@ -7,8 +7,8 @@ use Cake\Routing\RouteBuilder; use Cake\TestSuite\TestCase; use SwaggerBake\Lib\AnnotationLoader; -use SwaggerBake\Lib\EntityScanner; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Model\ModelScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Configuration; use SwaggerBake\Lib\Swagger; @@ -61,7 +61,7 @@ public function testSwagHeader() { $cakeRoute = new RouteScanner($this->router, $this->config); - $swagger = new Swagger(new EntityScanner($cakeRoute, $this->config)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $this->config)); $arr = json_decode($swagger->toString(), true); diff --git a/tests/TestCase/Lib/Annotations/SwagOperationTest.php b/tests/TestCase/Lib/Annotations/SwagOperationTest.php index 796d5850..14a92973 100644 --- a/tests/TestCase/Lib/Annotations/SwagOperationTest.php +++ b/tests/TestCase/Lib/Annotations/SwagOperationTest.php @@ -7,8 +7,8 @@ use Cake\Routing\RouteBuilder; use Cake\TestSuite\TestCase; use SwaggerBake\Lib\AnnotationLoader; -use SwaggerBake\Lib\EntityScanner; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Model\ModelScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Configuration; use SwaggerBake\Lib\Swagger; @@ -79,7 +79,7 @@ public function setUp(): void if (!$this->swagger instanceof Swagger) { $configuration = new Configuration($this->config, SWAGGER_BAKE_TEST_APP); $cakeRoute = new RouteScanner($this->router, $configuration); - $this->swagger = new Swagger(new EntityScanner($cakeRoute, $configuration)); + $this->swagger = new Swagger(new ModelScanner($cakeRoute, $configuration)); } AnnotationLoader::load(); diff --git a/tests/TestCase/Lib/Annotations/SwagPaginatorTest.php b/tests/TestCase/Lib/Annotations/SwagPaginatorTest.php index 746bf7c9..d5337658 100644 --- a/tests/TestCase/Lib/Annotations/SwagPaginatorTest.php +++ b/tests/TestCase/Lib/Annotations/SwagPaginatorTest.php @@ -7,8 +7,8 @@ use Cake\Routing\RouteBuilder; use Cake\TestSuite\TestCase; use SwaggerBake\Lib\AnnotationLoader; -use SwaggerBake\Lib\EntityScanner; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Model\ModelScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Configuration; use SwaggerBake\Lib\Swagger; @@ -53,7 +53,7 @@ public function testSwagPaginator() { $cakeRoute = new RouteScanner($this->router, $this->config); - $swagger = new Swagger(new EntityScanner($cakeRoute, $this->config)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $this->config)); $arr = json_decode($swagger->toString(), true); $this->assertArrayHasKey('/departments', $arr['paths']); diff --git a/tests/TestCase/Lib/Annotations/SwagPathParameterTest.php b/tests/TestCase/Lib/Annotations/SwagPathParameterTest.php index eb6cc958..d9ac779a 100644 --- a/tests/TestCase/Lib/Annotations/SwagPathParameterTest.php +++ b/tests/TestCase/Lib/Annotations/SwagPathParameterTest.php @@ -7,8 +7,8 @@ use Cake\Routing\RouteBuilder; use Cake\TestSuite\TestCase; use SwaggerBake\Lib\AnnotationLoader; -use SwaggerBake\Lib\EntityScanner; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Model\ModelScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Configuration; use SwaggerBake\Lib\Swagger; @@ -61,7 +61,7 @@ public function testSwagQuery() { $cakeRoute = new RouteScanner($this->router, $this->config); - $swagger = new Swagger(new EntityScanner($cakeRoute, $this->config)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $this->config)); $arr = json_decode($swagger->toString(), true); $params = $arr['paths']['/operation-path/path-parameter/{id}']['get']['parameters']; diff --git a/tests/TestCase/Lib/Annotations/SwagPathTest.php b/tests/TestCase/Lib/Annotations/SwagPathTest.php index 92ff18df..484d800a 100644 --- a/tests/TestCase/Lib/Annotations/SwagPathTest.php +++ b/tests/TestCase/Lib/Annotations/SwagPathTest.php @@ -9,8 +9,8 @@ use Cake\Routing\RouteBuilder; use Cake\TestSuite\TestCase; use SwaggerBake\Lib\AnnotationLoader; -use SwaggerBake\Lib\EntityScanner; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Model\ModelScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Configuration; use SwaggerBake\Lib\Swagger; @@ -65,7 +65,7 @@ public function testPath() $cakeRoute = new RouteScanner($this->router, $config); - $swagger = new Swagger(new EntityScanner($cakeRoute, $config)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $config)); $arr = json_decode($swagger->toString(), true); $employees = $arr['paths']['/employees']; @@ -80,7 +80,7 @@ public function testPathInvisible() $cakeRoute = new RouteScanner($this->router, $config); - $swagger = new Swagger(new EntityScanner($cakeRoute, $config)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $config)); $arr = json_decode($swagger->toString(), true); diff --git a/tests/TestCase/Lib/Annotations/SwagQueryTest.php b/tests/TestCase/Lib/Annotations/SwagQueryTest.php index d0d87dbd..2c4fac1e 100644 --- a/tests/TestCase/Lib/Annotations/SwagQueryTest.php +++ b/tests/TestCase/Lib/Annotations/SwagQueryTest.php @@ -7,8 +7,8 @@ use Cake\Routing\RouteBuilder; use Cake\TestSuite\TestCase; use SwaggerBake\Lib\AnnotationLoader; -use SwaggerBake\Lib\EntityScanner; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Model\ModelScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Configuration; use SwaggerBake\Lib\Swagger; @@ -53,7 +53,7 @@ public function testSwagQuery() { $cakeRoute = new RouteScanner($this->router, $this->config); - $swagger = new Swagger(new EntityScanner($cakeRoute, $this->config)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $this->config)); $arr = json_decode($swagger->toString(), true); $this->assertArrayHasKey('/departments', $arr['paths']); diff --git a/tests/TestCase/Lib/Annotations/SwagRequestBodyContentTest.php b/tests/TestCase/Lib/Annotations/SwagRequestBodyContentTest.php index 7f3ccd06..e540a895 100644 --- a/tests/TestCase/Lib/Annotations/SwagRequestBodyContentTest.php +++ b/tests/TestCase/Lib/Annotations/SwagRequestBodyContentTest.php @@ -7,8 +7,8 @@ use Cake\Routing\RouteBuilder; use Cake\TestSuite\TestCase; use SwaggerBake\Lib\AnnotationLoader; -use SwaggerBake\Lib\EntityScanner; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Model\ModelScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Configuration; use SwaggerBake\Lib\Swagger; @@ -71,7 +71,7 @@ public function testSwagRequestBodyContent() { $cakeRoute = new RouteScanner($this->router, $this->config); - $swagger = new Swagger(new EntityScanner($cakeRoute, $this->config)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $this->config)); $arr = json_decode($swagger->toString(), true); $operation = $arr['paths']['/swag-request-body-content/text-plain']['post']; @@ -83,7 +83,7 @@ public function testMultipleMimeTypes() { $cakeRoute = new RouteScanner($this->router, $this->config); - $swagger = new Swagger(new EntityScanner($cakeRoute, $this->config)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $this->config)); $arr = json_decode($swagger->toString(), true); $operation = $arr['paths']['/swag-request-body-content/multiple-mime-types']['post']; @@ -95,7 +95,7 @@ public function testUseMimeTypesFromConfig() { $cakeRoute = new RouteScanner($this->router, $this->config); - $swagger = new Swagger(new EntityScanner($cakeRoute, $this->config)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $this->config)); $arr = json_decode($swagger->toString(), true); $operation = $arr['paths']['/swag-request-body-content/use-config-defaults']['post']; diff --git a/tests/TestCase/Lib/Annotations/SwagRequestBodyTest.php b/tests/TestCase/Lib/Annotations/SwagRequestBodyTest.php index d6656367..82df06ce 100644 --- a/tests/TestCase/Lib/Annotations/SwagRequestBodyTest.php +++ b/tests/TestCase/Lib/Annotations/SwagRequestBodyTest.php @@ -7,8 +7,8 @@ use Cake\Routing\RouteBuilder; use Cake\TestSuite\TestCase; use SwaggerBake\Lib\AnnotationLoader; -use SwaggerBake\Lib\EntityScanner; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Model\ModelScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Configuration; use SwaggerBake\Lib\Swagger; @@ -59,9 +59,9 @@ public function setUp(): void public function testSwagRequestBody() { - $cakeRoute = new RouteScanner($this->router, $this->config); + $routeScanner = new RouteScanner($this->router, $this->config); - $swagger = new Swagger(new EntityScanner($cakeRoute, $this->config)); + $swagger = new Swagger(new ModelScanner($routeScanner, $this->config)); $arr = json_decode($swagger->toString(), true); $operation = $arr['paths']['/employees/custom-post']['post']; diff --git a/tests/TestCase/Lib/Annotations/SwagResponseSchemaTest.php b/tests/TestCase/Lib/Annotations/SwagResponseSchemaTest.php index 812fd124..05cfe254 100644 --- a/tests/TestCase/Lib/Annotations/SwagResponseSchemaTest.php +++ b/tests/TestCase/Lib/Annotations/SwagResponseSchemaTest.php @@ -7,8 +7,8 @@ use Cake\Routing\RouteBuilder; use Cake\TestSuite\TestCase; use SwaggerBake\Lib\AnnotationLoader; -use SwaggerBake\Lib\EntityScanner; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Model\ModelScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Configuration; use SwaggerBake\Lib\Swagger; @@ -69,7 +69,7 @@ public function setUp(): void if (!$this->swagger instanceof Swagger) { $cakeRoute = new RouteScanner($this->router, $this->config); - $this->swagger = new Swagger(new EntityScanner($cakeRoute, $this->config)); + $this->swagger = new Swagger(new ModelScanner($cakeRoute, $this->config)); } diff --git a/tests/TestCase/Lib/Annotations/SwagSecurityTest.php b/tests/TestCase/Lib/Annotations/SwagSecurityTest.php index 2e0f2e44..84042ad8 100644 --- a/tests/TestCase/Lib/Annotations/SwagSecurityTest.php +++ b/tests/TestCase/Lib/Annotations/SwagSecurityTest.php @@ -7,8 +7,8 @@ use Cake\Routing\RouteBuilder; use Cake\TestSuite\TestCase; use SwaggerBake\Lib\AnnotationLoader; -use SwaggerBake\Lib\EntityScanner; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Model\ModelScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Configuration; use SwaggerBake\Lib\Swagger; @@ -61,7 +61,7 @@ public function testSwagHeader() { $cakeRoute = new RouteScanner($this->router, $this->config); - $swagger = new Swagger(new EntityScanner($cakeRoute, $this->config)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $this->config)); $arr = json_decode($swagger->toString(), true); diff --git a/tests/TestCase/Lib/Decorator/EntityDecoratorTest.php b/tests/TestCase/Lib/Decorator/EntityDecoratorTest.php deleted file mode 100644 index 794b4f23..00000000 --- a/tests/TestCase/Lib/Decorator/EntityDecoratorTest.php +++ /dev/null @@ -1,29 +0,0 @@ - new Department(), - 'name' => 'Department', - 'fqns' => 'SwaggerBakeTest\App\Model\Entity\Department' - ]; - - $entityDecorator = (new EntityDecorator(new Entity())) - ->setName($properties['name']) - ->setEntity($properties['entity']) - ->setFqns($properties['fqns']); - - $this->assertEquals($properties['entity'], $entityDecorator->getEntity()); - $this->assertEquals($properties['name'], $entityDecorator->getName()); - $this->assertEquals($properties['fqns'], $entityDecorator->getFqns()); - } -} \ No newline at end of file diff --git a/tests/TestCase/Lib/Extension/CakeSearch/ExtensionTest.php b/tests/TestCase/Lib/Extension/CakeSearch/ExtensionTest.php index fa8216e0..b315b199 100644 --- a/tests/TestCase/Lib/Extension/CakeSearch/ExtensionTest.php +++ b/tests/TestCase/Lib/Extension/CakeSearch/ExtensionTest.php @@ -6,8 +6,8 @@ use Cake\Routing\Router; use Cake\TestSuite\TestCase; use SwaggerBake\Lib\AnnotationLoader; -use SwaggerBake\Lib\EntityScanner; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Model\ModelScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Configuration; use SwaggerBake\Lib\Extension\CakeSearch\Annotation\SwagSearch; use SwaggerBake\Lib\ExtensionLoader; @@ -71,7 +71,7 @@ public function testGetOperation() $configuration = new Configuration($this->config, SWAGGER_BAKE_TEST_APP); $cakeRoute = new RouteScanner($this->router, $configuration); - $swagger = new Swagger(new EntityScanner($cakeRoute, $configuration)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $configuration)); $arr = json_decode($swagger->toString(), true); diff --git a/tests/TestCase/Lib/Operation/OperationFromRouteFactoryTest.php b/tests/TestCase/Lib/Operation/OperationFromRouteFactoryTest.php index f4778cfa..b02b41d7 100644 --- a/tests/TestCase/Lib/Operation/OperationFromRouteFactoryTest.php +++ b/tests/TestCase/Lib/Operation/OperationFromRouteFactoryTest.php @@ -5,7 +5,7 @@ use Cake\Routing\RouteBuilder; use Cake\Routing\Router; use Cake\TestSuite\TestCase; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Configuration; use SwaggerBake\Lib\Factory\SwaggerFactory; use SwaggerBake\Lib\OpenApi\Operation; diff --git a/tests/TestCase/Lib/Operation/OperationPathTest.php b/tests/TestCase/Lib/Operation/OperationPathTest.php index 5f2ce512..bfbb1bb2 100644 --- a/tests/TestCase/Lib/Operation/OperationPathTest.php +++ b/tests/TestCase/Lib/Operation/OperationPathTest.php @@ -4,9 +4,9 @@ use Cake\TestSuite\TestCase; use Cake\Routing\Route\Route; -use SwaggerBake\Lib\Decorator\RouteDecorator; use SwaggerBake\Lib\OpenApi\Operation; use SwaggerBake\Lib\Operation\OperationPath; +use SwaggerBake\Lib\Route\RouteDecorator; class OperationPathTest extends TestCase { diff --git a/tests/TestCase/Lib/Operation/OperationRequestBodyTest.php b/tests/TestCase/Lib/Operation/OperationRequestBodyTest.php index 7e122252..16dfed45 100644 --- a/tests/TestCase/Lib/Operation/OperationRequestBodyTest.php +++ b/tests/TestCase/Lib/Operation/OperationRequestBodyTest.php @@ -9,8 +9,8 @@ use SwaggerBake\Lib\Annotation\SwagDto; use SwaggerBake\Lib\Annotation\SwagForm; use SwaggerBake\Lib\Annotation\SwagRequestBody; -use SwaggerBake\Lib\EntityScanner; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Model\ModelScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Configuration; use SwaggerBake\Lib\OpenApi\Operation; use SwaggerBake\Lib\OpenApi\Schema; @@ -60,7 +60,7 @@ public function testSwagFormGetOperationWithRequestBody() { $config = new Configuration($this->config, SWAGGER_BAKE_TEST_APP); $cakeRoute = new RouteScanner($this->router, $config); - $cakeModels = new EntityScanner($cakeRoute, $config); + $cakeModels = new ModelScanner($cakeRoute, $config); $swagger = new Swagger($cakeModels); $routes = $cakeRoute->getRoutes(); @@ -92,7 +92,7 @@ public function testSwagDtoGetOperationWithRequestBody() { $config = new Configuration($this->config, SWAGGER_BAKE_TEST_APP); $cakeRoute = new RouteScanner($this->router, $config); - $cakeModels = new EntityScanner($cakeRoute, $config); + $cakeModels = new ModelScanner($cakeRoute, $config); $swagger = new Swagger($cakeModels); $routes = $cakeRoute->getRoutes(); @@ -125,7 +125,7 @@ public function testIgnoreSchema() { $config = new Configuration($this->config, SWAGGER_BAKE_TEST_APP); $cakeRoute = new RouteScanner($this->router, $config); - $cakeModels = new EntityScanner($cakeRoute, $config); + $cakeModels = new ModelScanner($cakeRoute, $config); $swagger = new Swagger($cakeModels); $routes = $cakeRoute->getRoutes(); diff --git a/tests/TestCase/Lib/Operation/OperationResponseTest.php b/tests/TestCase/Lib/Operation/OperationResponseTest.php index 01097c77..91fc7cd0 100644 --- a/tests/TestCase/Lib/Operation/OperationResponseTest.php +++ b/tests/TestCase/Lib/Operation/OperationResponseTest.php @@ -7,7 +7,7 @@ use Cake\TestSuite\TestCase; use phpDocumentor\Reflection\DocBlockFactory; use SwaggerBake\Lib\Annotation\SwagResponseSchema; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Configuration; use SwaggerBake\Lib\OpenApi\Operation; use SwaggerBake\Lib\OpenApi\Response; diff --git a/tests/TestCase/Lib/Operation/OperationSecurityTest.php b/tests/TestCase/Lib/Operation/OperationSecurityTest.php index d77feb5d..c27aacf4 100644 --- a/tests/TestCase/Lib/Operation/OperationSecurityTest.php +++ b/tests/TestCase/Lib/Operation/OperationSecurityTest.php @@ -8,18 +8,15 @@ use Cake\Routing\Router; use Cake\TestSuite\TestCase; use SwaggerBake\Lib\Annotation\SwagSecurity; -use SwaggerBake\Lib\RouteScanner; use SwaggerBake\Lib\Configuration; -use SwaggerBake\Lib\Decorator\RouteDecorator; use SwaggerBake\Lib\Factory\SwaggerFactory; use SwaggerBake\Lib\OpenApi\Operation; use SwaggerBake\Lib\Operation\OperationSecurity; +use SwaggerBake\Lib\Route\RouteDecorator; +use SwaggerBake\Lib\Route\RouteScanner; class OperationSecurityTest extends TestCase { - /** @var OperationSecurity */ - private $operationSecurity; - /** @var \SwaggerBake\Lib\Swagger */ private $swagger; diff --git a/tests/TestCase/Lib/Path/PathFromRouteFactoryTest.php b/tests/TestCase/Lib/Path/PathFromRouteFactoryTest.php index 262514a4..c03e4a2f 100644 --- a/tests/TestCase/Lib/Path/PathFromRouteFactoryTest.php +++ b/tests/TestCase/Lib/Path/PathFromRouteFactoryTest.php @@ -5,7 +5,7 @@ use Cake\Routing\RouteBuilder; use Cake\Routing\Router; use Cake\TestSuite\TestCase; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Configuration; use SwaggerBake\Lib\OpenApi\Path; use SwaggerBake\Lib\Path\PathFromRouteFactory; diff --git a/tests/TestCase/Lib/Schema/SchemaFactoryTest.php b/tests/TestCase/Lib/Schema/SchemaFactoryTest.php index d573a736..89406a3e 100644 --- a/tests/TestCase/Lib/Schema/SchemaFactoryTest.php +++ b/tests/TestCase/Lib/Schema/SchemaFactoryTest.php @@ -2,15 +2,17 @@ namespace SwaggerBake\Test\TestCase\Lib\Schema; -use Cake\ORM\Entity; +use Cake\Controller\Controller; +use Cake\Datasource\ConnectionManager; use Cake\TestSuite\TestCase; +use MixerApi\Core\Model\ModelFactory; use SwaggerBake\Lib\Configuration; use SwaggerBake\Lib\Decorator\EntityDecorator; -use SwaggerBake\Lib\Decorator\PropertyDecorator; +use SwaggerBake\Lib\Model\ModelDecorator; use SwaggerBake\Lib\OpenApi\Schema; -use SwaggerBake\Lib\OpenApi\SchemaProperty; use SwaggerBake\Lib\Schema\SchemaFactory; use SwaggerBakeTest\App\Model\Entity\Department; +use SwaggerBakeTest\App\Model\Table\DepartmentsTable; class SchemaFactoryTest extends TestCase { @@ -41,27 +43,19 @@ public function setUp(): void public function testCreateSchema() { - $entityDecorator = new EntityDecorator(new Department()); - $entityDecorator->setProperties([ - (new PropertyDecorator())->setName('id')->setType('integer')->setIsPrimaryKey(true), - (new PropertyDecorator())->setName('name')->setType('string'), - (new PropertyDecorator())->setName('created')->setType('datetime'), - (new PropertyDecorator())->setName('modified')->setType('datetime'), - ]); - $schema = (new SchemaFactory($this->configuration))->create($entityDecorator); + $connection = ConnectionManager::get('default'); + $department = (new ModelFactory($connection, new DepartmentsTable()))->create(); + $decorator = new ModelDecorator($department, new Controller()); + $schema = (new SchemaFactory())->create($decorator); $this->assertInstanceOf(Schema::class, $schema); } public function testWriteSchema() { - $entityDecorator = new EntityDecorator(new Department()); - $entityDecorator->setProperties([ - (new PropertyDecorator())->setName('id')->setType('integer')->setIsPrimaryKey(true), - (new PropertyDecorator())->setName('name')->setType('string'), - (new PropertyDecorator())->setName('created')->setType('datetime'), - (new PropertyDecorator())->setName('modified')->setType('datetime'), - ]); - $schema = (new SchemaFactory($this->configuration))->create($entityDecorator, SchemaFactory::WRITEABLE_PROPERTIES); + $connection = ConnectionManager::get('default'); + $department = (new ModelFactory($connection, new DepartmentsTable()))->create(); + $decorator = new ModelDecorator($department, new Controller()); + $schema = (new SchemaFactory())->create($decorator, SchemaFactory::WRITEABLE_PROPERTIES); $this->assertCount(1, $schema->getProperties()); } } \ No newline at end of file diff --git a/tests/TestCase/Lib/Schema/SchemaPropertyFormatTest.php b/tests/TestCase/Lib/Schema/SchemaPropertyFormatTest.php index 0aea9cc3..bf6c448e 100644 --- a/tests/TestCase/Lib/Schema/SchemaPropertyFormatTest.php +++ b/tests/TestCase/Lib/Schema/SchemaPropertyFormatTest.php @@ -4,7 +4,7 @@ use Cake\TestSuite\TestCase; use Cake\Validation\Validator; -use SwaggerBake\Lib\Decorator\PropertyDecorator; +use MixerApi\Core\Model\ModelProperty; use SwaggerBake\Lib\OpenApi\SchemaProperty; use SwaggerBake\Lib\Schema\SchemaPropertyFormat; @@ -33,7 +33,7 @@ public function testWithFormat() $schemaPropertyFormat = new SchemaPropertyFormat( (new Validator())->{$rule}('test_field'), (new SchemaProperty())->setName('test_field')->setType($vars['type']), - (new PropertyDecorator())->setName('test_field')->setType($vars['type']) + (new ModelProperty())->setName('test_field')->setType($vars['type']) ); $schemaProperty = $schemaPropertyFormat->withFormat(); $this->assertEquals( diff --git a/tests/TestCase/Lib/Schema/SchemaPropertyValidationTest.php b/tests/TestCase/Lib/Schema/SchemaPropertyValidationTest.php index 26b0e452..fdd8b930 100644 --- a/tests/TestCase/Lib/Schema/SchemaPropertyValidationTest.php +++ b/tests/TestCase/Lib/Schema/SchemaPropertyValidationTest.php @@ -4,10 +4,9 @@ use Cake\TestSuite\TestCase; use Cake\Validation\Validator; -use SwaggerBake\Lib\Decorator\PropertyDecorator; +use MixerApi\Core\Model\ModelProperty; use SwaggerBake\Lib\OpenApi\SchemaProperty; use SwaggerBake\Lib\Schema\SchemaPropertyFactory; -use SwaggerBake\Lib\Schema\SchemaPropertyFormat; use SwaggerBake\Lib\Schema\SchemaPropertyValidation; class SchemaPropertyValidationTest extends TestCase @@ -25,7 +24,7 @@ public function testWithValidations() $schemaPropertyValidation = new SchemaPropertyValidation( $validator, (new SchemaProperty())->setName('test_field')->setType('integer'), - (new PropertyDecorator())->setName('test_field')->setType('integer') + (new ModelProperty())->setName('test_field')->setType('integer') ); $schemaProperty = $schemaPropertyValidation->withValidations(); @@ -40,13 +39,13 @@ public function testWithValidations() // length between $validator = (new Validator())->lengthBetween('test_field', [5,10]); - $propertyDecorator = (new PropertyDecorator())->setName('test_field')->setType('integer'); - $schemaProperty = (new SchemaPropertyFactory($validator))->create($propertyDecorator); + $property = (new ModelProperty())->setName('test_field')->setType('integer'); + $schemaProperty = (new SchemaPropertyFactory($validator))->create($property); $schemaPropertyValidation = new SchemaPropertyValidation( $validator, $schemaProperty, - $propertyDecorator + $property ); $schemaProperty = $schemaPropertyValidation->withValidations(); @@ -64,7 +63,7 @@ public function testWithValidationsMinAndMax() $schemaPropertyValidation = new SchemaPropertyValidation( $validator, (new SchemaProperty())->setName('test_field')->setType('integer'), - (new PropertyDecorator())->setName('test_field')->setType('integer') + (new ModelProperty())->setName('test_field')->setType('integer') ); $schemaProperty = $schemaPropertyValidation->withValidations(); @@ -82,7 +81,7 @@ public function testWithValidationsExclusiveMinAndMax() $schemaPropertyValidation = new SchemaPropertyValidation( $validator, (new SchemaProperty())->setName('test_field')->setType('integer'), - (new PropertyDecorator())->setName('test_field')->setType('integer') + (new ModelProperty())->setName('test_field')->setType('integer') ); $schemaProperty = $schemaPropertyValidation->withValidations(); @@ -103,7 +102,7 @@ public function testWithValidationsArrays() $schemaPropertyValidation = new SchemaPropertyValidation( $validator, (new SchemaProperty())->setName('test_field'), - (new PropertyDecorator())->setName('test_field') + (new ModelProperty())->setName('test_field') ); $schemaProperty = $schemaPropertyValidation->withValidations(); @@ -121,7 +120,7 @@ public function testWithValidationsRequirePresence() $schemaPropertyValidation = new SchemaPropertyValidation( $validator, (new SchemaProperty())->setName('test_field'), - (new PropertyDecorator())->setName('test_field') + (new ModelProperty())->setName('test_field') ); $schemaProperty = $schemaPropertyValidation->withValidations(); @@ -139,7 +138,7 @@ public function testWithValidationsRequirePresenceCreate() $schemaPropertyValidation = new SchemaPropertyValidation( $validator, (new SchemaProperty())->setName('test_field'), - (new PropertyDecorator())->setName('test_field') + (new ModelProperty())->setName('test_field') ); $schemaProperty = $schemaPropertyValidation->withValidations(); @@ -157,7 +156,7 @@ public function testWithValidationsRequirePresenceUpdate() $schemaPropertyValidation = new SchemaPropertyValidation( $validator, (new SchemaProperty())->setName('test_field'), - (new PropertyDecorator())->setName('test_field') + (new ModelProperty())->setName('test_field') ); $schemaProperty = $schemaPropertyValidation->withValidations(); @@ -178,7 +177,7 @@ public function testWithValidationsEmptyString() $schemaPropertyValidation = new SchemaPropertyValidation( $validator, (new SchemaProperty())->setName('test_field')->setType('string'), - (new PropertyDecorator())->setName('test_field')->setType('string') + (new ModelProperty())->setName('test_field')->setType('string') ); $schemaProperty = $schemaPropertyValidation->withValidations(); diff --git a/tests/TestCase/Lib/SwaggerOperationTest.php b/tests/TestCase/Lib/SwaggerOperationTest.php index c03fdb82..b12952bf 100644 --- a/tests/TestCase/Lib/SwaggerOperationTest.php +++ b/tests/TestCase/Lib/SwaggerOperationTest.php @@ -7,8 +7,8 @@ use Cake\Routing\RouteBuilder; use Cake\TestSuite\TestCase; use SwaggerBake\Lib\AnnotationLoader; -use SwaggerBake\Lib\EntityScanner; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Model\ModelScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Configuration; use SwaggerBake\Lib\Swagger; @@ -80,7 +80,7 @@ public function setUp(): void if (!$this->swagger instanceof Swagger) { $configuration = new Configuration($this->config, SWAGGER_BAKE_TEST_APP); $cakeRoute = new RouteScanner($this->router, $configuration); - $this->swagger = new Swagger(new EntityScanner($cakeRoute, $configuration)); + $this->swagger = new Swagger(new ModelScanner($cakeRoute, $configuration)); } AnnotationLoader::load(); @@ -169,7 +169,7 @@ public function testYmlPathOperationTakesPrecedence() $configuration = new Configuration($config, SWAGGER_BAKE_TEST_APP); $cakeRoute = new RouteScanner($this->router, $configuration); - $swagger = new Swagger(new EntityScanner($cakeRoute, $configuration)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $configuration)); $arr = json_decode($swagger->toString(), true); @@ -186,7 +186,7 @@ public function testSecuritySchemeFromAuthenticationComponent() $configuration = new Configuration($config, SWAGGER_BAKE_TEST_APP); $cakeRoute = new RouteScanner($this->router, $configuration); - $swagger = new Swagger(new EntityScanner($cakeRoute, $configuration)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $configuration)); $arr = json_decode($swagger->toString(), true); $securities = $arr['paths']['/departments']['get']['security']; @@ -201,7 +201,7 @@ public function testSecuritySchemeMultipleSwagSecurity() $configuration = new Configuration($config, SWAGGER_BAKE_TEST_APP); $cakeRoute = new RouteScanner($this->router, $configuration); - $swagger = new Swagger(new EntityScanner($cakeRoute, $configuration)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $configuration)); $arr = json_decode($swagger->toString(), true); $securities = $arr['paths']['/departments/{id}']['get']['security']; diff --git a/tests/TestCase/Lib/SwaggerSchemaTest.php b/tests/TestCase/Lib/SwaggerSchemaTest.php index df34be11..d2f5c0a1 100644 --- a/tests/TestCase/Lib/SwaggerSchemaTest.php +++ b/tests/TestCase/Lib/SwaggerSchemaTest.php @@ -6,8 +6,8 @@ use Cake\Routing\RouteBuilder; use Cake\TestSuite\TestCase; use SwaggerBake\Lib\AnnotationLoader; -use SwaggerBake\Lib\EntityScanner; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Model\ModelScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Configuration; use SwaggerBake\Lib\Swagger; @@ -53,7 +53,7 @@ public function testEmployeeTableProperties() { $cakeRoute = new RouteScanner($this->router, $this->config); - $swagger = new Swagger(new EntityScanner($cakeRoute, $this->config)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $this->config)); $arr = json_decode($swagger->toString(), true); @@ -70,7 +70,7 @@ public function testYmlSchemaTakesPrecedence() { $cakeRoute = new RouteScanner($this->router, $this->config); - $swagger = new Swagger(new EntityScanner($cakeRoute, $this->config)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $this->config)); $arr = json_decode($swagger->toString(), true); diff --git a/tests/TestCase/Lib/SwaggerTest.php b/tests/TestCase/Lib/SwaggerTest.php index 00ba591a..8c660df4 100644 --- a/tests/TestCase/Lib/SwaggerTest.php +++ b/tests/TestCase/Lib/SwaggerTest.php @@ -9,8 +9,8 @@ use Cake\Routing\RouteBuilder; use Cake\TestSuite\TestCase; use SwaggerBake\Lib\AnnotationLoader; -use SwaggerBake\Lib\EntityScanner; -use SwaggerBake\Lib\RouteScanner; +use SwaggerBake\Lib\Model\ModelScanner; +use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Configuration; use SwaggerBake\Lib\Swagger; @@ -75,7 +75,7 @@ public function testGetArrayWithExistingPathsAndSchema() $cakeRoute = new RouteScanner($this->router, $config); - $swagger = new Swagger(new EntityScanner($cakeRoute, $config)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $config)); $arr = json_decode($swagger->toString(), true); @@ -91,7 +91,7 @@ public function testGetArrayFromBareBones() $cakeRoute = new RouteScanner($this->router, $config); - $swagger = new Swagger(new EntityScanner($cakeRoute, $config)); + $swagger = new Swagger(new ModelScanner($cakeRoute, $config)); $arr = json_decode($swagger->toString(), true); $this->assertArrayHasKey('/departments', $arr['paths']); diff --git a/tests/test_app/src/Dto/EmployeeData.php b/tests/test_app/src/Dto/EmployeeData.php index dc8d5b97..bdeb1120 100644 --- a/tests/test_app/src/Dto/EmployeeData.php +++ b/tests/test_app/src/Dto/EmployeeData.php @@ -17,19 +17,19 @@ class EmployeeData private $lastName; /** - * @Swag\SwagDtoForm(name="title", type="string", description="testing") + * @Swag\SwagRequestBody(name="title", type="string", description="testing") * @var string */ private $title; /** - * @Swag\SwagDtoForm(name="age", type="integer", format="int32" description="testing") + * @Swag\SwagRequestBody(name="age", type="integer", format="int32" description="testing") * @var integer */ private $age; /** - * @Swag\SwagDtoForm(name="date", type="string", format="date", description="testing") + * @Swag\SwagRequestBody(name="date", type="string", format="date", description="testing") * @var string */ private $date;