diff --git a/src/Generator/Client.php b/src/Generator/Client.php index 22e4333..025349f 100644 --- a/src/Generator/Client.php +++ b/src/Generator/Client.php @@ -16,7 +16,6 @@ use ApiClients\Tools\OpenApiClientGenerator\PrivatePromotedPropertyAsParam; use ApiClients\Tools\OpenApiClientGenerator\Representation; use ApiClients\Tools\OpenApiClientGenerator\Utils; -use EventSauce\ObjectHydrator\ObjectMapper; use Jawira\CaseConverter\Convert; use NumberToWords\NumberToWords; use PhpParser\Builder\Method; @@ -903,49 +902,6 @@ private static function callOperation(Routers $routers, Representation\Operation } })($operation->parameters), ] : []), - /** @phpstan-ignore-next-line */ - ...(count(array_filter((new ReflectionClass($operation->className->fullyQualified->source))->getConstructor()->getParameters(), static fn (ReflectionParameter $parameter): bool => $parameter->name === 'responseSchemaValidator' || $parameter->name === 'hydrator')) > 0 ? [ - new Node\Stmt\If_( - new Node\Expr\BinaryOp\Equal( - new Node\Expr\FuncCall( - new Node\Name('\array_key_exists'), - [ - new Arg(new Node\Expr\ClassConstFetch( - new Node\Name($path->hydrator->className->relative), - 'class', - )), - new Arg(new Node\Expr\PropertyFetch( - new Node\Expr\Variable('this'), - 'hydrator', - )), - ], - ), - new Node\Expr\ConstFetch(new Node\Name('false')), - ), - [ - 'stmts' => [ - new Node\Stmt\Expression( - new Node\Expr\Assign( - new Node\Expr\ArrayDimFetch(new Node\Expr\PropertyFetch( - new Node\Expr\Variable('this'), - 'hydrator', - ), new Node\Expr\ClassConstFetch( - new Node\Name($path->hydrator->className->relative), - 'class', - )), - new Node\Expr\MethodCall( - new Node\Expr\PropertyFetch( - new Node\Expr\Variable('this'), - 'hydrators', - ), - 'getObjectMapper' . ucfirst($path->hydrator->methodName), - ), - ), - ), - ], - ], - ), - ] : []), ...($operation->matchMethod !== 'LIST' ? self::makeCall( $operation, $path, @@ -1115,13 +1071,15 @@ private static function makeCall(Representation\Operation $operation, Representa new Node\Expr\Variable('this'), 'responseSchemaValidator', )), - new Arg(new Node\Expr\ArrayDimFetch(new Node\Expr\PropertyFetch( - new Node\Expr\Variable('this'), - 'hydrator', - ), new Node\Expr\ClassConstFetch( - new Node\Name($path->hydrator->className->relative), - 'class', - ))), + new Arg( + new Node\Expr\MethodCall( + new Node\Expr\PropertyFetch( + new Node\Expr\Variable('this'), + 'hydrators', + ), + 'getObjectMapper' . ucfirst($path->hydrator->methodName), + ), + ), ] : []), ], ), @@ -1150,12 +1108,6 @@ private static function createRouter(string $pathPrefix, string $namespace, Rout $factory = new BuilderFactory(); $stmt = $factory->namespace(Utils::dirname($namespace . $className)); $class = $factory->class(Utils::basename($namespace . $className))->makeFinal()->addStmt( - $factory->property('hydrator')->setType('array')->setDefault([])->makePrivate()->setDocComment(new Doc(implode(PHP_EOL, [ - '/**', - ' * @var array', - ' */', - ]))), - )->addStmt( $constructor, ); diff --git a/tests/app/etc/openapi-client-generator.state b/tests/app/etc/openapi-client-generator.state index 90e5f2d..2cbb9f5 100644 --- a/tests/app/etc/openapi-client-generator.state +++ b/tests/app/etc/openapi-client-generator.state @@ -208,23 +208,23 @@ }, { "name": ".\/tests\/app\/src\/\/Router\/Get\/Pets.php", - "hash": "68179fe011002d1b456b8f3598380a67" + "hash": "51682197401f5f61739d1ae126d04e81" }, { "name": ".\/tests\/app\/src\/\/Router\/Get\/PetsList.php", - "hash": "61aa5045f5b53d6edfd8eded49fcde80" + "hash": "789dd8b770f3725e3d00073322705e19" }, { "name": ".\/tests\/app\/src\/\/Router\/List\/Pets.php", - "hash": "5bc8638e735e4e3a16359b144b03b640" + "hash": "2275eaa5b79fe7e404e44307c7bd611e" }, { "name": ".\/tests\/app\/src\/\/Router\/List\/PetsList.php", - "hash": "2e4dc5732c808e2d2047203c6f881c05" + "hash": "24686950c441b8eda04aebbe3b2ffd24" }, { "name": ".\/tests\/app\/src\/\/Router\/Post\/Pets.php", - "hash": "e25d1cae2ac66fc5c4081ac3655fb413" + "hash": "4f12671bfe69bab76001414bef941837" }, { "name": ".\/tests\/app\/src\/\/Router\/Get\/Two.php", @@ -284,7 +284,7 @@ }, { "name": ".\/tests\/app\/src\/\/Router\/Get.php", - "hash": "64270922a47a8ea29f38370be61608bc" + "hash": "0c8b86bc66e7540692ee4266e1c2ea95" } ] }, diff --git a/tests/app/src/Router/Get.php b/tests/app/src/Router/Get.php index 8e52860..85b549c 100644 --- a/tests/app/src/Router/Get.php +++ b/tests/app/src/Router/Get.php @@ -15,10 +15,6 @@ use ApiClients\Contracts; final class Get { - /** - * @var array - */ - private array $hydrator = array(); public function __construct(private \League\OpenAPIValidation\Schema\SchemaValidator $requestSchemaValidator, private \League\OpenAPIValidation\Schema\SchemaValidator $responseSchemaValidator, private \ApiClients\Client\PetStore\Hydrators $hydrators, private \React\Http\Browser $browser, private \ApiClients\Contracts\HTTP\Headers\AuthenticationInterface $authentication) { } @@ -27,10 +23,7 @@ public function __construct(private \League\OpenAPIValidation\Schema\SchemaValid */ public function showPetById(array $params) : \ApiClients\Client\PetStore\Schema\Cat|\ApiClients\Client\PetStore\Schema\Dog|\ApiClients\Client\PetStore\Schema\Bird|\ApiClients\Client\PetStore\Schema\Fish|array { - if (\array_key_exists(Hydrator\Operation\Pets\PetId::class, $this->hydrator) == false) { - $this->hydrator[Hydrator\Operation\Pets\PetId::class] = $this->hydrators->getObjectMapperOperation🌀Pets🌀PetId(); - } - $operator = new Operator\ShowPetById($this->browser, $this->authentication, $this->responseSchemaValidator, $this->hydrator[Hydrator\Operation\Pets\PetId::class]); + $operator = new Operator\ShowPetById($this->browser, $this->authentication, $this->responseSchemaValidator, $this->hydrators->getObjectMapperOperation🌀Pets🌀PetId()); return $operator->call(); } } diff --git a/tests/app/src/Router/Get/Pets.php b/tests/app/src/Router/Get/Pets.php index 709ca55..6402d89 100644 --- a/tests/app/src/Router/Get/Pets.php +++ b/tests/app/src/Router/Get/Pets.php @@ -15,10 +15,6 @@ use ApiClients\Contracts; final class Pets { - /** - * @var array - */ - private array $hydrator = array(); public function __construct(private \League\OpenAPIValidation\Schema\SchemaValidator $requestSchemaValidator, private \League\OpenAPIValidation\Schema\SchemaValidator $responseSchemaValidator, private \ApiClients\Client\PetStore\Hydrators $hydrators, private \React\Http\Browser $browser, private \ApiClients\Contracts\HTTP\Headers\AuthenticationInterface $authentication) { } @@ -38,10 +34,7 @@ public function list(array $params) : iterable } $arguments['page'] = $params['page']; unset($params['page']); - if (\array_key_exists(Hydrator\Operation\Pets::class, $this->hydrator) == false) { - $this->hydrator[Hydrator\Operation\Pets::class] = $this->hydrators->getObjectMapperOperation🌀Pets(); - } - $operator = new Operator\Pets\List_($this->browser, $this->authentication, $this->responseSchemaValidator, $this->hydrator[Hydrator\Operation\Pets::class]); + $operator = new Operator\Pets\List_($this->browser, $this->authentication, $this->responseSchemaValidator, $this->hydrators->getObjectMapperOperation🌀Pets()); return $operator->call($arguments['per_page'], $arguments['page']); } /** @@ -60,10 +53,7 @@ public function names(array $params) : iterable } $arguments['page'] = $params['page']; unset($params['page']); - if (\array_key_exists(Hydrator\Operation\Pets\Names::class, $this->hydrator) == false) { - $this->hydrator[Hydrator\Operation\Pets\Names::class] = $this->hydrators->getObjectMapperOperation🌀Pets🌀Names(); - } - $operator = new Operator\Pets\Names($this->browser, $this->authentication, $this->responseSchemaValidator, $this->hydrator[Hydrator\Operation\Pets\Names::class]); + $operator = new Operator\Pets\Names($this->browser, $this->authentication, $this->responseSchemaValidator, $this->hydrators->getObjectMapperOperation🌀Pets🌀Names()); return $operator->call($arguments['per_page'], $arguments['page']); } } diff --git a/tests/app/src/Router/Get/PetsList.php b/tests/app/src/Router/Get/PetsList.php index b0f60ef..ef6ccda 100644 --- a/tests/app/src/Router/Get/PetsList.php +++ b/tests/app/src/Router/Get/PetsList.php @@ -15,10 +15,6 @@ use ApiClients\Contracts; final class PetsList { - /** - * @var array - */ - private array $hydrator = array(); public function __construct(private \League\OpenAPIValidation\Schema\SchemaValidator $requestSchemaValidator, private \League\OpenAPIValidation\Schema\SchemaValidator $responseSchemaValidator, private \ApiClients\Client\PetStore\Hydrators $hydrators, private \React\Http\Browser $browser, private \ApiClients\Contracts\HTTP\Headers\AuthenticationInterface $authentication) { } @@ -38,10 +34,7 @@ public function gatos(array $params) : iterable } $arguments['page'] = $params['page']; unset($params['page']); - if (\array_key_exists(Hydrator\Operation\Pets\Gatos::class, $this->hydrator) == false) { - $this->hydrator[Hydrator\Operation\Pets\Gatos::class] = $this->hydrators->getObjectMapperOperation🌀Pets🌀Gatos(); - } - $operator = new Operator\Pets\List_\Gatos($this->browser, $this->authentication, $this->responseSchemaValidator, $this->hydrator[Hydrator\Operation\Pets\Gatos::class]); + $operator = new Operator\Pets\List_\Gatos($this->browser, $this->authentication, $this->responseSchemaValidator, $this->hydrators->getObjectMapperOperation🌀Pets🌀Gatos()); return $operator->call($arguments['per_page'], $arguments['page']); } } diff --git a/tests/app/src/Router/List/Pets.php b/tests/app/src/Router/List/Pets.php index 9970c7c..f40ace7 100644 --- a/tests/app/src/Router/List/Pets.php +++ b/tests/app/src/Router/List/Pets.php @@ -15,10 +15,6 @@ use ApiClients\Contracts; final class Pets { - /** - * @var array - */ - private array $hydrator = array(); public function __construct(private \League\OpenAPIValidation\Schema\SchemaValidator $requestSchemaValidator, private \League\OpenAPIValidation\Schema\SchemaValidator $responseSchemaValidator, private \ApiClients\Client\PetStore\Hydrators $hydrators, private \React\Http\Browser $browser, private \ApiClients\Contracts\HTTP\Headers\AuthenticationInterface $authentication) { } @@ -38,12 +34,9 @@ public function listListing(array $params) : iterable } $arguments['page'] = $params['page']; unset($params['page']); - if (\array_key_exists(Hydrator\Operation\Pets::class, $this->hydrator) == false) { - $this->hydrator[Hydrator\Operation\Pets::class] = $this->hydrators->getObjectMapperOperation🌀Pets(); - } $arguments['page'] = 1; do { - $operator = new Operator\Pets\ListListing($this->browser, $this->authentication, $this->responseSchemaValidator, $this->hydrator[Hydrator\Operation\Pets::class]); + $operator = new Operator\Pets\ListListing($this->browser, $this->authentication, $this->responseSchemaValidator, $this->hydrators->getObjectMapperOperation🌀Pets()); $items = $operator->call($arguments['per_page'], $arguments['page']); yield from $items; $arguments['page']++; @@ -65,12 +58,9 @@ public function namesListing(array $params) : iterable } $arguments['page'] = $params['page']; unset($params['page']); - if (\array_key_exists(Hydrator\Operation\Pets\Names::class, $this->hydrator) == false) { - $this->hydrator[Hydrator\Operation\Pets\Names::class] = $this->hydrators->getObjectMapperOperation🌀Pets🌀Names(); - } $arguments['page'] = 1; do { - $operator = new Operator\Pets\NamesListing($this->browser, $this->authentication, $this->responseSchemaValidator, $this->hydrator[Hydrator\Operation\Pets\Names::class]); + $operator = new Operator\Pets\NamesListing($this->browser, $this->authentication, $this->responseSchemaValidator, $this->hydrators->getObjectMapperOperation🌀Pets🌀Names()); $items = $operator->call($arguments['per_page'], $arguments['page']); yield from $items; $arguments['page']++; diff --git a/tests/app/src/Router/List/PetsList.php b/tests/app/src/Router/List/PetsList.php index f2c5cff..750a09f 100644 --- a/tests/app/src/Router/List/PetsList.php +++ b/tests/app/src/Router/List/PetsList.php @@ -15,10 +15,6 @@ use ApiClients\Contracts; final class PetsList { - /** - * @var array - */ - private array $hydrator = array(); public function __construct(private \League\OpenAPIValidation\Schema\SchemaValidator $requestSchemaValidator, private \League\OpenAPIValidation\Schema\SchemaValidator $responseSchemaValidator, private \ApiClients\Client\PetStore\Hydrators $hydrators, private \React\Http\Browser $browser, private \ApiClients\Contracts\HTTP\Headers\AuthenticationInterface $authentication) { } @@ -38,12 +34,9 @@ public function gatosListing(array $params) : iterable } $arguments['page'] = $params['page']; unset($params['page']); - if (\array_key_exists(Hydrator\Operation\Pets\Gatos::class, $this->hydrator) == false) { - $this->hydrator[Hydrator\Operation\Pets\Gatos::class] = $this->hydrators->getObjectMapperOperation🌀Pets🌀Gatos(); - } $arguments['page'] = 1; do { - $operator = new Operator\Pets\List_\GatosListing($this->browser, $this->authentication, $this->responseSchemaValidator, $this->hydrator[Hydrator\Operation\Pets\Gatos::class]); + $operator = new Operator\Pets\List_\GatosListing($this->browser, $this->authentication, $this->responseSchemaValidator, $this->hydrators->getObjectMapperOperation🌀Pets🌀Gatos()); $items = $operator->call($arguments['per_page'], $arguments['page']); yield from $items; $arguments['page']++; diff --git a/tests/app/src/Router/Post/Pets.php b/tests/app/src/Router/Post/Pets.php index c65de47..aeab8bb 100644 --- a/tests/app/src/Router/Post/Pets.php +++ b/tests/app/src/Router/Post/Pets.php @@ -15,10 +15,6 @@ use ApiClients\Contracts; final class Pets { - /** - * @var array - */ - private array $hydrator = array(); public function __construct(private \League\OpenAPIValidation\Schema\SchemaValidator $requestSchemaValidator, private \League\OpenAPIValidation\Schema\SchemaValidator $responseSchemaValidator, private \ApiClients\Client\PetStore\Hydrators $hydrators, private \React\Http\Browser $browser, private \ApiClients\Contracts\HTTP\Headers\AuthenticationInterface $authentication) { } @@ -27,10 +23,7 @@ public function __construct(private \League\OpenAPIValidation\Schema\SchemaValid */ public function create(array $params) : array { - if (\array_key_exists(Hydrator\Operation\Pets::class, $this->hydrator) == false) { - $this->hydrator[Hydrator\Operation\Pets::class] = $this->hydrators->getObjectMapperOperation🌀Pets(); - } - $operator = new Operator\Pets\Create($this->browser, $this->authentication, $this->requestSchemaValidator, $this->responseSchemaValidator, $this->hydrator[Hydrator\Operation\Pets::class]); + $operator = new Operator\Pets\Create($this->browser, $this->authentication, $this->requestSchemaValidator, $this->responseSchemaValidator, $this->hydrators->getObjectMapperOperation🌀Pets()); return $operator->call($params); } }