2012-04-11 20:00:21 +02:00
|
|
|
<?php
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
namespace Nelmio\ApiDocBundle\Attribute;
|
2012-04-11 20:00:21 +02:00
|
|
|
|
2012-07-20 00:58:58 +02:00
|
|
|
use Symfony\Component\Routing\Route;
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
#[\Attribute(\Attribute::TARGET_METHOD)]
|
2012-04-11 20:00:21 +02:00
|
|
|
class ApiDoc
|
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
public const DEFAULT_VIEW = 'default';
|
2015-05-16 12:17:59 +02:00
|
|
|
|
2012-04-11 20:00:21 +02:00
|
|
|
/**
|
2012-11-19 18:21:12 +01:00
|
|
|
* Requirements are mandatory parameters in a route.
|
|
|
|
*
|
2024-10-01 23:00:23 +03:00
|
|
|
* @var array<string, array<string, string>>
|
2012-11-19 18:21:12 +01:00
|
|
|
*/
|
2024-10-01 23:00:23 +03:00
|
|
|
private array $requirements = [];
|
2012-11-19 18:21:12 +01:00
|
|
|
|
2014-11-22 22:27:13 +01:00
|
|
|
/**
|
2015-05-16 12:17:59 +02:00
|
|
|
* Which views is this route used. Defaults to "Default"
|
2014-11-22 22:27:13 +01:00
|
|
|
*
|
2024-10-01 23:00:23 +03:00
|
|
|
* @var string[]
|
2014-11-22 22:27:13 +01:00
|
|
|
*/
|
2024-10-01 23:00:23 +03:00
|
|
|
private array $views = [];
|
2014-11-22 22:27:13 +01:00
|
|
|
|
2012-11-19 18:21:12 +01:00
|
|
|
/**
|
|
|
|
* Filters are optional parameters in the query string.
|
|
|
|
*
|
2024-10-01 23:00:23 +03:00
|
|
|
* @var array<string, array<string, string>>
|
2012-04-11 20:00:21 +02:00
|
|
|
*/
|
2024-10-01 23:00:23 +03:00
|
|
|
private array $filters = [];
|
2012-04-11 20:00:21 +02:00
|
|
|
|
2012-11-19 18:21:12 +01:00
|
|
|
/**
|
|
|
|
* Parameters are data a client can send.
|
|
|
|
*
|
2024-10-01 23:00:23 +03:00
|
|
|
* @var array<string, array<string, mixed>>
|
2012-11-19 18:21:12 +01:00
|
|
|
*/
|
2024-10-01 23:00:23 +03:00
|
|
|
private array $parameters = [];
|
2016-05-19 14:28:32 +03:00
|
|
|
/**
|
|
|
|
* Headers that client can send.
|
|
|
|
*
|
2024-10-01 23:00:23 +03:00
|
|
|
* @var array<string, array<string, mixed>>
|
2012-04-11 20:00:21 +02:00
|
|
|
*/
|
2024-10-01 23:00:23 +03:00
|
|
|
private array $headers = [];
|
2012-04-12 17:24:38 +02:00
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
private ?string $link = null;
|
2013-02-13 17:08:00 -02:00
|
|
|
|
2012-07-13 13:32:53 +01:00
|
|
|
/**
|
2012-11-19 18:21:12 +01:00
|
|
|
* Extended documentation.
|
2012-07-13 13:32:53 +01:00
|
|
|
*/
|
2024-10-01 23:00:23 +03:00
|
|
|
private ?string $documentation = null;
|
2012-07-13 13:32:53 +01:00
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
private Route $route;
|
|
|
|
private ?string $host = null;
|
|
|
|
private string $method;
|
|
|
|
private string $uri;
|
2012-04-11 20:00:21 +02:00
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
private array $response = [];
|
2012-07-20 00:58:58 +02:00
|
|
|
|
2013-04-11 22:03:40 +02:00
|
|
|
/**
|
2024-10-01 23:00:23 +03:00
|
|
|
* @var array<int|string, string[]>
|
2013-04-11 22:03:40 +02:00
|
|
|
*/
|
2024-10-01 23:00:23 +03:00
|
|
|
private array $statusCodes = [];
|
2013-04-11 22:03:40 +02:00
|
|
|
|
2012-07-20 00:58:58 +02:00
|
|
|
/**
|
2024-10-01 23:00:23 +03:00
|
|
|
* @var array<int, array<mixed>>
|
2012-07-20 00:58:58 +02:00
|
|
|
*/
|
2024-10-01 23:00:23 +03:00
|
|
|
private array $responseMap = [];
|
2012-07-20 00:58:58 +02:00
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
private array $parsedResponseMap = [];
|
2012-07-20 00:58:58 +02:00
|
|
|
|
2013-03-18 08:40:03 +01:00
|
|
|
/**
|
2024-10-01 23:00:23 +03:00
|
|
|
* @var array<string|int, string>
|
2013-03-18 08:40:03 +01:00
|
|
|
*/
|
2024-10-01 23:00:23 +03:00
|
|
|
private array $tags = [];
|
2014-05-27 13:33:50 +02:00
|
|
|
|
2024-10-01 16:11:23 +03:00
|
|
|
private ?string $scope = null;
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
/**
|
|
|
|
* @param string[]|string|null $description
|
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
private string|bool $resource = false,
|
|
|
|
private array|string|null $description = null,
|
|
|
|
private string|array|null $input = null,
|
|
|
|
private ?array $inputs = null,
|
|
|
|
private string|array|null $output = null,
|
|
|
|
private ?string $section = null,
|
|
|
|
private bool $deprecated = false,
|
|
|
|
private ?string $resourceDescription = null,
|
|
|
|
?array $filters = null,
|
|
|
|
?array $requirements = null,
|
|
|
|
array|string|null $views = null,
|
|
|
|
?array $parameters = null,
|
|
|
|
?array $headers = null,
|
|
|
|
?array $statusCodes = null,
|
|
|
|
array|string|int|null $tags = null,
|
|
|
|
?array $responseMap = null,
|
|
|
|
) {
|
|
|
|
if (null !== $filters) {
|
|
|
|
foreach ($filters as $filter) {
|
2012-04-11 20:00:21 +02:00
|
|
|
if (!isset($filter['name'])) {
|
|
|
|
throw new \InvalidArgumentException('A "filter" element has to contain a "name" attribute');
|
|
|
|
}
|
|
|
|
|
|
|
|
$name = $filter['name'];
|
|
|
|
unset($filter['name']);
|
|
|
|
|
2012-07-18 12:23:57 +02:00
|
|
|
$this->addFilter($name, $filter);
|
2012-04-11 20:00:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
if (null !== $requirements) {
|
|
|
|
foreach ($requirements as $requirement) {
|
2013-07-17 20:41:27 +02:00
|
|
|
if (!isset($requirement['name'])) {
|
|
|
|
throw new \InvalidArgumentException('A "requirement" element has to contain a "name" attribute');
|
|
|
|
}
|
|
|
|
|
|
|
|
$name = $requirement['name'];
|
|
|
|
unset($requirement['name']);
|
|
|
|
|
|
|
|
$this->addRequirement($name, $requirement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
if (null !== $views) {
|
|
|
|
if (!is_array($views)) {
|
|
|
|
$views = [$views];
|
2014-11-22 22:27:13 +01:00
|
|
|
}
|
2015-05-16 12:17:59 +02:00
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
foreach ($views as $view) {
|
2015-05-16 12:17:59 +02:00
|
|
|
$this->addView($view);
|
2014-11-22 22:27:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
if (null !== $parameters) {
|
|
|
|
foreach ($parameters as $parameter) {
|
2013-07-17 20:41:27 +02:00
|
|
|
if (!isset($parameter['name'])) {
|
|
|
|
throw new \InvalidArgumentException('A "parameter" element has to contain a "name" attribute');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($parameter['dataType'])) {
|
|
|
|
throw new \InvalidArgumentException(sprintf(
|
|
|
|
'"%s" parameter element has to contain a "dataType" attribute',
|
|
|
|
$parameter['name']
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
$name = $parameter['name'];
|
|
|
|
unset($parameter['name']);
|
|
|
|
|
|
|
|
$this->addParameter($name, $parameter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
if (null !== $headers) {
|
|
|
|
foreach ($headers as $header) {
|
2016-05-19 14:28:32 +03:00
|
|
|
if (!isset($header['name'])) {
|
|
|
|
throw new \InvalidArgumentException('A "header" element has to contain a "name" attribute');
|
|
|
|
}
|
|
|
|
|
|
|
|
$name = $header['name'];
|
|
|
|
unset($header['name']);
|
|
|
|
|
|
|
|
$this->addHeader($name, $header);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
if (null !== $statusCodes) {
|
|
|
|
foreach ($statusCodes as $statusCode => $statusDescription) {
|
|
|
|
$this->addStatusCode($statusCode, $statusDescription);
|
2013-02-18 21:07:59 +01:00
|
|
|
}
|
2012-11-13 04:45:07 +00:00
|
|
|
}
|
2012-12-26 12:23:28 +01:00
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
if (null !== $tags) {
|
|
|
|
if (is_array($tags)) {
|
|
|
|
foreach ($tags as $tag => $colorCode) {
|
2014-07-19 13:43:39 +02:00
|
|
|
if (is_numeric($tag)) {
|
|
|
|
$this->addTag($colorCode);
|
|
|
|
} else {
|
|
|
|
$this->addTag($tag, $colorCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2024-10-01 23:00:23 +03:00
|
|
|
$this->tags[] = $tags;
|
2014-06-25 08:46:01 +02:00
|
|
|
}
|
|
|
|
}
|
2014-05-27 13:33:50 +02:00
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
if (null !== $responseMap) {
|
|
|
|
$this->responseMap = $responseMap;
|
2014-06-17 17:05:00 -07:00
|
|
|
if (isset($this->responseMap[200])) {
|
|
|
|
$this->output = $this->responseMap[200];
|
|
|
|
}
|
|
|
|
}
|
2012-04-11 20:00:21 +02:00
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function addFilter(string $name, array $filter): void
|
2012-04-11 20:00:21 +02:00
|
|
|
{
|
2012-07-20 00:58:58 +02:00
|
|
|
$this->filters[$name] = $filter;
|
2012-04-11 20:00:21 +02:00
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function addStatusCode(int|string $statusCode, string|array $description): void
|
2013-02-18 21:07:59 +01:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$this->statusCodes[$statusCode] = !is_array($description) ? [$description] : $description;
|
2013-02-18 21:07:59 +01:00
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function addTag(int|string $tag, string $colorCode = '#d9534f'): void
|
2014-07-19 13:43:39 +02:00
|
|
|
{
|
|
|
|
$this->tags[$tag] = $colorCode;
|
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function addRequirement(string $name, array $requirement): void
|
2012-07-18 12:23:57 +02:00
|
|
|
{
|
2012-07-20 00:58:58 +02:00
|
|
|
$this->requirements[$name] = $requirement;
|
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function setRequirements(array $requirements): void
|
2012-07-20 00:58:58 +02:00
|
|
|
{
|
|
|
|
$this->requirements = array_merge($this->requirements, $requirements);
|
2012-07-18 12:23:57 +02:00
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function getInput(): string|array|null
|
2012-04-11 20:00:21 +02:00
|
|
|
{
|
2012-07-23 15:44:37 -04:00
|
|
|
return $this->input;
|
2012-04-11 20:00:21 +02:00
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function getInputs(): ?array
|
2019-04-24 16:42:22 +03:00
|
|
|
{
|
|
|
|
return $this->inputs;
|
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function getOutput(): array|string|null
|
2012-08-27 12:56:19 -04:00
|
|
|
{
|
2012-11-19 18:21:12 +01:00
|
|
|
return $this->output;
|
2012-08-27 12:56:19 -04:00
|
|
|
}
|
|
|
|
|
2012-04-12 17:48:21 +02:00
|
|
|
/**
|
2024-10-01 23:00:23 +03:00
|
|
|
* @return string[]|string|null
|
2012-04-12 17:48:21 +02:00
|
|
|
*/
|
2024-10-01 23:00:23 +03:00
|
|
|
public function getDescription(): array|string|null
|
2012-04-12 17:24:38 +02:00
|
|
|
{
|
|
|
|
return $this->description;
|
|
|
|
}
|
|
|
|
|
2012-04-19 16:23:26 +02:00
|
|
|
/**
|
2024-10-01 23:00:23 +03:00
|
|
|
* @param string[]|string|null $description
|
2012-04-19 16:23:26 +02:00
|
|
|
*/
|
2024-10-01 23:00:23 +03:00
|
|
|
public function setDescription(array|string|null $description): void
|
2012-04-19 16:23:26 +02:00
|
|
|
{
|
|
|
|
$this->description = $description;
|
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function setLink(?string $link): void
|
2013-08-16 19:18:05 +02:00
|
|
|
{
|
|
|
|
$this->link = $link;
|
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function getSection(): ?string
|
2013-02-13 17:08:00 -02:00
|
|
|
{
|
|
|
|
return $this->section;
|
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function addView(string $view): void
|
2014-11-22 22:27:13 +01:00
|
|
|
{
|
2015-05-16 12:17:59 +02:00
|
|
|
$this->views[] = $view;
|
2014-11-22 22:27:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-10-01 23:00:23 +03:00
|
|
|
* @return string[]
|
2014-11-22 22:27:13 +01:00
|
|
|
*/
|
2024-10-01 23:00:23 +03:00
|
|
|
public function getViews(): array
|
2014-11-22 22:27:13 +01:00
|
|
|
{
|
2015-05-16 12:17:59 +02:00
|
|
|
return $this->views;
|
2014-11-22 22:27:13 +01:00
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function setDocumentation(?string $documentation): void
|
2012-07-13 13:32:53 +01:00
|
|
|
{
|
|
|
|
$this->documentation = $documentation;
|
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function getDocumentation(): ?string
|
2013-07-25 13:47:54 -07:00
|
|
|
{
|
|
|
|
return $this->documentation;
|
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function isResource(): bool
|
2012-04-11 20:00:21 +02:00
|
|
|
{
|
2013-10-11 15:44:31 +02:00
|
|
|
return (bool) $this->resource;
|
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function getResource(): string|bool
|
2013-10-11 15:44:31 +02:00
|
|
|
{
|
|
|
|
return $this->resource && is_string($this->resource) ? $this->resource : false;
|
2012-04-11 20:00:21 +02:00
|
|
|
}
|
2012-07-20 00:58:58 +02:00
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function addParameter(string $name, array $parameter): void
|
2012-11-14 23:59:06 +01:00
|
|
|
{
|
|
|
|
$this->parameters[$name] = $parameter;
|
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function setParameters(array $parameters): void
|
2012-07-20 00:58:58 +02:00
|
|
|
{
|
|
|
|
$this->parameters = $parameters;
|
|
|
|
}
|
2012-08-27 13:25:03 -04:00
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function addHeader($name, array $header): void
|
2016-05-19 14:28:32 +03:00
|
|
|
{
|
|
|
|
$this->headers[$name] = $header;
|
|
|
|
}
|
|
|
|
|
2012-08-27 12:56:19 -04:00
|
|
|
/**
|
2014-03-27 19:49:59 +00:00
|
|
|
* Sets the response data as processed by the parsers - same format as parameters
|
2012-08-27 12:56:19 -04:00
|
|
|
*/
|
2024-10-01 15:54:04 +03:00
|
|
|
public function setResponse(array $response): void
|
2012-08-27 12:56:19 -04:00
|
|
|
{
|
|
|
|
$this->response = $response;
|
|
|
|
}
|
2012-08-27 13:25:03 -04:00
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
public function setRoute(Route $route): void
|
2012-07-20 00:58:58 +02:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$this->route = $route;
|
2013-04-12 10:45:20 +03:00
|
|
|
|
|
|
|
if (method_exists($route, 'getHost')) {
|
2024-10-01 15:54:04 +03:00
|
|
|
$this->host = $route->getHost() ?: null;
|
2015-11-10 01:51:26 +01:00
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
// replace route placeholders
|
2015-12-10 09:16:35 +01:00
|
|
|
foreach ($route->getDefaults() as $key => $value) {
|
2024-01-30 18:39:44 +03:00
|
|
|
if (null !== $this->host && is_string($value)) {
|
2015-12-10 09:16:35 +01:00
|
|
|
$this->host = str_replace('{' . $key . '}', $value, $this->host);
|
|
|
|
}
|
2015-11-10 01:51:26 +01:00
|
|
|
}
|
2013-04-12 10:45:20 +03:00
|
|
|
} else {
|
|
|
|
$this->host = null;
|
|
|
|
}
|
|
|
|
|
2024-10-01 15:54:04 +03:00
|
|
|
$this->uri = $route->getPath();
|
2015-04-30 15:34:19 +02:00
|
|
|
$this->method = $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY';
|
2012-07-20 00:58:58 +02:00
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function getRoute(): Route
|
2012-07-20 00:58:58 +02:00
|
|
|
{
|
|
|
|
return $this->route;
|
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function getHost(): ?string
|
2013-04-11 22:03:40 +02:00
|
|
|
{
|
|
|
|
return $this->host;
|
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function getDeprecated(): bool
|
2013-03-18 08:40:03 +01:00
|
|
|
{
|
|
|
|
return $this->deprecated;
|
|
|
|
}
|
|
|
|
|
2013-04-30 16:21:12 +04:00
|
|
|
/**
|
2024-10-01 23:00:23 +03:00
|
|
|
* @return array<string, array<string, string>>
|
2013-04-30 16:21:12 +04:00
|
|
|
*/
|
2024-10-01 23:00:23 +03:00
|
|
|
public function getFilters(): array
|
2013-04-30 16:21:12 +04:00
|
|
|
{
|
|
|
|
return $this->filters;
|
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function getRequirements(): array
|
2013-04-30 16:21:12 +04:00
|
|
|
{
|
|
|
|
return $this->requirements;
|
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function getParameters(): array
|
2014-06-18 11:50:26 +02:00
|
|
|
{
|
|
|
|
return $this->parameters;
|
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function getHeaders(): array
|
2016-05-19 14:28:32 +03:00
|
|
|
{
|
|
|
|
return $this->headers;
|
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function setDeprecated(bool $deprecated): void
|
2013-03-18 08:40:03 +01:00
|
|
|
{
|
2024-10-01 23:00:23 +03:00
|
|
|
$this->deprecated = $deprecated;
|
2013-03-18 08:40:03 +01:00
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function getMethod(): string
|
2014-09-29 16:17:36 +02:00
|
|
|
{
|
|
|
|
return $this->method;
|
|
|
|
}
|
|
|
|
|
2024-10-01 16:11:23 +03:00
|
|
|
public function setScope(string $scope): void
|
|
|
|
{
|
|
|
|
$this->scope = $scope;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getScope(): ?string
|
|
|
|
{
|
|
|
|
return $this->scope;
|
|
|
|
}
|
|
|
|
|
2012-07-20 00:58:58 +02:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function toArray()
|
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$data = [
|
2024-10-01 23:00:23 +03:00
|
|
|
'method' => $this->method ?? null,
|
|
|
|
'uri' => $this->uri ?? null,
|
2024-10-01 15:54:04 +03:00
|
|
|
];
|
2012-07-20 00:58:58 +02:00
|
|
|
|
2013-04-11 22:03:40 +02:00
|
|
|
if ($host = $this->host) {
|
|
|
|
$data['host'] = $host;
|
|
|
|
}
|
|
|
|
|
2012-07-20 00:58:58 +02:00
|
|
|
if ($description = $this->description) {
|
|
|
|
$data['description'] = $description;
|
|
|
|
}
|
|
|
|
|
2013-08-16 19:18:05 +02:00
|
|
|
if ($link = $this->link) {
|
|
|
|
$data['link'] = $link;
|
|
|
|
}
|
|
|
|
|
2012-07-20 00:58:58 +02:00
|
|
|
if ($documentation = $this->documentation) {
|
|
|
|
$data['documentation'] = $documentation;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($filters = $this->filters) {
|
|
|
|
$data['filters'] = $filters;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($parameters = $this->parameters) {
|
|
|
|
$data['parameters'] = $parameters;
|
|
|
|
}
|
|
|
|
|
2016-05-19 14:28:32 +03:00
|
|
|
if ($headers = $this->headers) {
|
|
|
|
$data['headers'] = $headers;
|
|
|
|
}
|
|
|
|
|
2012-07-20 00:58:58 +02:00
|
|
|
if ($requirements = $this->requirements) {
|
|
|
|
$data['requirements'] = $requirements;
|
|
|
|
}
|
2012-08-27 13:25:03 -04:00
|
|
|
|
2015-05-16 12:17:59 +02:00
|
|
|
if ($views = $this->views) {
|
|
|
|
$data['views'] = $views;
|
2014-11-22 22:27:13 +01:00
|
|
|
}
|
|
|
|
|
2012-08-27 12:56:19 -04:00
|
|
|
if ($response = $this->response) {
|
|
|
|
$data['response'] = $response;
|
|
|
|
}
|
2012-07-23 15:44:37 -04:00
|
|
|
|
2016-01-26 04:21:08 +01:00
|
|
|
if ($parsedResponseMap = $this->parsedResponseMap) {
|
|
|
|
$data['parsedResponseMap'] = $parsedResponseMap;
|
|
|
|
}
|
|
|
|
|
2012-11-13 04:45:07 +00:00
|
|
|
if ($statusCodes = $this->statusCodes) {
|
|
|
|
$data['statusCodes'] = $statusCodes;
|
|
|
|
}
|
|
|
|
|
2013-03-17 16:40:31 +01:00
|
|
|
if ($section = $this->section) {
|
2013-02-14 13:52:20 -02:00
|
|
|
$data['section'] = $section;
|
|
|
|
}
|
|
|
|
|
2014-05-27 13:33:50 +02:00
|
|
|
if ($tags = $this->tags) {
|
|
|
|
$data['tags'] = $tags;
|
|
|
|
}
|
|
|
|
|
2014-06-17 17:05:00 -07:00
|
|
|
if ($resourceDescription = $this->resourceDescription) {
|
|
|
|
$data['resourceDescription'] = $resourceDescription;
|
|
|
|
}
|
|
|
|
|
2013-03-18 08:40:03 +01:00
|
|
|
$data['deprecated'] = $this->deprecated;
|
2024-10-01 16:11:23 +03:00
|
|
|
$data['scope'] = $this->scope;
|
2012-12-10 10:21:04 -08:00
|
|
|
|
2012-07-20 00:58:58 +02:00
|
|
|
return $data;
|
|
|
|
}
|
2014-06-17 17:05:00 -07:00
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function getResourceDescription(): ?string
|
2014-06-17 17:05:00 -07:00
|
|
|
{
|
|
|
|
return $this->resourceDescription;
|
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function getResponseMap(): array
|
2014-06-17 17:05:00 -07:00
|
|
|
{
|
|
|
|
if (!isset($this->responseMap[200]) && null !== $this->output) {
|
|
|
|
$this->responseMap[200] = $this->output;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->responseMap;
|
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function getParsedResponseMap(): array
|
2014-06-17 17:05:00 -07:00
|
|
|
{
|
|
|
|
return $this->parsedResponseMap;
|
|
|
|
}
|
|
|
|
|
2024-10-01 23:00:23 +03:00
|
|
|
public function setResponseForStatusCode(array $model, array $type, int $statusCode = 200): void
|
2014-06-17 17:05:00 -07:00
|
|
|
{
|
2024-10-01 15:54:04 +03:00
|
|
|
$this->parsedResponseMap[$statusCode] = ['type' => $type, 'model' => $model];
|
2024-10-01 23:00:23 +03:00
|
|
|
if (200 === $statusCode && $this->response !== $model) {
|
2014-06-17 17:05:00 -07:00
|
|
|
$this->response = $model;
|
|
|
|
}
|
|
|
|
}
|
2012-04-11 20:00:21 +02:00
|
|
|
}
|