Always provide a context to swagger-php (#1860)

The next swagger-php release will make `context` a required parameter
for `Analysis` and adding annotations to it.
This commit is contained in:
Martin Rademacher 2021-08-18 07:52:21 +12:00 committed by GitHub
parent 985b43fb60
commit 74a440a2b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 5 deletions

View File

@ -17,6 +17,7 @@ use Nelmio\ApiDocBundle\Model\ModelRegistry;
use Nelmio\ApiDocBundle\ModelDescriber\ModelDescriberInterface;
use Nelmio\ApiDocBundle\OpenApiPhp\DefaultOperationId;
use Nelmio\ApiDocBundle\OpenApiPhp\ModelRegister;
use Nelmio\ApiDocBundle\OpenApiPhp\Util;
use OpenApi\Analysis;
use OpenApi\Annotations\OpenApi;
use Psr\Cache\CacheItemPoolInterface;
@ -95,8 +96,9 @@ final class ApiDocGenerator
$describer->describe($this->openApi);
}
$analysis = new Analysis();
$analysis->addAnnotation($this->openApi, null);
$context = Util::createContext();
$analysis = new Analysis([], $context);
$analysis->addAnnotation($this->openApi, $context);
// Register model annotations
$modelRegister = new ModelRegister($modelRegistry, $this->mediaTypes);

View File

@ -14,6 +14,7 @@ namespace Nelmio\ApiDocBundle\ModelDescriber\Annotations;
use Doctrine\Common\Annotations\Reader;
use Nelmio\ApiDocBundle\Model\ModelRegistry;
use Nelmio\ApiDocBundle\OpenApiPhp\ModelRegister;
use Nelmio\ApiDocBundle\OpenApiPhp\Util;
use OpenApi\Analyser;
use OpenApi\Analysis;
use OpenApi\Annotations as OA;
@ -41,7 +42,7 @@ class OpenApiAnnotationsReader
}
// Read @Model annotations
$this->modelRegister->__invoke(new Analysis([$oaSchema]));
$this->modelRegister->__invoke(new Analysis([$oaSchema], Util::createContext()));
if (!$oaSchema->validate()) {
return;
@ -82,7 +83,7 @@ class OpenApiAnnotationsReader
Analyser::$context = null;
// Read @Model annotations
$this->modelRegister->__invoke(new Analysis([$oaProperty]), $serializationGroups);
$this->modelRegister->__invoke(new Analysis([$oaProperty], Util::createContext()), $serializationGroups);
if (!$oaProperty->validate()) {
return;

View File

@ -166,6 +166,6 @@ final class ModelRegister
}
$annotation->merge([$modelAnnotation]);
$analysis->addAnnotation($modelAnnotation, null);
$analysis->addAnnotation($modelAnnotation, $properties['_context']);
}
}