mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
Revert "Use the same root context everywhere"
This reverts commit 5d747aefc33807fbb40a58178c277098fa74f3fe.
This commit is contained in:
parent
1ddd3f3214
commit
6cab5c59c3
@ -105,6 +105,7 @@ final class ApiDocGenerator
|
||||
|
||||
$describer->describe($this->openApi);
|
||||
}
|
||||
|
||||
$analysis = new Analysis([], $context);
|
||||
$analysis->addAnnotation($this->openApi, $context);
|
||||
|
||||
|
@ -68,7 +68,7 @@ final class ModelRegistry
|
||||
}
|
||||
|
||||
// Reserve the name
|
||||
$s = Util::getSchema($this->api, $this->names[$hash]);
|
||||
Util::getSchema($this->api, $this->names[$hash]);
|
||||
|
||||
return OA\Components::SCHEMA_REF.$this->names[$hash];
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ use Nelmio\ApiDocBundle\OpenApiPhp\Util;
|
||||
use Nelmio\ApiDocBundle\Util\SetsContextTrait;
|
||||
use OpenApi\Analysis;
|
||||
use OpenApi\Annotations as OA;
|
||||
use OpenApi\Context;
|
||||
use OpenApi\Generator;
|
||||
|
||||
/**
|
||||
@ -38,15 +39,11 @@ class OpenApiAnnotationsReader
|
||||
|
||||
public function updateSchema(\ReflectionClass $reflectionClass, OA\Schema $schema): void
|
||||
{
|
||||
$this->setContext(Util::createContext([], $schema->_context));
|
||||
|
||||
/** @var OA\Schema|null $oaSchema */
|
||||
if (!$oaSchema = $this->getAnnotation($reflectionClass, OA\Schema::class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->setContext(null);
|
||||
|
||||
// Read @Model annotations
|
||||
$this->modelRegister->__invoke(new Analysis([$oaSchema], Util::createContext()));
|
||||
|
||||
@ -72,12 +69,12 @@ class OpenApiAnnotationsReader
|
||||
// In order to have nicer errors
|
||||
$declaringClass = $reflection->getDeclaringClass();
|
||||
|
||||
$this->setContext(Util::createContext([
|
||||
$this->setContext(new Context([
|
||||
'namespace' => $declaringClass->getNamespaceName(),
|
||||
'class' => $declaringClass->getShortName(),
|
||||
'property' => $reflection->name,
|
||||
'filename' => $declaringClass->getFileName(),
|
||||
], $property->_context));
|
||||
]));
|
||||
|
||||
/** @var OA\Property|null $oaProperty */
|
||||
if (!$oaProperty = $this->getAnnotation($reflection, OA\Property::class)) {
|
||||
|
@ -13,7 +13,6 @@ namespace Nelmio\ApiDocBundle\ModelDescriber;
|
||||
|
||||
use Nelmio\ApiDocBundle\Model\Model;
|
||||
use Nelmio\ApiDocBundle\Model\ModelRegistry;
|
||||
use Nelmio\ApiDocBundle\OpenApiPhp\Util;
|
||||
use OpenApi\Annotations as OA;
|
||||
use Symfony\Component\PropertyInfo\Type;
|
||||
|
||||
@ -44,18 +43,18 @@ trait ApplyOpenApiDiscriminatorTrait
|
||||
array $typeMap
|
||||
): void {
|
||||
$schema->oneOf = [];
|
||||
$discriminator = Util::getChild($schema, OA\Discriminator::class);
|
||||
$discriminator->propertyName = $discriminatorProperty;
|
||||
$discriminator->mapping = [];
|
||||
$schema->discriminator = new OA\Discriminator([]);
|
||||
$schema->discriminator->propertyName = $discriminatorProperty;
|
||||
$schema->discriminator->mapping = [];
|
||||
foreach ($typeMap as $propertyValue => $className) {
|
||||
$oneOfSchema = Util::createChild($schema, OA\Schema::class);
|
||||
$oneOfSchema = new OA\Schema([]);
|
||||
$oneOfSchema->ref = $modelRegistry->register(new Model(
|
||||
new Type(Type::BUILTIN_TYPE_OBJECT, false, $className),
|
||||
$model->getGroups(),
|
||||
$model->getOptions()
|
||||
));
|
||||
$schema->oneOf[] = $oneOfSchema;
|
||||
$discriminator->mapping[$propertyValue] = $oneOfSchema->ref;
|
||||
$schema->discriminator->mapping[$propertyValue] = $oneOfSchema->ref;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ final class FormModelDescriber implements ModelDescriberInterface, ModelRegistry
|
||||
$ref = $this->modelRegistry->register($model);
|
||||
// We need to use allOf for description and title to be displayed
|
||||
if ($config->hasOption('documentation') && !empty($config->getOption('documentation'))) {
|
||||
$property->allOf = [Util::createChild($property, OA\Schema::class, ['ref' => $ref])];
|
||||
$property->allOf = [new OA\Schema(['ref' => $ref])];
|
||||
} else {
|
||||
$property->ref = $ref;
|
||||
}
|
||||
|
@ -292,7 +292,7 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
|
||||
if (empty($customFields)) { // no custom fields
|
||||
$property->ref = $modelRef;
|
||||
} else {
|
||||
$property->allOf = [Util::createChild($property, OA\Schema::class, ['ref' => $modelRef])];
|
||||
$property->allOf = [new OA\Schema(['ref' => $modelRef])];
|
||||
}
|
||||
|
||||
$this->contexts[$model->getHash()] = $context;
|
||||
|
@ -160,11 +160,11 @@ final class ModelRegister
|
||||
) {
|
||||
switch ($type) {
|
||||
case 'json':
|
||||
$modelAnnotation = Util::createChild($annotation, OA\JsonContent::class, $properties);
|
||||
$modelAnnotation = new OA\JsonContent($properties);
|
||||
|
||||
break;
|
||||
case 'xml':
|
||||
$modelAnnotation = Util::createChild($annotation, OA\XmlContent::class, $properties);
|
||||
$modelAnnotation = new OA\XmlContent($properties);
|
||||
|
||||
break;
|
||||
default:
|
||||
|
@ -84,7 +84,7 @@ final class Util
|
||||
public static function getSchema(OA\OpenApi $api, $schema): OA\Schema
|
||||
{
|
||||
if (!$api->components instanceof OA\Components) {
|
||||
$api->components = self::createChild($api, OA\Components::class, []);
|
||||
$api->components = new OA\Components([]);
|
||||
}
|
||||
|
||||
return self::getIndexedCollectionItem($api->components, OA\Schema::class, $schema);
|
||||
|
@ -14,7 +14,6 @@ namespace Nelmio\ApiDocBundle\PropertyDescriber;
|
||||
use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareInterface;
|
||||
use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareTrait;
|
||||
use Nelmio\ApiDocBundle\Model\Model;
|
||||
use Nelmio\ApiDocBundle\OpenApiPhp\Util;
|
||||
use OpenApi\Annotations as OA;
|
||||
use Symfony\Component\PropertyInfo\Type;
|
||||
|
||||
@ -38,7 +37,7 @@ class ObjectPropertyDescriber implements PropertyDescriberInterface, ModelRegist
|
||||
|
||||
if ($types[0]->isNullable()) {
|
||||
$property->nullable = true;
|
||||
$property->allOf = [Util::createChild($property, OA\Schema::class, ['ref' => $this->modelRegistry->register(new Model($type, $groups))])];
|
||||
$property->allOf = [new OA\Schema(['ref' => $this->modelRegistry->register(new Model($type, $groups))])];
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ final class FosRestDescriber implements RouteDescriberInterface
|
||||
throw new \InvalidArgumentException('Unsupported media type');
|
||||
}
|
||||
if (!isset($requestBody->content[$contentType])) {
|
||||
$requestBody->content[$contentType] = Util::createChild($requestBody, OA\MediaType::class,
|
||||
$requestBody->content[$contentType] = new OA\MediaType(
|
||||
[
|
||||
'mediaType' => $contentType,
|
||||
]
|
||||
|
@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the NelmioApiDocBundle package.
|
||||
*
|
||||
* (c) Nelmio
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Nelmio\ApiDocBundle\Tests\Functional;
|
||||
|
||||
use Nelmio\ApiDocBundle\OpenApiPhp\Util;
|
||||
use OpenApi\Analysis;
|
||||
|
||||
class SwaggerPHPApiComplianceTest extends WebTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
static::createClient([], ['HTTP_HOST' => 'api.example.com']);
|
||||
}
|
||||
|
||||
public function testAllContextsHaveSameRoot()
|
||||
{
|
||||
$openApi = $this->getOpenApiDefinition();
|
||||
$root = $openApi->_context;
|
||||
|
||||
$counter = 0;
|
||||
foreach ((new Analysis([$openApi], Util::createContext()))->annotations as $annotation) {
|
||||
$this->assertSame($annotation->_context->root(), $root);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user