NelmioApiDocBundle/Describer/DefaultDescriber.php

51 lines
1.5 KiB
PHP
Raw Normal View History

2016-08-01 19:58:57 +02:00
<?php
/*
2016-12-29 12:09:26 +01:00
* This file is part of the NelmioApiDocBundle package.
2016-08-01 19:58:57 +02:00
*
2016-12-29 12:09:26 +01:00
* (c) Nelmio
2016-08-01 19:58:57 +02:00
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
2016-12-29 12:09:26 +01:00
namespace Nelmio\ApiDocBundle\Describer;
2016-08-01 19:58:57 +02:00
use Nelmio\ApiDocBundle\OpenApiPhp\Util;
use OpenApi\Annotations as OA;
2016-08-01 19:58:57 +02:00
/**
* Makes the swagger documentation valid even if there are missing fields.
*
* @author Ener-Getick <egetick@gmail.com>
*/
2016-11-30 15:04:53 +01:00
final class DefaultDescriber implements DescriberInterface
2016-08-01 19:58:57 +02:00
{
public function describe(OA\OpenApi $api)
2016-08-01 19:58:57 +02:00
{
// Info
/** @var OA\Info $info */
$info = Util::getChild($api, OA\Info::class);
if (OA\UNDEFINED === $info->title) {
$info->title = '';
2016-08-01 19:58:57 +02:00
}
if (OA\UNDEFINED === $info->version) {
$info->version = '0.0.0';
2016-08-01 19:58:57 +02:00
}
// Paths
$paths = OA\UNDEFINED === $api->paths ? [] : $api->paths;
foreach ($paths as $path) {
foreach (Util::OPERATIONS as $method) {
/** @var OA\Operation $operation */
$operation = $path->{$method};
if (OA\UNDEFINED !== $operation && null !== $operation && empty($operation->responses ?? [])) {
/** @var OA\Response $response */
$response = Util::getIndexedCollectionItem($operation, OA\Response::class, 'default');
$response->description = '';
2016-08-01 19:58:57 +02:00
}
}
}
}
}