Skip to content

feat(openapi): manage error resources in global #7082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 4.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Metadata/ApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace ApiPlatform\Metadata;

use ApiPlatform\Metadata\Exception\ProblemExceptionInterface;
use ApiPlatform\Metadata\GraphQl\Operation as GraphQlOperation;
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
use ApiPlatform\State\OptionsInterface;
Expand Down Expand Up @@ -45,6 +46,7 @@ class ApiResource extends Metadata
* @param mixed|null $messenger
* @param mixed|null $input
* @param mixed|null $output
* @param array<class-string<ProblemExceptionInterface>>|null $errors
*/
public function __construct(
/**
Expand Down Expand Up @@ -966,6 +968,7 @@ public function __construct(
protected ?bool $strictQueryParameterValidation = null,
protected ?bool $hideHydraOperation = null,
protected array $extraProperties = [],
?array $errors = null,
) {
parent::__construct(
shortName: $shortName,
Expand Down Expand Up @@ -1005,13 +1008,14 @@ class: $class,
provider: $provider,
processor: $processor,
stateOptions: $stateOptions,
errors: $errors,
parameters: $parameters,
rules: $rules,
policy: $policy,
middleware: $middleware,
strictQueryParameterValidation: $strictQueryParameterValidation,
hideHydraOperation: $hideHydraOperation,
extraProperties: $extraProperties
extraProperties: $extraProperties,
);

$this->operations = null === $operations ? null : new Operations($operations);
Expand Down
5 changes: 2 additions & 3 deletions src/Metadata/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ public function __construct(
?array $exceptionToStatus = null,
?bool $queryParameterValidationEnabled = null,
?array $links = null,
?array $errors = null,

?string $shortName = null,
?string $class = null,
?bool $paginationEnabled = null,
Expand Down Expand Up @@ -94,6 +92,7 @@ public function __construct(
$provider = null,
$processor = null,
?OptionsInterface $stateOptions = null,
?array $errors = null,
array|Parameters|null $parameters = null,
mixed $rules = null,
?string $policy = null,
Expand Down Expand Up @@ -131,7 +130,6 @@ public function __construct(
exceptionToStatus: $exceptionToStatus,
queryParameterValidationEnabled: $queryParameterValidationEnabled,
links: $links,
errors: $errors,
shortName: $shortName,
class: $class,
paginationEnabled: $paginationEnabled,
Expand Down Expand Up @@ -183,6 +181,7 @@ class: $class,
strictQueryParameterValidation: $strictQueryParameterValidation,
hideHydraOperation: $hideHydraOperation,
stateOptions: $stateOptions,
errors: $errors,
);
}
}
5 changes: 2 additions & 3 deletions src/Metadata/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ public function __construct(
?array $exceptionToStatus = null,
?bool $queryParameterValidationEnabled = null,
?array $links = null,
?array $errors = null,

?string $shortName = null,
?string $class = null,
?bool $paginationEnabled = null,
Expand Down Expand Up @@ -94,6 +92,7 @@ public function __construct(
$provider = null,
$processor = null,
?OptionsInterface $stateOptions = null,
?array $errors = null,
?bool $hideHydraOperation = null,
array $extraProperties = [],
) {
Expand Down Expand Up @@ -125,7 +124,6 @@ public function __construct(
exceptionToStatus: $exceptionToStatus,
queryParameterValidationEnabled: $queryParameterValidationEnabled,
links: $links,
errors: $errors,
shortName: $shortName,
class: $class,
paginationEnabled: $paginationEnabled,
Expand Down Expand Up @@ -170,6 +168,7 @@ class: $class,
provider: $provider,
processor: $processor,
stateOptions: $stateOptions,
errors: $errors,
hideHydraOperation: $hideHydraOperation,
extraProperties: $extraProperties,
);
Expand Down
5 changes: 2 additions & 3 deletions src/Metadata/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ public function __construct(
?array $exceptionToStatus = null,
?bool $queryParameterValidationEnabled = null,
?array $links = null,
?array $errors = null,

?string $shortName = null,
?string $class = null,
?bool $paginationEnabled = null,
Expand Down Expand Up @@ -94,6 +92,7 @@ public function __construct(
$provider = null,
$processor = null,
?OptionsInterface $stateOptions = null,
?array $errors = null,
array|Parameters|null $parameters = null,
mixed $rules = null,
?string $policy = null,
Expand Down Expand Up @@ -130,7 +129,6 @@ public function __construct(
exceptionToStatus: $exceptionToStatus,
queryParameterValidationEnabled: $queryParameterValidationEnabled,
links: $links,
errors: $errors,
shortName: $shortName,
class: $class,
paginationEnabled: $paginationEnabled,
Expand Down Expand Up @@ -175,6 +173,7 @@ class: $class,
provider: $provider,
processor: $processor,
stateOptions: $stateOptions,
errors: $errors,
parameters: $parameters,
rules: $rules,
policy: $policy,
Expand Down
5 changes: 2 additions & 3 deletions src/Metadata/GetCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ public function __construct(
?array $exceptionToStatus = null,
?bool $queryParameterValidationEnabled = null,
?array $links = null,
?array $errors = null,

?string $shortName = null,
?string $class = null,
?bool $paginationEnabled = null,
Expand Down Expand Up @@ -94,6 +92,7 @@ public function __construct(
$provider = null,
$processor = null,
?OptionsInterface $stateOptions = null,
?array $errors = null,
array|Parameters|null $parameters = null,
array|string|null $rules = null,
?string $policy = null,
Expand Down Expand Up @@ -131,7 +130,6 @@ public function __construct(
exceptionToStatus: $exceptionToStatus,
queryParameterValidationEnabled: $queryParameterValidationEnabled,
links: $links,
errors: $errors,
shortName: $shortName,
class: $class,
paginationEnabled: $paginationEnabled,
Expand Down Expand Up @@ -183,6 +181,7 @@ class: $class,
strictQueryParameterValidation: $strictQueryParameterValidation,
hideHydraOperation: $hideHydraOperation,
stateOptions: $stateOptions,
errors: $errors,
);
}

Expand Down
21 changes: 3 additions & 18 deletions src/Metadata/HttpOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ public function __construct(
protected bool|OpenApiOperation|Webhook|null $openapi = null,
protected ?array $exceptionToStatus = null,
protected ?array $links = null,
protected ?array $errors = null,
protected ?bool $strictQueryParameterValidation = null,
protected ?bool $hideHydraOperation = null,

Expand Down Expand Up @@ -202,6 +201,7 @@ public function __construct(
$provider = null,
$processor = null,
?OptionsInterface $stateOptions = null,
?array $errors = null,
array|Parameters|null $parameters = null,
array|string|null $rules = null,
?string $policy = null,
Expand Down Expand Up @@ -254,14 +254,15 @@ class: $class,
provider: $provider,
processor: $processor,
stateOptions: $stateOptions,
errors: $errors,
parameters: $parameters,
rules: $rules,
policy: $policy,
middleware: $middleware,
queryParameterValidationEnabled: $queryParameterValidationEnabled,
strictQueryParameterValidation: $strictQueryParameterValidation,
hideHydraOperation: $hideHydraOperation,
extraProperties: $extraProperties
extraProperties: $extraProperties,
);
}

Expand Down Expand Up @@ -621,20 +622,4 @@ public function withLinks(array $links): static

return $self;
}

public function getErrors(): ?array
{
return $this->errors;
}

/**
* @param class-string<ProblemExceptionInterface>[] $errors
*/
public function withErrors(array $errors): static
{
$self = clone $this;
$self->errors = $errors;

return $self;
}
}
19 changes: 19 additions & 0 deletions src/Metadata/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace ApiPlatform\Metadata;

use ApiPlatform\Metadata\Exception\ProblemExceptionInterface;
use ApiPlatform\State\OptionsInterface;

/**
Expand All @@ -34,6 +35,7 @@ abstract class Metadata
* @param mixed|null $processor
* @param Parameters|array<string, Parameter> $parameters
* @param callable|string|array<string, \Illuminate\Contracts\Validation\Rule|array|string> $rules Laravel rules can be a FormRequest class, a callable or an array of rules
* @param array<class-string<ProblemExceptionInterface>>|null $errors
*/
public function __construct(
protected ?string $shortName = null,
Expand Down Expand Up @@ -73,6 +75,7 @@ public function __construct(
protected $provider = null,
protected $processor = null,
protected ?OptionsInterface $stateOptions = null,
protected ?array $errors = null,
/*
* @experimental
*/
Expand Down Expand Up @@ -694,4 +697,20 @@ public function withHideHydraOperation(bool $hideHydraOperation): static

return $self;
}

public function getErrors(): ?array
{
return $this->errors;
}

/**
* @param class-string<ProblemExceptionInterface>[] $errors
*/
public function withErrors(array $errors): static
{
$self = clone $this;
$self->errors = $errors;

return $self;
}
}
30 changes: 17 additions & 13 deletions src/Metadata/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace ApiPlatform\Metadata;

use ApiPlatform\Metadata\Exception\ProblemExceptionInterface;
use ApiPlatform\State\OptionsInterface;

/**
Expand Down Expand Up @@ -47,19 +48,20 @@ abstract class Operation extends Metadata
* class?: string|null,
* name?: string,
* }|string|false|null $output {@see https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation}
* @param string|array|bool|null $mercure {@see https://api-platform.com/docs/core/mercure}
* @param string|bool|null $messenger {@see https://api-platform.com/docs/core/messenger/#dispatching-a-resource-through-the-message-bus}
* @param bool|null $elasticsearch {@see https://api-platform.com/docs/core/elasticsearch/}
* @param bool|null $read {@see https://api-platform.com/docs/core/events/#the-event-system}
* @param bool|null $deserialize {@see https://api-platform.com/docs/core/events/#the-event-system}
* @param bool|null $validate {@see https://api-platform.com/docs/core/events/#the-event-system}
* @param bool|null $write {@see https://api-platform.com/docs/core/events/#the-event-system}
* @param bool|null $serialize {@see https://api-platform.com/docs/core/events/#the-event-system}
* @param bool|null $fetchPartial {@see https://api-platform.com/docs/core/performance/#fetch-partial}
* @param bool|null $forceEager {@see https://api-platform.com/docs/core/performance/#force-eager}
* @param string|callable|null $provider {@see https://api-platform.com/docs/core/state-providers/#state-providers}
* @param string|callable|null $processor {@see https://api-platform.com/docs/core/state-processors/#state-processors}
* @param array<string, Parameter> $parameters
* @param string|array|bool|null $mercure {@see https://api-platform.com/docs/core/mercure}
* @param string|bool|null $messenger {@see https://api-platform.com/docs/core/messenger/#dispatching-a-resource-through-the-message-bus}
* @param bool|null $elasticsearch {@see https://api-platform.com/docs/core/elasticsearch/}
* @param bool|null $read {@see https://api-platform.com/docs/core/events/#the-event-system}
* @param bool|null $deserialize {@see https://api-platform.com/docs/core/events/#the-event-system}
* @param bool|null $validate {@see https://api-platform.com/docs/core/events/#the-event-system}
* @param bool|null $write {@see https://api-platform.com/docs/core/events/#the-event-system}
* @param bool|null $serialize {@see https://api-platform.com/docs/core/events/#the-event-system}
* @param bool|null $fetchPartial {@see https://api-platform.com/docs/core/performance/#fetch-partial}
* @param bool|null $forceEager {@see https://api-platform.com/docs/core/performance/#force-eager}
* @param string|callable|null $provider {@see https://api-platform.com/docs/core/state-providers/#state-providers}
* @param string|callable|null $processor {@see https://api-platform.com/docs/core/state-processors/#state-processors}
* @param array<string, Parameter> $parameters
* @param array<class-string<ProblemExceptionInterface>>|null $errors
*/
public function __construct(
protected ?string $shortName = null,
Expand Down Expand Up @@ -806,6 +808,7 @@ public function __construct(
protected $provider = null,
protected $processor = null,
protected ?OptionsInterface $stateOptions = null,
?array $errors = null,
array|Parameters|null $parameters = null,
array|string|null $rules = null,
?string $policy = null,
Expand Down Expand Up @@ -853,6 +856,7 @@ class: $class,
provider: $provider,
processor: $processor,
stateOptions: $stateOptions,
errors: $errors,
parameters: $parameters,
rules: $rules,
policy: $policy,
Expand Down
7 changes: 3 additions & 4 deletions src/Metadata/Patch.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ public function __construct(
?array $exceptionToStatus = null,
?bool $queryParameterValidationEnabled = null,
?array $links = null,
?array $errors = null,

?string $shortName = null,
?string $class = null,
?bool $paginationEnabled = null,
Expand Down Expand Up @@ -94,6 +92,7 @@ public function __construct(
$provider = null,
$processor = null,
?OptionsInterface $stateOptions = null,
?array $errors = null,
array|Parameters|null $parameters = null,
mixed $rules = null,
?string $policy = null,
Expand Down Expand Up @@ -131,7 +130,6 @@ public function __construct(
exceptionToStatus: $exceptionToStatus,
queryParameterValidationEnabled: $queryParameterValidationEnabled,
links: $links,
errors: $errors,
shortName: $shortName,
class: $class,
paginationEnabled: $paginationEnabled,
Expand Down Expand Up @@ -176,13 +174,14 @@ class: $class,
provider: $provider,
processor: $processor,
stateOptions: $stateOptions,
errors: $errors,
parameters: $parameters,
rules: $rules,
policy: $policy,
middleware: $middleware,
strictQueryParameterValidation: $strictQueryParameterValidation,
hideHydraOperation: $hideHydraOperation,
extraProperties: $extraProperties
extraProperties: $extraProperties,
);
}
}
Loading
Loading