From 66a4f43e9598e4117156f30934b9e3bcac789f63 Mon Sep 17 00:00:00 2001 From: mittwald-machine Date: Mon, 25 Nov 2024 19:11:16 +0000 Subject: [PATCH] feat: add precondition failed response handling for domain deletion and email resend operations --- ...DeleteDomainPreconditionFailedResponse.php | 127 ++++++++++++++++++ .../V2/Clients/Domain/DomainClientImpl.php | 4 + ...dDomainEmailPreconditionFailedResponse.php | 127 ++++++++++++++++++ 3 files changed, 258 insertions(+) create mode 100644 src/Generated/V2/Clients/Domain/DeleteDomain/DeleteDomainPreconditionFailedResponse.php create mode 100644 src/Generated/V2/Clients/Domain/ResendDomainEmail/ResendDomainEmailPreconditionFailedResponse.php diff --git a/src/Generated/V2/Clients/Domain/DeleteDomain/DeleteDomainPreconditionFailedResponse.php b/src/Generated/V2/Clients/Domain/DeleteDomain/DeleteDomainPreconditionFailedResponse.php new file mode 100644 index 00000000..6516f2d5 --- /dev/null +++ b/src/Generated/V2/Clients/Domain/DeleteDomain/DeleteDomainPreconditionFailedResponse.php @@ -0,0 +1,127 @@ + 'object', + 'required' => [ + 'body', + ], + 'properties' => [ + 'body' => [ + '$ref' => '#/components/schemas/de.mittwald.v1.commons.Error', + ], + ], + ]; + + private Error $body; + + private ResponseInterface|null $httpResponse = null; + + public function __construct(Error $body) + { + $this->body = $body; + } + + public function getBody(): Error + { + return $this->body; + } + + public function withBody(Error $body): self + { + $clone = clone $this; + $clone->body = $body; + + return $clone; + } + + /** + * Builds a new instance from an input array + * + * @param array|object $input Input data + * @param bool $validate Set this to false to skip validation; use at own risk + * @return DeleteDomainPreconditionFailedResponse Created instance + * @throws InvalidArgumentException + */ + public static function buildFromInput(array|object $input, bool $validate = true): DeleteDomainPreconditionFailedResponse + { + $input = is_array($input) ? Validator::arrayToObjectRecursive($input) : $input; + if ($validate) { + static::validateInput($input); + } + + $body = Error::buildFromInput($input->{'body'}, validate: $validate); + + $obj = new self($body); + + return $obj; + } + + /** + * Converts this object back to a simple array that can be JSON-serialized + * + * @return array Converted array + */ + public function toJson(): array + { + $output = []; + $output['body'] = $this->body->toJson(); + + return $output; + } + + /** + * Validates an input array + * + * @param array|object $input Input data + * @param bool $return Return instead of throwing errors + * @return bool Validation result + * @throws InvalidArgumentException + */ + public static function validateInput(array|object $input, bool $return = false): bool + { + $validator = new \Mittwald\ApiClient\Validator\Validator(); + $input = is_array($input) ? Validator::arrayToObjectRecursive($input) : $input; + $validator->validate($input, static::$schema); + + if (!$validator->isValid() && !$return) { + $errors = array_map(function (array $e): string { + return $e["property"] . ": " . $e["message"]; + }, $validator->getErrors()); + throw new InvalidArgumentException(join(", ", $errors)); + } + + return $validator->isValid(); + } + + public function __clone() + { + } + + public static function fromResponse(ResponseInterface $httpResponse): self + { + $parsedBody = json_decode($httpResponse->getBody()->getContents(), associative: true); + $response = static::buildFromInput(['body' => $parsedBody], validate: false); + $response->httpResponse = $httpResponse; + return $response; + } + + public function getResponse(): ResponseInterface|null + { + return $this->httpResponse; + } +} diff --git a/src/Generated/V2/Clients/Domain/DomainClientImpl.php b/src/Generated/V2/Clients/Domain/DomainClientImpl.php index 140171a5..49591c19 100644 --- a/src/Generated/V2/Clients/Domain/DomainClientImpl.php +++ b/src/Generated/V2/Clients/Domain/DomainClientImpl.php @@ -67,6 +67,7 @@ use Mittwald\ApiClient\Generated\V2\Clients\Domain\DeleteDomain\DeleteDomainDefaultResponse; use Mittwald\ApiClient\Generated\V2\Clients\Domain\DeleteDomain\DeleteDomainNotFoundResponse; use Mittwald\ApiClient\Generated\V2\Clients\Domain\DeleteDomain\DeleteDomainOKResponse; +use Mittwald\ApiClient\Generated\V2\Clients\Domain\DeleteDomain\DeleteDomainPreconditionFailedResponse; use Mittwald\ApiClient\Generated\V2\Clients\Domain\DeleteDomain\DeleteDomainRequest; use Mittwald\ApiClient\Generated\V2\Clients\Domain\DeleteDomain\DeleteDomainTooManyRequestsResponse; use Mittwald\ApiClient\Generated\V2\Clients\Domain\DeprecatedDomainGetScreenshotForDomain\DeprecatedDomainGetScreenshotForDomainDefaultResponse; @@ -229,6 +230,7 @@ use Mittwald\ApiClient\Generated\V2\Clients\Domain\ResendDomainEmail\ResendDomainEmailBadRequestResponse; use Mittwald\ApiClient\Generated\V2\Clients\Domain\ResendDomainEmail\ResendDomainEmailDefaultResponse; use Mittwald\ApiClient\Generated\V2\Clients\Domain\ResendDomainEmail\ResendDomainEmailNotFoundResponse; +use Mittwald\ApiClient\Generated\V2\Clients\Domain\ResendDomainEmail\ResendDomainEmailPreconditionFailedResponse; use Mittwald\ApiClient\Generated\V2\Clients\Domain\ResendDomainEmail\ResendDomainEmailRequest; use Mittwald\ApiClient\Generated\V2\Clients\Domain\ResendDomainEmail\ResendDomainEmailTooManyRequestsResponse; use Mittwald\ApiClient\Generated\V2\Clients\Domain\SslCheckReplaceCertificate\SslCheckReplaceCertificateDefaultResponse; @@ -930,6 +932,7 @@ public function deleteDomain(DeleteDomainRequest $request): DeleteDomainOKRespon throw new UnexpectedResponseException(match ($httpResponse->getStatusCode()) { 400 => DeleteDomainBadRequestResponse::fromResponse($httpResponse), 404 => DeleteDomainNotFoundResponse::fromResponse($httpResponse), + 412 => DeleteDomainPreconditionFailedResponse::fromResponse($httpResponse), 429 => DeleteDomainTooManyRequestsResponse::fromResponse($httpResponse), default => DeleteDomainDefaultResponse::fromResponse($httpResponse), }); @@ -1122,6 +1125,7 @@ public function resendDomainEmail(ResendDomainEmailRequest $request): EmptyRespo throw new UnexpectedResponseException(match ($httpResponse->getStatusCode()) { 400 => ResendDomainEmailBadRequestResponse::fromResponse($httpResponse), 404 => ResendDomainEmailNotFoundResponse::fromResponse($httpResponse), + 412 => ResendDomainEmailPreconditionFailedResponse::fromResponse($httpResponse), 429 => ResendDomainEmailTooManyRequestsResponse::fromResponse($httpResponse), default => ResendDomainEmailDefaultResponse::fromResponse($httpResponse), }); diff --git a/src/Generated/V2/Clients/Domain/ResendDomainEmail/ResendDomainEmailPreconditionFailedResponse.php b/src/Generated/V2/Clients/Domain/ResendDomainEmail/ResendDomainEmailPreconditionFailedResponse.php new file mode 100644 index 00000000..464b21cb --- /dev/null +++ b/src/Generated/V2/Clients/Domain/ResendDomainEmail/ResendDomainEmailPreconditionFailedResponse.php @@ -0,0 +1,127 @@ + 'object', + 'required' => [ + 'body', + ], + 'properties' => [ + 'body' => [ + '$ref' => '#/components/schemas/de.mittwald.v1.commons.Error', + ], + ], + ]; + + private Error $body; + + private ResponseInterface|null $httpResponse = null; + + public function __construct(Error $body) + { + $this->body = $body; + } + + public function getBody(): Error + { + return $this->body; + } + + public function withBody(Error $body): self + { + $clone = clone $this; + $clone->body = $body; + + return $clone; + } + + /** + * Builds a new instance from an input array + * + * @param array|object $input Input data + * @param bool $validate Set this to false to skip validation; use at own risk + * @return ResendDomainEmailPreconditionFailedResponse Created instance + * @throws InvalidArgumentException + */ + public static function buildFromInput(array|object $input, bool $validate = true): ResendDomainEmailPreconditionFailedResponse + { + $input = is_array($input) ? Validator::arrayToObjectRecursive($input) : $input; + if ($validate) { + static::validateInput($input); + } + + $body = Error::buildFromInput($input->{'body'}, validate: $validate); + + $obj = new self($body); + + return $obj; + } + + /** + * Converts this object back to a simple array that can be JSON-serialized + * + * @return array Converted array + */ + public function toJson(): array + { + $output = []; + $output['body'] = $this->body->toJson(); + + return $output; + } + + /** + * Validates an input array + * + * @param array|object $input Input data + * @param bool $return Return instead of throwing errors + * @return bool Validation result + * @throws InvalidArgumentException + */ + public static function validateInput(array|object $input, bool $return = false): bool + { + $validator = new \Mittwald\ApiClient\Validator\Validator(); + $input = is_array($input) ? Validator::arrayToObjectRecursive($input) : $input; + $validator->validate($input, static::$schema); + + if (!$validator->isValid() && !$return) { + $errors = array_map(function (array $e): string { + return $e["property"] . ": " . $e["message"]; + }, $validator->getErrors()); + throw new InvalidArgumentException(join(", ", $errors)); + } + + return $validator->isValid(); + } + + public function __clone() + { + } + + public static function fromResponse(ResponseInterface $httpResponse): self + { + $parsedBody = json_decode($httpResponse->getBody()->getContents(), associative: true); + $response = static::buildFromInput(['body' => $parsedBody], validate: false); + $response->httpResponse = $httpResponse; + return $response; + } + + public function getResponse(): ResponseInterface|null + { + return $this->httpResponse; + } +}