*/ public array $methods; public string $uri; public Metadata $metadata; /** * @var array */ public array $headers = []; /** * @var array */ public array $urlParameters = []; /** * @var array */ public array $cleanUrlParameters = []; /** * @var array */ public array $queryParameters = []; /** * @var array */ public array $cleanQueryParameters = []; /** * @var array */ public array $bodyParameters = []; /** * @var array */ public array $cleanBodyParameters = []; /** * @var array * @var array */ public array $fileParameters = []; /** * @var \Knuckles\Camel\Extraction\ResponseCollection|array */ public $responses; /** * @var array */ public array $responseFields = []; /** * Authentication info for this endpoint. In the form [{where}, {name}, {sample}] * Example: ["query", "api_key", "njiuyiw97865rfyvgfvb1"] */ public array $auth = []; /** * @var array */ public array $nestedBodyParameters = []; public ?string $boundUri; public ?string $output; public function __construct(array $parameters = []) { // spatie/dto currently doesn't auto-cast nested DTOs like that $parameters['responses'] = new ResponseCollection($parameters['responses']); $parameters['bodyParameters'] = array_map(fn($param) => new Parameter($param), $parameters['bodyParameters']); $parameters['queryParameters'] = array_map(fn($param) => new Parameter($param), $parameters['queryParameters']); $parameters['urlParameters'] = array_map(fn($param) => new Parameter($param), $parameters['urlParameters']); $parameters['responseFields'] = array_map(fn($param) => new ResponseField($param), $parameters['responseFields']); parent::__construct($parameters); $this->boundUri = u::getUrlWithBoundParameters($this->uri, $this->cleanUrlParameters); $this->nestedBodyParameters = Extractor::nestArrayAndObjectFields($this->bodyParameters); $this->cleanBodyParameters = Extractor::cleanParams($this->bodyParameters); $this->cleanQueryParameters = Extractor::cleanParams($this->queryParameters); $this->cleanUrlParameters = Extractor::cleanParams($this->urlParameters); [$files, $regularParameters] = collect($this->cleanBodyParameters) ->partition( fn($example) => $example instanceof UploadedFile || (is_array($example) && ($example[0] ?? null) instanceof UploadedFile) ); if (count($files)) { $this->headers['Content-Type'] = 'multipart/form-data'; } $this->fileParameters = $files->toArray(); $this->cleanBodyParameters = $regularParameters->toArray(); } /** * @param Route $route * * @return array */ 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->methods[0].str_replace(['/', '?', '{', '}', ':'], '-', $this->uri); } public function hasResponses() { return count($this->responses) > 0; } }