mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-09 02:59:27 +03:00
Fix ServerVariable management (#1694)
* Fix ServerVariable management * Fix cs * Apply StyleCI fixes
This commit is contained in:
parent
23fdbf0412
commit
eeb4a8b90e
@ -27,8 +27,6 @@ class DumpCommand extends Command
|
||||
|
||||
/**
|
||||
* DumpCommand constructor.
|
||||
*
|
||||
* @param ContainerInterface $generatorLocator
|
||||
*/
|
||||
public function __construct(ContainerInterface $generatorLocator)
|
||||
{
|
||||
@ -50,9 +48,6 @@ class DumpCommand extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
*
|
||||
* @throws InvalidArgumentException If the area to dump is not valid
|
||||
*
|
||||
* @return int|void
|
||||
|
@ -85,7 +85,7 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar
|
||||
$serializedName = $annotationsReader->getPropertyName($reflection, $serializedName);
|
||||
}
|
||||
|
||||
$property = Util::getProperty($schema, $annotationsReader->getPropertyName($reflection, $serializedName));
|
||||
$property = Util::getProperty($schema, $annotationsReader->getPropertyName($reflection, $serializedName));
|
||||
|
||||
// Interpret additional options
|
||||
$groups = $model->getGroups();
|
||||
|
@ -54,7 +54,7 @@ final class ModelRegister
|
||||
|
||||
// Misusage of ::$ref
|
||||
if (($annotation instanceof OA\Response || $annotation instanceof OA\RequestBody) && $annotation->ref instanceof ModelAnnotation) {
|
||||
throw new \InvalidArgumentException(sprintf('Using @Model inside @%s::$ref is not allowed. You should use ::$ref with @Property, @Parameter, @Schema, @Items but within @Response or @RequestBody you should put @Model directly at the root of the annotation : `@Response(..., @Model(...))`.', get_class($annotation)));
|
||||
throw new \InvalidArgumentException(sprintf('Using @Model inside @%s::$ref is not allowed. You should use ::$ref with @Property, @Parameter, @Schema, @Items but within @Response or @RequestBody you should put @Model directly at the root of the annotation : `@Response(..., @Model(...))`.', get_class($annotation)));
|
||||
}
|
||||
|
||||
// Implicit usages
|
||||
|
@ -65,10 +65,7 @@ final class Util
|
||||
* @see OA\OpenApi::$paths
|
||||
* @see OA\PathItem::path
|
||||
*
|
||||
* @param OA\OpenApi $api
|
||||
* @param string $path
|
||||
*
|
||||
* @return OA\PathItem
|
||||
* @param string $path
|
||||
*/
|
||||
public static function getPath(OA\OpenApi $api, $path): OA\PathItem
|
||||
{
|
||||
@ -79,10 +76,7 @@ final class Util
|
||||
* Return an existing Schema object from $api->components->schemas[] having its member schema set to $schema.
|
||||
* Create, add to $api->components->schemas[] and return this new Schema object and set the property if none found.
|
||||
*
|
||||
* @param OA\OpenApi $api
|
||||
* @param string $schema
|
||||
*
|
||||
* @return OA\Schema
|
||||
* @param string $schema
|
||||
*
|
||||
* @see OA\Schema::$schema
|
||||
* @see OA\Components::$schemas
|
||||
@ -106,10 +100,7 @@ final class Util
|
||||
* @see OA\Schema::$properties
|
||||
* @see OA\Property::$property
|
||||
*
|
||||
* @param OA\Schema $schema
|
||||
* @param string $property
|
||||
*
|
||||
* @return OA\Property
|
||||
* @param string $property
|
||||
*/
|
||||
public static function getProperty(OA\Schema $schema, $property): OA\Property
|
||||
{
|
||||
@ -128,10 +119,7 @@ final class Util
|
||||
* @see OA\PathItem::$options
|
||||
* @see OA\PathItem::$head
|
||||
*
|
||||
* @param OA\PathItem $path
|
||||
* @param string $method
|
||||
*
|
||||
* @return OA\Operation
|
||||
* @param string $method
|
||||
*/
|
||||
public static function getOperation(OA\PathItem $path, $method): OA\Operation
|
||||
{
|
||||
@ -151,11 +139,8 @@ final class Util
|
||||
* @see OA\Parameter::$name
|
||||
* @see OA\Parameter::$in
|
||||
*
|
||||
* @param OA\Operation $operation
|
||||
* @param string $name
|
||||
* @param string $in
|
||||
*
|
||||
* @return OA\Parameter
|
||||
* @param string $name
|
||||
* @param string $in
|
||||
*/
|
||||
public static function getOperationParameter(OA\Operation $operation, $name, $in): OA\Parameter
|
||||
{
|
||||
@ -171,11 +156,7 @@ final class Util
|
||||
*
|
||||
* @see OA\AbstractAnnotation::$_nested
|
||||
*
|
||||
* @param OA\AbstractAnnotation $parent
|
||||
* @param $class
|
||||
* @param array $properties
|
||||
*
|
||||
* @return OA\AbstractAnnotation
|
||||
*/
|
||||
public static function getChild(OA\AbstractAnnotation $parent, $class, array $properties = []): OA\AbstractAnnotation
|
||||
{
|
||||
@ -201,11 +182,7 @@ final class Util
|
||||
*
|
||||
* @see OA\AbstractAnnotation::$_nested
|
||||
*
|
||||
* @param OA\AbstractAnnotation $parent
|
||||
* @param string $class
|
||||
* @param array $properties
|
||||
*
|
||||
* @return OA\AbstractAnnotation
|
||||
* @param string $class
|
||||
*/
|
||||
public static function getCollectionItem(OA\AbstractAnnotation $parent, $class, array $properties = []): OA\AbstractAnnotation
|
||||
{
|
||||
@ -238,11 +215,8 @@ final class Util
|
||||
*
|
||||
* @see OA\AbstractAnnotation::$_nested
|
||||
*
|
||||
* @param OA\AbstractAnnotation $parent
|
||||
* @param string $class
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return OA\AbstractAnnotation
|
||||
* @param string $class
|
||||
* @param mixed $value
|
||||
*/
|
||||
public static function getIndexedCollectionItem(OA\AbstractAnnotation $parent, $class, $value): OA\AbstractAnnotation
|
||||
{
|
||||
@ -266,9 +240,6 @@ final class Util
|
||||
* Search for an Annotation within $collection that has all members set
|
||||
* to the respective values in the associative array $properties.
|
||||
*
|
||||
* @param array $collection
|
||||
* @param array $properties
|
||||
*
|
||||
* @return int|string|null
|
||||
*/
|
||||
public static function searchCollectionItem(array $collection, array $properties)
|
||||
@ -289,7 +260,6 @@ final class Util
|
||||
/**
|
||||
* Search for an Annotation within the $collection that has its member $index set to $value.
|
||||
*
|
||||
* @param array $collection
|
||||
* @param string $member
|
||||
* @param mixed $value
|
||||
*
|
||||
@ -304,12 +274,8 @@ final class Util
|
||||
* Create a new Object of $class with members $properties within $parent->{$collection}[]
|
||||
* and return the created index.
|
||||
*
|
||||
* @param OA\AbstractAnnotation $parent
|
||||
* @param string $collection
|
||||
* @param string $class
|
||||
* @param array $properties
|
||||
*
|
||||
* @return int
|
||||
* @param string $collection
|
||||
* @param string $class
|
||||
*/
|
||||
public static function createCollectionItem(OA\AbstractAnnotation $parent, $collection, $class, array $properties = []): int
|
||||
{
|
||||
@ -326,14 +292,9 @@ final class Util
|
||||
/**
|
||||
* Create a new Object of $class with members $properties and set the context parent to be $parent.
|
||||
*
|
||||
*
|
||||
* @param OA\AbstractAnnotation $parent
|
||||
* @param string $class
|
||||
* @param array $properties
|
||||
* @param string $class
|
||||
*
|
||||
* @throws \InvalidArgumentException at an attempt to pass in properties that are found in $parent::$_nested
|
||||
*
|
||||
* @return OA\AbstractAnnotation
|
||||
*/
|
||||
public static function createChild(OA\AbstractAnnotation $parent, $class, array $properties = []): OA\AbstractAnnotation
|
||||
{
|
||||
@ -352,11 +313,6 @@ final class Util
|
||||
* Create a new Context with members $properties and parent context $parent.
|
||||
*
|
||||
* @see Context
|
||||
*
|
||||
* @param array $properties
|
||||
* @param Context|null $parent
|
||||
*
|
||||
* @return Context
|
||||
*/
|
||||
public static function createContext(array $properties = [], Context $parent = null): Context
|
||||
{
|
||||
@ -371,9 +327,7 @@ final class Util
|
||||
* The main purpose is to create a Swagger Object from array config values
|
||||
* in the structure of a json serialized Swagger object.
|
||||
*
|
||||
* @param OA\AbstractAnnotation $annotation
|
||||
* @param array|\ArrayObject|OA\AbstractAnnotation $from
|
||||
* @param bool $overwrite
|
||||
*/
|
||||
public static function merge(OA\AbstractAnnotation $annotation, $from, bool $overwrite = false)
|
||||
{
|
||||
@ -496,42 +450,7 @@ final class Util
|
||||
function ($value) {
|
||||
return \is_array($value) ? $value[0] : $value;
|
||||
},
|
||||
self::getNesting($class) ?? []
|
||||
$class::$_nested
|
||||
));
|
||||
}
|
||||
|
||||
private static function getNesting($class)
|
||||
{
|
||||
switch ($class) {
|
||||
case OA\OpenApi::class:
|
||||
return OA\OpenApi::$_nested;
|
||||
case OA\Info::class:
|
||||
return OA\Info::$_nested;
|
||||
case OA\PathItem::class:
|
||||
return OA\PathItem::$_nested;
|
||||
case OA\Get::class:
|
||||
case OA\Post::class:
|
||||
case OA\Put::class:
|
||||
case OA\Delete::class:
|
||||
case OA\Patch::class:
|
||||
case OA\Head::class:
|
||||
case OA\Options::class:
|
||||
return OA\Operation::$_nested;
|
||||
case OA\Parameter::class:
|
||||
return OA\Parameter::$_nested;
|
||||
case OA\Items::class:
|
||||
return OA\Items::$_nested;
|
||||
case OA\Property::class:
|
||||
case OA\Schema::class:
|
||||
return OA\Schema::$_nested;
|
||||
case OA\Tag::class:
|
||||
return OA\Tag::$_nested;
|
||||
case OA\Response::class:
|
||||
return OA\Response::$_nested;
|
||||
case OA\Header::class:
|
||||
return OA\Header::$_nested;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -169,6 +169,12 @@ class TestKernel extends Kernel
|
||||
// Filter routes
|
||||
$c->loadFromExtension('nelmio_api_doc', [
|
||||
'documentation' => [
|
||||
'servers' => [ // from https://github.com/nelmio/NelmioApiDocBundle/issues/1691
|
||||
[
|
||||
'url' => 'https://api.example.com/secured/{version}',
|
||||
'variables' => ['version' => ['default' => 'v1']],
|
||||
],
|
||||
],
|
||||
'info' => [
|
||||
'title' => 'My Default App',
|
||||
],
|
||||
|
Loading…
x
Reference in New Issue
Block a user