update bug daashboards
This commit is contained in:
169
vendor/knuckleswtf/scribe/camel/Extraction/ExtractedEndpointData.php
vendored
Normal file
169
vendor/knuckleswtf/scribe/camel/Extraction/ExtractedEndpointData.php
vendored
Normal file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
namespace Knuckles\Camel\Extraction;
|
||||
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Routing\Route;
|
||||
use Knuckles\Camel\BaseDTO;
|
||||
use Knuckles\Scribe\Extracting\Shared\UrlParamsNormalizer;
|
||||
use Knuckles\Scribe\Tools\Globals;
|
||||
use Knuckles\Scribe\Tools\Utils as u;
|
||||
|
||||
class ExtractedEndpointData extends BaseDTO
|
||||
{
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
public array $httpMethods;
|
||||
|
||||
public string $uri;
|
||||
|
||||
public Metadata $metadata;
|
||||
|
||||
/**
|
||||
* @var array<string,string>
|
||||
*/
|
||||
public array $headers = [];
|
||||
|
||||
/**
|
||||
* @var array<string,Parameter>
|
||||
*/
|
||||
public array $urlParameters = [];
|
||||
|
||||
/**
|
||||
* @var array<string,mixed>
|
||||
*/
|
||||
public array $cleanUrlParameters = [];
|
||||
|
||||
/**
|
||||
* @var array<string,Parameter>
|
||||
*/
|
||||
public array $queryParameters = [];
|
||||
|
||||
/**
|
||||
* @var array<string,mixed>
|
||||
*/
|
||||
public array $cleanQueryParameters = [];
|
||||
|
||||
/**
|
||||
* @var array<string,Parameter>
|
||||
*/
|
||||
public array $bodyParameters = [];
|
||||
|
||||
/**
|
||||
* @var array<string,mixed>
|
||||
*/
|
||||
public array $cleanBodyParameters = [];
|
||||
|
||||
/**
|
||||
* @var array<string,array|UploadedFile>
|
||||
*/
|
||||
public array $fileParameters = [];
|
||||
|
||||
public ResponseCollection $responses;
|
||||
|
||||
/**
|
||||
* @var array<string,ResponseField>
|
||||
*/
|
||||
public array $responseFields = [];
|
||||
|
||||
/**
|
||||
* Authentication info for this endpoint. In the form [{where}, {name}, {sample}]
|
||||
* Example: ["queryParameters", "api_key", "njiuyiw97865rfyvgfvb1"].
|
||||
*/
|
||||
public array $auth = [];
|
||||
|
||||
public ?\ReflectionClass $controller;
|
||||
|
||||
public ?\ReflectionFunctionAbstract $method;
|
||||
|
||||
public ?Route $route;
|
||||
|
||||
public function __construct(array $parameters = [])
|
||||
{
|
||||
$parameters['metadata'] ??= new Metadata([]);
|
||||
$parameters['responses'] ??= new ResponseCollection([]);
|
||||
|
||||
parent::__construct($parameters);
|
||||
|
||||
$defaultNormalizer = fn () => UrlParamsNormalizer::normalizeParameterNamesInRouteUri($this->route, $this->method);
|
||||
$this->uri = match (is_callable(Globals::$__normalizeEndpointUrlUsing)) {
|
||||
true => call_user_func_array(
|
||||
Globals::$__normalizeEndpointUrlUsing,
|
||||
[$this->route->uri, $this->route, $this->method, $this->controller, $defaultNormalizer]
|
||||
),
|
||||
default => $defaultNormalizer(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $extras Only used for quick overrides in tests
|
||||
*
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public static function fromRoute(Route $route, array $extras = []): self
|
||||
{
|
||||
$httpMethods = self::getMethods($route);
|
||||
$uri = $route->uri();
|
||||
|
||||
[$controllerName, $methodName] = u::getRouteClassAndMethodNames($route);
|
||||
$controller = new \ReflectionClass($controllerName);
|
||||
$method = u::getReflectedRouteMethod([$controllerName, $methodName]);
|
||||
|
||||
$data = compact('httpMethods', 'uri', 'controller', 'method', 'route');
|
||||
$data = array_merge($data, $extras);
|
||||
|
||||
return new self($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
public static function getMethods(Route $route): array
|
||||
{
|
||||
$methods = $route->methods();
|
||||
|
||||
// Laravel adds an automatic "HEAD" endpoint for each GET request, so we'll strip that out,
|
||||
// but not if there's only one method (means it was intentional)
|
||||
if (count($methods) === 1) {
|
||||
return $methods;
|
||||
}
|
||||
|
||||
return array_diff($methods, ['HEAD']);
|
||||
}
|
||||
|
||||
public function name()
|
||||
{
|
||||
return sprintf("[%s] {$this->route->uri}.", implode(',', $this->route->methods));
|
||||
}
|
||||
|
||||
public function endpointId()
|
||||
{
|
||||
return $this->httpMethods[0].str_replace(['/', '?', '{', '}', ':', '\\', '+', '|'], '-', $this->uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the endpoint data for serialising.
|
||||
*/
|
||||
public function forSerialisation()
|
||||
{
|
||||
$copyArray = $this->except(
|
||||
// Get rid of all duplicate data
|
||||
'cleanQueryParameters',
|
||||
'cleanUrlParameters',
|
||||
'fileParameters',
|
||||
'cleanBodyParameters',
|
||||
// and objects used only in extraction
|
||||
'route',
|
||||
'controller',
|
||||
'method',
|
||||
'auth',
|
||||
);
|
||||
// Remove these, since they're on the parent group object
|
||||
if (isset($copyArray['metadata']) && $copyArray['metadata'] instanceof Metadata) {
|
||||
$copyArray['metadata'] = $copyArray['metadata']->except('groupName', 'groupDescription');
|
||||
}
|
||||
|
||||
return $copyArray;
|
||||
}
|
||||
}
|
||||
24
vendor/knuckleswtf/scribe/camel/Extraction/Metadata.php
vendored
Normal file
24
vendor/knuckleswtf/scribe/camel/Extraction/Metadata.php
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Knuckles\Camel\Extraction;
|
||||
|
||||
use Knuckles\Camel\BaseDTO;
|
||||
|
||||
class Metadata extends BaseDTO
|
||||
{
|
||||
public ?string $groupName;
|
||||
|
||||
public ?string $groupDescription;
|
||||
|
||||
public ?string $subgroup;
|
||||
|
||||
public ?string $subgroupDescription;
|
||||
|
||||
public ?string $title;
|
||||
|
||||
public ?string $description;
|
||||
|
||||
public bool $authenticated = false;
|
||||
|
||||
public bool|string $deprecated = false;
|
||||
}
|
||||
32
vendor/knuckleswtf/scribe/camel/Extraction/Parameter.php
vendored
Normal file
32
vendor/knuckleswtf/scribe/camel/Extraction/Parameter.php
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Knuckles\Camel\Extraction;
|
||||
|
||||
use Knuckles\Camel\BaseDTO;
|
||||
|
||||
class Parameter extends BaseDTO
|
||||
{
|
||||
public string $name;
|
||||
|
||||
public ?string $description = null;
|
||||
|
||||
public bool $required = false;
|
||||
|
||||
public mixed $example = null;
|
||||
|
||||
public string $type = 'string';
|
||||
|
||||
public array $enumValues = [];
|
||||
|
||||
public bool $exampleWasSpecified = false;
|
||||
|
||||
public bool $nullable = false;
|
||||
|
||||
public bool $deprecated = false;
|
||||
|
||||
public function __construct(array $parameters = [])
|
||||
{
|
||||
unset($parameters['setter']);
|
||||
parent::__construct($parameters);
|
||||
}
|
||||
}
|
||||
67
vendor/knuckleswtf/scribe/camel/Extraction/Response.php
vendored
Normal file
67
vendor/knuckleswtf/scribe/camel/Extraction/Response.php
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Knuckles\Camel\Extraction;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Knuckles\Camel\BaseDTO;
|
||||
|
||||
class Response extends BaseDTO
|
||||
{
|
||||
public int $status;
|
||||
|
||||
public ?string $content;
|
||||
|
||||
public array $headers = [];
|
||||
|
||||
public ?string $description;
|
||||
|
||||
public function __construct(array $parameters = [])
|
||||
{
|
||||
if (is_array($parameters['content'] ?? null)) {
|
||||
$parameters['content'] = json_encode($parameters['content'], JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
|
||||
if (isset($parameters['status'])) {
|
||||
$parameters['status'] = (int) $parameters['status'];
|
||||
}
|
||||
|
||||
$hiddenHeaders = [
|
||||
'date',
|
||||
'Date',
|
||||
'etag',
|
||||
'ETag',
|
||||
'last-modified',
|
||||
'Last-Modified',
|
||||
'date',
|
||||
'Date',
|
||||
'content-length',
|
||||
'Content-Length',
|
||||
'connection',
|
||||
'Connection',
|
||||
'x-powered-by',
|
||||
'X-Powered-By',
|
||||
];
|
||||
if (! empty($parameters['headers'])) {
|
||||
foreach ($hiddenHeaders as $headerName) {
|
||||
unset($parameters['headers'][$headerName]);
|
||||
}
|
||||
}
|
||||
|
||||
parent::__construct($parameters);
|
||||
}
|
||||
|
||||
public function fullDescription()
|
||||
{
|
||||
$description = $this->status;
|
||||
if ($this->description) {
|
||||
$description .= ", {$this->description}";
|
||||
}
|
||||
|
||||
return $description;
|
||||
}
|
||||
|
||||
public function isBinary(): bool
|
||||
{
|
||||
return is_string($this->content) && Str::startsWith($this->content, '<<binary>>');
|
||||
}
|
||||
}
|
||||
20
vendor/knuckleswtf/scribe/camel/Extraction/ResponseCollection.php
vendored
Normal file
20
vendor/knuckleswtf/scribe/camel/Extraction/ResponseCollection.php
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Knuckles\Camel\Extraction;
|
||||
|
||||
use Knuckles\Camel\BaseDTOCollection;
|
||||
|
||||
/**
|
||||
* @extends BaseDTOCollection<Response>
|
||||
*/
|
||||
class ResponseCollection extends BaseDTOCollection
|
||||
{
|
||||
public static string $base = Response::class;
|
||||
|
||||
public function hasSuccessResponse(): bool
|
||||
{
|
||||
return $this->first(
|
||||
fn ($response) => '2' === ((string) ($response->status))[0]
|
||||
) !== null;
|
||||
}
|
||||
}
|
||||
31
vendor/knuckleswtf/scribe/camel/Extraction/ResponseField.php
vendored
Normal file
31
vendor/knuckleswtf/scribe/camel/Extraction/ResponseField.php
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Knuckles\Camel\Extraction;
|
||||
|
||||
use Knuckles\Camel\BaseDTO;
|
||||
|
||||
class ResponseField extends BaseDTO
|
||||
{
|
||||
// TODO make this extend Parameter, so we can have strong types and a unified API
|
||||
// but first we need to normalize incoming data
|
||||
|
||||
/** @var string */
|
||||
public $name;
|
||||
|
||||
/** @var string */
|
||||
public $description;
|
||||
|
||||
/** @var string */
|
||||
public $type;
|
||||
|
||||
/** @var bool */
|
||||
public $required;
|
||||
|
||||
/** @var mixed */
|
||||
public $example;
|
||||
|
||||
public array $enumValues = [];
|
||||
|
||||
/** @var bool */
|
||||
public $nullable;
|
||||
}
|
||||
Reference in New Issue
Block a user