Skip to content

Commit 8e0b758

Browse files
authored
Merge pull request #94 from php-api-clients/look-up-nested-schemas-in-webhooks
Look up nested schemas in webhooks
2 parents 1d94df4 + 69c3af1 commit 8e0b758

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/Gatherer/WebHookHydrator.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ public static function gather(
2121

2222
$schemaClasses = [];
2323
foreach ($webHooks as $webHook) {
24-
foreach ($webHook->schema as $schema) {
25-
$schemaClasses[] = $schema;
24+
foreach ($webHook->schema as $webHookSchema) {
25+
foreach (self::listSchemas($webHookSchema) as $schema) {
26+
$schemaClasses[] = $schema;
27+
}
2628
}
2729
}
2830

@@ -31,4 +33,19 @@ public static function gather(
3133
...$schemaClasses,
3234
);
3335
}
36+
37+
/**
38+
* @return iterable<\ApiClients\Tools\OpenApiClientGenerator\Representation\Schema>
39+
*/
40+
private static function listSchemas(\ApiClients\Tools\OpenApiClientGenerator\Representation\Schema $schema): iterable
41+
{
42+
foreach ($schema->properties as $property) {
43+
foreach ($property->type as $propertyType) {
44+
if ($propertyType->payload instanceof \ApiClients\Tools\OpenApiClientGenerator\Representation\Schema) {
45+
yield $propertyType->payload;
46+
yield from self::listSchemas($propertyType->payload);
47+
}
48+
}
49+
}
50+
}
3451
}

src/Generator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,28 @@ public function generate(string $namespace, string $destinationPath)
4141
new Node\Stmt\Use_([
4242
new Node\Stmt\UseUse(
4343
new Node\Name(
44-
$namespace . 'Hydrator',
44+
ltrim($namespace, '\\') . 'Hydrator',
4545
)
4646
)
4747
]),
4848
new Node\Stmt\Use_([
4949
new Node\Stmt\UseUse(
5050
new Node\Name(
51-
$namespace . 'Operation',
51+
ltrim($namespace, '\\') . 'Operation',
5252
)
5353
)
5454
]),
5555
new Node\Stmt\Use_([
5656
new Node\Stmt\UseUse(
5757
new Node\Name(
58-
$namespace . 'Schema',
58+
ltrim($namespace, '\\') . 'Schema',
5959
)
6060
)
6161
]),
6262
new Node\Stmt\Use_([
6363
new Node\Stmt\UseUse(
6464
new Node\Name(
65-
$namespace . 'WebHook',
65+
ltrim($namespace, '\\') . 'WebHook',
6666
)
6767
)
6868
]),

0 commit comments

Comments
 (0)