Skip to content

Commit 55c41b8

Browse files
authored
Clean up remaining places without context (zircote#985)
This paves the way for retiring `Context::detect()`
1 parent 41b787b commit 55c41b8

14 files changed

+40
-38
lines changed

src/Context.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* @property string $interface
3939
* @property bool $static Indicate a static method
4040
* @property bool $nullable Indicate a nullable value
41-
* @property bool $generated Indicate the context was generated by a processor
41+
* @property bool $generated Indicate the context was generated by a processor or the serializer
4242
* @property Annotations\AbstractAnnotation $nested
4343
* @property Annotations\AbstractAnnotation[] $annotations
4444
* @property \Psr\Log\LoggerInterface $logger Guaranteed to be set when using the `Generator`

src/Processors/ExpandClasses.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __invoke(Analysis $analysis)
3232
$anchestorSchema = $analysis->getSchemaForSource($anchestor['context']->fullyQualifiedName($anchestor['class']));
3333
if ($anchestorSchema) {
3434
$refPath = $anchestorSchema->schema !== Generator::UNDEFINED ? $anchestorSchema->schema : $anchestor['class'];
35-
$this->inheritFrom($schema, $anchestorSchema, $refPath, $anchestor['context']->_context);
35+
$this->inheritFrom($schema, $anchestorSchema, $refPath, $anchestor['context']);
3636

3737
// one anchestor is enough
3838
break;

src/Processors/ExpandInterfaces.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __invoke(Analysis $analysis)
3232
$interfaceSchema = $analysis->getSchemaForSource($interface['context']->fullyQualifiedName($interface['interface']));
3333
if ($interfaceSchema) {
3434
$refPath = $interfaceSchema->schema !== Generator::UNDEFINED ? $interfaceSchema->schema : $interface['interface'];
35-
$this->inheritFrom($schema, $interfaceSchema, $refPath, $interface['context']->_context);
35+
$this->inheritFrom($schema, $interfaceSchema, $refPath, $interface['context']);
3636
} else {
3737
$this->mergeAnnotations($schema, $interface, $existing);
3838
$this->mergeMethods($schema, $interface, $existing);

src/Processors/ExpandTraits.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __invoke(Analysis $analysis)
3333
$traitSchema = $analysis->getSchemaForSource($trait['context']->fullyQualifiedName($trait['trait']));
3434
if ($traitSchema) {
3535
$refPath = $traitSchema->schema !== Generator::UNDEFINED ? $traitSchema->schema : $trait['trait'];
36-
$this->inheritFrom($schema, $traitSchema, $refPath, $trait['context']->_context);
36+
$this->inheritFrom($schema, $traitSchema, $refPath, $trait['context']);
3737
} else {
3838
if ($schema->_context->is('class')) {
3939
$this->mergeAnnotations($schema, $trait, $existing);

src/Processors/MergeIntoComponents.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use OpenApi\Analysis;
1010
use OpenApi\Annotations\Components;
11+
use OpenApi\Context;
1112
use OpenApi\Generator;
1213

1314
/**
@@ -19,7 +20,8 @@ public function __invoke(Analysis $analysis)
1920
{
2021
$components = $analysis->openapi->components;
2122
if ($components === Generator::UNDEFINED) {
22-
$components = new Components([]);
23+
$context = new Context([], $analysis->context);
24+
$components = new Components(['_context' => $context]);
2325
$components->_context->generated = true;
2426
}
2527

src/Serializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function deserializeFile(string $filename, string $className = OA\OpenApi
105105
*/
106106
protected function doDeserialize(\stdClass $c, string $class)
107107
{
108-
$annotation = new $class([]);
108+
$annotation = new $class(['_context' => new Context(['generated' => true])]);
109109
foreach ((array) $c as $property => $value) {
110110
if ($property === '$ref') {
111111
$property = 'ref';

tests/Annotations/OperationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function testSecuritySerialization($security, $dockBlock, $expected)
4545
// test with Get implementation...
4646
$operation = new OA\Get([
4747
'security' => $security,
48+
'_context' => $this->getContext(),
4849
]);
4950
$flags = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
5051
$json = $operation->toJson($flags);

tests/OpenApiTestCase.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,12 @@ protected function createOpenApiWithInfo()
167167
'info' => new Info([
168168
'title' => 'swagger-php Test-API',
169169
'version' => 'test',
170-
'_context' => $this->getContext(['unittest' => true]),
170+
'_context' => $this->getContext(),
171171
]),
172172
'paths' => [
173-
new PathItem(['path' => '/test']),
173+
new PathItem(['path' => '/test', '_context' => $this->getContext()]),
174174
],
175-
'_context' => $this->getContext(['unittest' => true]),
175+
'_context' => $this->getContext(),
176176
]);
177177
}
178178

tests/Processors/BuildPathsTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ class BuildPathsTest extends OpenApiTestCase
2020
{
2121
public function testMergePathsWithSamePath()
2222
{
23-
$openapi = new OpenApi([]);
23+
$openapi = new OpenApi(['_context' => $this->getContext()]);
2424
$openapi->paths = [
25-
new PathItem(['path' => '/comments']),
26-
new PathItem(['path' => '/comments']),
25+
new PathItem(['path' => '/comments', '_context' => $this->getContext()]),
26+
new PathItem(['path' => '/comments', '_context' => $this->getContext()]),
2727
];
2828
$analysis = new Analysis([$openapi], $this->getContext());
2929
$analysis->openapi = $openapi;
@@ -34,12 +34,12 @@ public function testMergePathsWithSamePath()
3434

3535
public function testMergeOperationsWithSamePath()
3636
{
37-
$openapi = new OpenApi([]);
37+
$openapi = new OpenApi(['_context' => $this->getContext()]);
3838
$analysis = new Analysis(
3939
[
4040
$openapi,
41-
new Get(['path' => '/comments']),
42-
new Post(['path' => '/comments']),
41+
new Get(['path' => '/comments', '_context' => $this->getContext()]),
42+
new Post(['path' => '/comments', '_context' => $this->getContext()]),
4343
],
4444
$this->getContext()
4545
);

tests/Processors/ExpandClassesTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class ExpandClassesTest extends OpenApiTestCase
2727
{
2828
protected function validate(Analysis $analysis)
2929
{
30-
$analysis->openapi->info = new Info(['title' => 'test', 'version' => '1.0.0']);
31-
$analysis->openapi->paths = [new PathItem(['path' => '/test'])];
30+
$analysis->openapi->info = new Info(['title' => 'test', 'version' => '1.0.0', '_context' => $this->getContext()]);
31+
$analysis->openapi->paths = [new PathItem(['path' => '/test', '_context' => $this->getContext()])];
3232
$analysis->validate();
3333
}
3434

@@ -244,8 +244,8 @@ public function testPreserveExistingAllOf()
244244
]);
245245
$this->validate($analysis);
246246

247-
$analysis->openapi->info = new Info(['title' => 'test', 'version' => '1.0.0']);
248-
$analysis->openapi->paths = [new PathItem(['path' => '/test'])];
247+
$analysis->openapi->info = new Info(['title' => 'test', 'version' => '1.0.0', '_context' => $this->getContext()]);
248+
$analysis->openapi->paths = [new PathItem(['path' => '/test', '_context' => $this->getContext()])];
249249
$analysis->validate();
250250

251251
/* @var Schema[] $schemas */

0 commit comments

Comments
 (0)