Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 9 additions & 57 deletions src/Generator/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
),
),
] : []),
],
),
Expand Down Expand Up @@ -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<class-string, \\' . ObjectMapper::class . '>',
' */',
]))),
)->addStmt(
$constructor,
);

Expand Down
12 changes: 6 additions & 6 deletions tests/app/etc/openapi-client-generator.state
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -284,7 +284,7 @@
},
{
"name": ".\/tests\/app\/src\/\/Router\/Get.php",
"hash": "64270922a47a8ea29f38370be61608bc"
"hash": "0c8b86bc66e7540692ee4266e1c2ea95"
}
]
},
Expand Down
9 changes: 1 addition & 8 deletions tests/app/src/Router/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
use ApiClients\Contracts;
final class Get
{
/**
* @var array<class-string, \EventSauce\ObjectHydrator\ObjectMapper>
*/
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)
{
}
Expand All @@ -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();
}
}
14 changes: 2 additions & 12 deletions tests/app/src/Router/Get/Pets.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
use ApiClients\Contracts;
final class Pets
{
/**
* @var array<class-string, \EventSauce\ObjectHydrator\ObjectMapper>
*/
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)
{
}
Expand All @@ -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']);
}
/**
Expand All @@ -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']);
}
}
9 changes: 1 addition & 8 deletions tests/app/src/Router/Get/PetsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
use ApiClients\Contracts;
final class PetsList
{
/**
* @var array<class-string, \EventSauce\ObjectHydrator\ObjectMapper>
*/
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)
{
}
Expand All @@ -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']);
}
}
14 changes: 2 additions & 12 deletions tests/app/src/Router/List/Pets.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
use ApiClients\Contracts;
final class Pets
{
/**
* @var array<class-string, \EventSauce\ObjectHydrator\ObjectMapper>
*/
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)
{
}
Expand All @@ -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']++;
Expand All @@ -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']++;
Expand Down
9 changes: 1 addition & 8 deletions tests/app/src/Router/List/PetsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
use ApiClients\Contracts;
final class PetsList
{
/**
* @var array<class-string, \EventSauce\ObjectHydrator\ObjectMapper>
*/
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)
{
}
Expand All @@ -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']++;
Expand Down
9 changes: 1 addition & 8 deletions tests/app/src/Router/Post/Pets.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
use ApiClients\Contracts;
final class Pets
{
/**
* @var array<class-string, \EventSauce\ObjectHydrator\ObjectMapper>
*/
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)
{
}
Expand All @@ -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);
}
}