Skip to content

Commit 723d32f

Browse files
authored
Merge pull request #144 from php-api-clients/store-state-cache-file-to-prevent-unesecary-file-overwriting-and-spec-generating
Store state cache to prevent unnecessary file overwriting with the same contents
2 parents 7c47421 + a7c87c3 commit 723d32f

File tree

11 files changed

+300
-192
lines changed

11 files changed

+300
-192
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ else
2121
-v "`pwd`:`pwd`" \
2222
-v "${COMPOSER_CACHE_DIR}:/home/app/.composer/cache" \
2323
-w "`pwd`" \
24+
-e "FORCE_GENERATION=$$FORCE_GENERATION" \
2425
"wyrihaximusnet/php:8.2-nts-alpine-slim-dev"
2526
endif
2627

bin/openapi-client-generator.source

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ use Symfony\Component\Yaml\Yaml;
2020
exit((function (string $configurationFile): int {
2121
$configuration = (new ObjectMapperUsingReflection())->hydrateObject(Configuration::class, Yaml::parseFile($configurationFile));
2222
(new Generator(
23-
$configuration->spec
23+
$configuration,
24+
dirname($configurationFile) . DIRECTORY_SEPARATOR,
2425
))->generate(
2526
$configuration->namespace->source . '\\',
2627
$configuration->namespace->test . '\\',
2728
dirname($configurationFile) . DIRECTORY_SEPARATOR,
28-
$configuration,
2929
);
3030

3131
return 0;

example/openapi-client-one.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
state:
2+
file: etc/openapi-client-generator.state
3+
additionalFiles:
4+
- composer.json
5+
- composer.lock
16
spec: https://raw.githubusercontent.com/github/rest-api-description/main/descriptions-next/api.github.com/api.github.com.yaml
27
#spec: file:///home/wyrihaximus/Projects/PHPAPIClients/openapi-client-generator/example/api.github.com.yaml
38
namespace:

example/openapi-client-subsplit.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
state:
2+
file: etc/openapi-client-generator.state
3+
additionalFiles:
4+
- composer.json
5+
- composer.lock
16
spec: https://raw.githubusercontent.com/github/rest-api-description/main/descriptions-next/api.github.com/api.github.com.yaml
27
#spec: file:///home/wyrihaximus/Projects/PHPAPIClients/openapi-client-generator/example/api.github.com.yaml
38
namespace:

src/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* @param array<class-string<ContentType>>|null $contentType
1818
*/
1919
public function __construct(
20+
public \ApiClients\Tools\OpenApiClientGenerator\Configuration\State $state,
2021
public string $spec,
2122
public Templates $templates,
2223
public Namespace_ $namespace,

src/Configuration/State.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace ApiClients\Tools\OpenApiClientGenerator\Configuration;
4+
5+
use EventSauce\ObjectHydrator\MapFrom;
6+
use EventSauce\ObjectHydrator\PropertyCasters\CastListToType;
7+
8+
final readonly class State
9+
{
10+
/**
11+
* @param array<string> $additionalFiles
12+
*/
13+
public function __construct(
14+
public string $file,
15+
#[MapFrom('additionalFiles')]
16+
#[CastListToType('string')]
17+
public ?array $additionalFiles,
18+
) {
19+
}
20+
}

src/Files.php

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)