Skip to content

Commit 267f45f

Browse files
authored
Merge pull request #149 from php-api-clients/make-entry-points-toggleable
Make entry points toggleable
2 parents e2efe44 + ca6584f commit 267f45f

15 files changed

+1247
-506
lines changed

example/openapi-client-one.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ state:
55
- composer.lock
66
spec: https://raw.githubusercontent.com/github/rest-api-description/main/descriptions-next/api.github.com/api.github.com.yaml
77
#spec: file:///home/wyrihaximus/Projects/PHPAPIClients/openapi-client-generator/example/api.github.com.yaml
8+
entryPoints:
9+
call: true
10+
operations: true
11+
webHooks: true
812
namespace:
913
source: ApiClients\Client\Github
1014
test: ApiClients\Tests\Client\Github

example/openapi-client-subsplit.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ state:
55
- composer.lock
66
spec: https://raw.githubusercontent.com/github/rest-api-description/main/descriptions-next/api.github.com/api.github.com.yaml
77
#spec: file:///home/wyrihaximus/Projects/PHPAPIClients/openapi-client-generator/example/api.github.com.yaml
8+
entryPoints:
9+
call: true
10+
operations: true
11+
webHooks: true
812
namespace:
913
source: ApiClients\Client\Github
1014
test: ApiClients\Tests\Client\Github

src/Configuration.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace ApiClients\Tools\OpenApiClientGenerator;
66

77
use ApiClients\Tools\OpenApiClientGenerator\Configuration\Destination;
8+
use ApiClients\Tools\OpenApiClientGenerator\Configuration\EntryPoints;
89
use ApiClients\Tools\OpenApiClientGenerator\Configuration\Namespace_;
910
use ApiClients\Tools\OpenApiClientGenerator\Configuration\Schemas;
1011
use ApiClients\Tools\OpenApiClientGenerator\Configuration\State;
@@ -22,6 +23,8 @@
2223
public function __construct(
2324
public State $state,
2425
public string $spec,
26+
#[MapFrom('entryPoints')]
27+
public EntryPoints $entryPoints,
2528
public Templates $templates,
2629
public Namespace_ $namespace,
2730
public Destination $destination,

src/Configuration/EntryPoints.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ApiClients\Tools\OpenApiClientGenerator\Configuration;
6+
7+
use EventSauce\ObjectHydrator\MapFrom;
8+
9+
final readonly class EntryPoints
10+
{
11+
public function __construct(
12+
public bool $call,
13+
#[MapFrom('operations')]
14+
public bool $operations,
15+
#[MapFrom('webHooks')]
16+
public bool $webHooks,
17+
) {
18+
}
19+
}

src/Generator.php

Lines changed: 67 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
use ApiClients\Tools\OpenApiClientGenerator\Generator\Hydrator;
1414
use ApiClients\Tools\OpenApiClientGenerator\Generator\Hydrators;
1515
use ApiClients\Tools\OpenApiClientGenerator\Generator\Operation;
16+
use ApiClients\Tools\OpenApiClientGenerator\Generator\Operations;
17+
use ApiClients\Tools\OpenApiClientGenerator\Generator\OperationsInterface;
1618
use ApiClients\Tools\OpenApiClientGenerator\Generator\OperationTest;
19+
use ApiClients\Tools\OpenApiClientGenerator\Generator\Operator;
1720
use ApiClients\Tools\OpenApiClientGenerator\Generator\Schema;
1821
use ApiClients\Tools\OpenApiClientGenerator\Generator\WebHook;
1922
use ApiClients\Tools\OpenApiClientGenerator\Generator\WebHooks;
@@ -86,6 +89,8 @@ public function __construct(
8689
new Step('generating_schemas', 'Generating: Schemas', true),
8790
new Step('generating_clientinterface', 'Generating: ClientInterface', false),
8891
new Step('generating_client', 'Generating: Client', false),
92+
new Step('generating_operationsinterface_entry_point', 'Generating: OperationsInterface Entry Point', false),
93+
new Step('generating_operations_entry_point', 'Generating: Operations Entry Point', false),
8994
new Step('generating_webhooks', 'Generating: WebHooks', true),
9095
new Step('generating_webhooks_entry_point', 'Generating: WebHooks Entry Point', false),
9196
new Step('generating_hydrators', 'Generating: Hydrators', true),
@@ -128,8 +133,6 @@ public function __construct(
128133
(static function (string $root, Files $files, string ...$additionalFiles): bool {
129134
foreach ($additionalFiles as $additionalFile) {
130135
if ($files->has($additionalFile) && (! file_exists($root . $additionalFile) || $files->get($additionalFile)->hash !== md5(file_get_contents($root . $additionalFile)))) {
131-
echo $additionalFile, PHP_EOL;
132-
133136
return false;
134137
}
135138
}
@@ -176,6 +179,7 @@ public function generate(string $namespace, string $namespaceTest, string $confi
176179
'Error' => 'ErrorSchemas',
177180
'Hydrator' => null,
178181
'Operation' => null,
182+
'Operator' => null,
179183
'Schema' => null,
180184
'WebHook' => null,
181185
'Router' => null,
@@ -192,7 +196,7 @@ public function generate(string $namespace, string $namespaceTest, string $confi
192196
$fileContentsHash = md5($fileContents);
193197
if (
194198
! $this->state->generatedFiles->has($fileName) ||
195-
$this->state->generatedFiles->get($fileName)->hash === $fileContentsHash
199+
$this->state->generatedFiles->get($fileName)->hash !== $fileContentsHash
196200
) {
197201
@mkdir(dirname($fileName), 0744, true);
198202
file_put_contents($fileName, $fileContents);
@@ -207,7 +211,6 @@ public function generate(string $namespace, string $namespaceTest, string $confi
207211
}
208212

209213
foreach ($existingFiles as $existingFile) {
210-
echo $existingFile, PHP_EOL;
211214
$this->state->generatedFiles->remove($existingFile);
212215
unlink($existingFile);
213216
}
@@ -253,7 +256,6 @@ private function all(string $namespace, string $namespaceTest, string $configura
253256
$this->statusOutput->advanceStep('gathering_schemas');
254257
}
255258
}
256-
257259
$this->statusOutput->markStepDone('gathering_schemas');
258260

259261
$webHooks = [];
@@ -269,7 +271,6 @@ private function all(string $namespace, string $namespaceTest, string $configura
269271
$this->statusOutput->advanceStep('gathering_webhooks');
270272
}
271273
}
272-
273274
$this->statusOutput->markStepDone('gathering_webhooks');
274275

275276
$paths = [];
@@ -334,6 +335,15 @@ private function oneClient(string $namespace, string $namespaceTest, string $con
334335
$this->configuration,
335336
);
336337

338+
yield from Operator::generate(
339+
$this->configuration->destination->source . DIRECTORY_SEPARATOR,
340+
$namespace,
341+
$operation,
342+
$path->hydrator,
343+
$throwableSchemaRegistry,
344+
$this->configuration,
345+
);
346+
337347
yield from OperationTest::generate(
338348
$this->configuration->destination->test . DIRECTORY_SEPARATOR,
339349
$namespaceTest,
@@ -347,7 +357,6 @@ private function oneClient(string $namespace, string $namespaceTest, string $con
347357

348358
$this->statusOutput->advanceStep('generating_operations');
349359
}
350-
351360
$this->statusOutput->markStepDone('generating_operations');
352361

353362
$unknownSchemaCount = 0;
@@ -360,7 +369,6 @@ private function oneClient(string $namespace, string $namespaceTest, string $con
360369
$this->statusOutput->advanceStep('gathering_unknown_schemas');
361370
}
362371
}
363-
364372
$this->statusOutput->markStepDone('gathering_unknown_schemas');
365373

366374
$this->statusOutput->itemForStep('generating_schemas', count($schemas));
@@ -382,25 +390,43 @@ private function oneClient(string $namespace, string $namespaceTest, string $con
382390

383391
$this->statusOutput->advanceStep('generating_schemas');
384392
}
385-
386393
$this->statusOutput->markStepDone('generating_schemas');
387394

388395
$client = \ApiClients\Tools\OpenApiClientGenerator\Gatherer\Client::gather($this->spec, ...$paths);
396+
$routers = new Client\Routers();
389397

390398
$this->statusOutput->markStepDone('generating_clientinterface');
391-
392399
yield from ClientInterface::generate(
400+
$this->configuration,
393401
$this->configuration->destination->source . DIRECTORY_SEPARATOR,
394402
$namespace,
395403
$operations,
396404
);
397405

398406
$this->statusOutput->markStepDone('generating_client');
399-
400407
yield from Client::generate(
408+
$this->configuration,
401409
$this->configuration->destination->source . DIRECTORY_SEPARATOR,
402410
$namespace,
403411
$client,
412+
$routers,
413+
);
414+
415+
$this->statusOutput->markStepDone('generating_operationsinterface_entry_point');
416+
yield from OperationsInterface::generate(
417+
$this->configuration,
418+
$this->configuration->destination->source . DIRECTORY_SEPARATOR,
419+
$namespace,
420+
$operations,
421+
);
422+
423+
$this->statusOutput->markStepDone('generating_operations_entry_point');
424+
yield from Operations::generate(
425+
$this->configuration,
426+
$this->configuration->destination->source . DIRECTORY_SEPARATOR,
427+
$namespace,
428+
$operations,
429+
$routers,
404430
);
405431

406432
$webHooksHydrators = [];
@@ -421,11 +447,9 @@ private function oneClient(string $namespace, string $namespaceTest, string $con
421447

422448
$this->statusOutput->advanceStep('generating_webhooks');
423449
}
424-
425450
$this->statusOutput->markStepDone('generating_webhooks');
426451

427452
$this->statusOutput->markStepDone('generating_webhooks_entry_point');
428-
429453
yield from WebHooks::generate($this->configuration->destination->source . DIRECTORY_SEPARATOR, $namespace, $webHooksHydrators, $webHooks);
430454

431455
$this->statusOutput->itemForStep('generating_hydrators', count($hydrators));
@@ -434,11 +458,9 @@ private function oneClient(string $namespace, string $namespaceTest, string $con
434458

435459
$this->statusOutput->advanceStep('generating_hydrators');
436460
}
437-
438461
$this->statusOutput->markStepDone('generating_hydrators');
439462

440463
$this->statusOutput->markStepDone('generating_hydrators_entry_point');
441-
442464
yield from Hydrators::generate($this->configuration->destination->source . DIRECTORY_SEPARATOR, $namespace, ...$hydrators);
443465

444466
$this->statusOutput->markStepDone('generating_templated_files');
@@ -485,6 +507,15 @@ private function subSplitClient(string $namespace, string $namespaceTest, string
485507
$this->configuration,
486508
);
487509

510+
yield from Operator::generate(
511+
$this->configuration->subSplit->subSplitsDestination . DIRECTORY_SEPARATOR . $this->splitPathPrefix($this->configuration->subSplit->sectionPackage, $split) . $this->configuration->destination->source,
512+
$namespace,
513+
$operation,
514+
$path->hydrator,
515+
$throwableSchemaRegistry,
516+
$this->configuration,
517+
);
518+
488519
yield from OperationTest::generate(
489520
$this->configuration->subSplit->subSplitsDestination . DIRECTORY_SEPARATOR . $this->splitPathPrefix($this->configuration->subSplit->sectionPackage, $split) . $this->configuration->destination->test,
490521
$namespaceTest,
@@ -498,7 +529,6 @@ private function subSplitClient(string $namespace, string $namespaceTest, string
498529

499530
$this->statusOutput->advanceStep('generating_operations');
500531
}
501-
502532
$this->statusOutput->markStepDone('generating_operations');
503533

504534
$webHooksHydrators = [];
@@ -527,7 +557,6 @@ private function subSplitClient(string $namespace, string $namespaceTest, string
527557
$this->statusOutput->advanceStep('gathering_unknown_schemas');
528558
}
529559
}
530-
531560
$this->statusOutput->markStepDone('gathering_unknown_schemas');
532561

533562
$sortedSchemas = [];
@@ -594,25 +623,43 @@ private function subSplitClient(string $namespace, string $namespaceTest, string
594623

595624
$this->statusOutput->advanceStep('generating_schemas');
596625
}
597-
598626
$this->statusOutput->markStepDone('generating_schemas');
599627

600628
$client = \ApiClients\Tools\OpenApiClientGenerator\Gatherer\Client::gather($this->spec, ...$paths);
629+
$routers = new Client\Routers();
601630

602631
$this->statusOutput->markStepDone('generating_clientinterface');
603-
604632
yield from ClientInterface::generate(
633+
$this->configuration,
605634
$this->configuration->subSplit->subSplitsDestination . DIRECTORY_SEPARATOR . $this->splitPathPrefix($this->configuration->subSplit->rootPackage, '') . $this->configuration->destination->source,
606635
$namespace,
607636
$operations,
608637
);
609638

610639
$this->statusOutput->markStepDone('generating_client');
611-
612640
yield from Client::generate(
641+
$this->configuration,
613642
$this->configuration->subSplit->subSplitsDestination . DIRECTORY_SEPARATOR . $this->splitPathPrefix($this->configuration->subSplit->rootPackage, '') . $this->configuration->destination->source,
614643
$namespace,
615644
$client,
645+
$routers,
646+
);
647+
648+
$this->statusOutput->markStepDone('generating_operationsinterface_entry_point');
649+
yield from OperationsInterface::generate(
650+
$this->configuration,
651+
$this->configuration->subSplit->subSplitsDestination . DIRECTORY_SEPARATOR . $this->splitPathPrefix($this->configuration->subSplit->rootPackage, '') . $this->configuration->destination->source,
652+
$namespace,
653+
$operations,
654+
);
655+
656+
$this->statusOutput->markStepDone('generating_operations_entry_point');
657+
yield from Operations::generate(
658+
$this->configuration,
659+
$this->configuration->subSplit->subSplitsDestination . DIRECTORY_SEPARATOR . $this->splitPathPrefix($this->configuration->subSplit->rootPackage, '') . $this->configuration->destination->source,
660+
$namespace,
661+
$operations,
662+
$routers,
616663
);
617664

618665
$this->statusOutput->itemForStep('generating_webhooks', count($webHooks));
@@ -636,11 +683,9 @@ private function subSplitClient(string $namespace, string $namespaceTest, string
636683

637684
$this->statusOutput->advanceStep('generating_webhooks');
638685
}
639-
640686
$this->statusOutput->markStepDone('generating_webhooks');
641687

642688
$this->statusOutput->markStepDone('generating_webhooks_entry_point');
643-
644689
yield from WebHooks::generate(
645690
$this->configuration->subSplit->subSplitsDestination . DIRECTORY_SEPARATOR . $this->splitPathPrefix($this->configuration->subSplit->rootPackage, '') . $this->configuration->destination->source,
646691
$namespace,
@@ -660,11 +705,9 @@ private function subSplitClient(string $namespace, string $namespaceTest, string
660705

661706
$this->statusOutput->advanceStep('generating_hydrators');
662707
}
663-
664708
$this->statusOutput->markStepDone('generating_hydrators');
665709

666710
$this->statusOutput->markStepDone('generating_hydrators_entry_point');
667-
668711
yield from Hydrators::generate(
669712
$this->configuration->subSplit->subSplitsDestination . DIRECTORY_SEPARATOR . $this->splitPathPrefix($this->configuration->subSplit->rootPackage, '') . $this->configuration->destination->source,
670713
$namespace,
@@ -765,7 +808,6 @@ private function subSplitClient(string $namespace, string $namespaceTest, string
765808
);
766809
$this->statusOutput->advanceStep('generating_templates_files_subsplit_package');
767810
}
768-
769811
$this->statusOutput->markStepDone('generating_templates_files_subsplit_package');
770812

771813
$this->statusOutput->markStepDone('generating_subsplit_configuration');

0 commit comments

Comments
 (0)