Skip to content

Commit

Permalink
Change cache key
Browse files Browse the repository at this point in the history
  • Loading branch information
msmakouz committed Dec 8, 2023
1 parent 985d2b7 commit dadfb10
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ return [
'exclude' => null,
'pattern' => null,
'version' => null,
'cache_item_id' => SwaggerConfig::DEFAULT_CACHE_ITEM_ID,
'cache_key' => SwaggerConfig::DEFAULT_CACHE_KEY,
'generator_config' => [
'operationId' => [
'hash' => true,
Expand Down
4 changes: 2 additions & 2 deletions src/Bootloader/SwaggerBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private function initConfig(DebugMode $debugMode, DirectoriesInterface $dirs): v
'exclude' => null,
'pattern' => null,
'version' => null,
'cache_item_id' => SwaggerConfig::DEFAULT_CACHE_ITEM_ID,
'cache_key' => SwaggerConfig::DEFAULT_CACHE_KEY,
'generator_config' => [
'operationId' => [
'hash' => true,
Expand Down Expand Up @@ -150,7 +150,7 @@ private function initGenerator(
CacheInterface $cache,
SwaggerConfig $config
): GeneratorInterface {
return new Generator($registry, $config->getCacheItemId(), $config->useCache() ? $cache : null);
return new Generator($registry, $config->getCacheKey(), $config->useCache() ? $cache : null);
}

private function initOpenApiParser(SwaggerConfig $config): OpenApiParser
Expand Down
8 changes: 4 additions & 4 deletions src/Config/SwaggerConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
final class SwaggerConfig extends InjectableConfig
{
public const CONFIG = 'swagger';
public const DEFAULT_CACHE_ITEM_ID = 'cache_item_id';
public const DEFAULT_CACHE_KEY = 'swagger_docs';

protected array $config = [
'documentation' => [
Expand All @@ -28,7 +28,7 @@ final class SwaggerConfig extends InjectableConfig
'exclude' => null,
'pattern' => null,
'version' => null,
'cache_item_id' => self::DEFAULT_CACHE_ITEM_ID,
'cache_key' => self::DEFAULT_CACHE_KEY,
'generator_config' => [
'operationId' => [
'hash' => true,
Expand Down Expand Up @@ -85,9 +85,9 @@ public function getPattern(): ?string
/**
* @psalm-return non-empty-string
*/
public function getCacheItemId(): string
public function getCacheKey(): string
{
return $this->config['cache_item_id'] ?? self::DEFAULT_CACHE_ITEM_ID;
return $this->config['cache_key'] ?? self::DEFAULT_CACHE_KEY;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Generator/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
final class Generator implements GeneratorInterface
{
/**
* @psalm-param non-empty-string $cacheItemId
* @psalm-param non-empty-string $cacheKey
*/
public function __construct(
private readonly ParserRegistryInterface $parsers,
private readonly string $cacheItemId,
private readonly string $cacheKey,
private readonly ?CacheInterface $cache = null,
) {
}
Expand All @@ -28,7 +28,7 @@ public function __construct(
*/
public function generate(): OpenApi
{
$item = $this->cache?->get($this->cacheItemId);
$item = $this->cache?->get($this->cacheKey);
if (null !== $item) {
return $item;
}
Expand All @@ -43,7 +43,7 @@ public function generate(): OpenApi
$parser->parse($openApi, $analysis);
}

$this->cache?->set($this->cacheItemId, $openApi);
$this->cache?->set($this->cacheKey, $openApi);

return $openApi;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/Merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function merge(
private static function mergeFromArray(AbstractAnnotation $annotation, array $properties, bool $overwrite): void
{
$done = [];
$defaults = get_class_vars(\get_class($annotation));
$defaults = get_class_vars($annotation::class);

foreach ($annotation::$_nested as $className => $propertyName) {
if (\is_string($propertyName)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Functional/Bootloader/SwaggerBootloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function testDefaultConfigShouldBeDefined(): void
'exclude' => null,
'pattern' => null,
'version' => null,
'cache_item_id' => SwaggerConfig::DEFAULT_CACHE_ITEM_ID,
'cache_key' => SwaggerConfig::DEFAULT_CACHE_KEY,
'generator_config' => [
'operationId' => [
'hash' => true,
Expand Down
6 changes: 3 additions & 3 deletions tests/src/Unit/Config/SwaggerConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ public function testGetPattern(): void
$this->assertSame('foo', $config->getPattern());
}

public function testGetCacheItemId(): void
public function testGetCacheKey(): void
{
$config = new SwaggerConfig(['cache_item_id' => 'some']);
$config = new SwaggerConfig(['cache_key' => 'some']);

$this->assertSame('some', $config->getCacheItemId());
$this->assertSame('some', $config->getCacheKey());
}

public function testGetVersion(): void
Expand Down

0 comments on commit dadfb10

Please sign in to comment.