Skip to content

Commit

Permalink
fixed transformers configuration leaking between versions (#706)
Browse files Browse the repository at this point in the history
  • Loading branch information
romalytvynenko authored Feb 5, 2025
1 parent 9482d3c commit 1459e8c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Configuration/GeneratorConfigCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public function register(string $name, array $config): GeneratorConfig
{
$this->apis[$name] = $generatorConfig = new GeneratorConfig(
config: array_merge(config('scramble') ?: [], $config),
parametersExtractors: $this->apis[Scramble::DEFAULT_API]->parametersExtractors,
operationTransformers: $this->apis[Scramble::DEFAULT_API]->operationTransformers,
documentTransformers: $this->apis[Scramble::DEFAULT_API]->documentTransformers,
serverVariables: $this->apis[Scramble::DEFAULT_API]->serverVariables,
parametersExtractors: clone $this->apis[Scramble::DEFAULT_API]->parametersExtractors,
operationTransformers: clone $this->apis[Scramble::DEFAULT_API]->operationTransformers,
documentTransformers: clone $this->apis[Scramble::DEFAULT_API]->documentTransformers,
serverVariables: clone $this->apis[Scramble::DEFAULT_API]->serverVariables,
);

return $generatorConfig;
Expand Down
23 changes: 23 additions & 0 deletions tests/GeneratorConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ public function registered_api_exposed_explicitly()
collect($routes->getRoutes())->firstWhere('uri', 'docs/v2/openapi.json')
);
}

/** @test */
#[WithProviders([UsesCommonConfiguration_GeneratorConfigTest::class])]
public function uses_common_configurations()
{
$defaultConfig = Scramble::getConfigurationsInstance()->get('default');
$v2Config = Scramble::getConfigurationsInstance()->get('v2');

$this->assertEquals(['common', 'only-default'], $defaultConfig->documentTransformers->all());
$this->assertEquals(['common', 'only-v2'], $v2Config->documentTransformers->all());
}
}

class DisablesExposedRoutes_GeneratorConfigTest extends ServiceProvider
Expand Down Expand Up @@ -147,6 +158,18 @@ public function boot()
}
}

class UsesCommonConfiguration_GeneratorConfigTest extends ServiceProvider
{
public function boot()
{
Scramble::configure()->withDocumentTransformers('common');

Scramble::registerApi('v2')->withDocumentTransformers('only-v2');

Scramble::configure()->withDocumentTransformers('only-default');
}
}

#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class WithProviders implements Invokable
{
Expand Down

0 comments on commit 1459e8c

Please sign in to comment.