Skip to content

Commit

Permalink
Update generated client
Browse files Browse the repository at this point in the history
  • Loading branch information
mittwald-machine committed Jan 11, 2024
1 parent 79b251a commit 0283b8e
Show file tree
Hide file tree
Showing 10 changed files with 400 additions and 24 deletions.
2 changes: 2 additions & 0 deletions src/Generated/V2/Clients/Domain/DomainClientImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
use Mittwald\ApiClient\Generated\V2\Clients\Domain\IngressIngressVerifyOwnership\IngressIngressVerifyOwnershipDefaultResponse;
use Mittwald\ApiClient\Generated\V2\Clients\Domain\IngressIngressVerifyOwnership\IngressIngressVerifyOwnershipNotFoundResponse;
use Mittwald\ApiClient\Generated\V2\Clients\Domain\IngressIngressVerifyOwnership\IngressIngressVerifyOwnershipOKResponse;
use Mittwald\ApiClient\Generated\V2\Clients\Domain\IngressIngressVerifyOwnership\IngressIngressVerifyOwnershipPreconditionFailedResponse;
use Mittwald\ApiClient\Generated\V2\Clients\Domain\IngressIngressVerifyOwnership\IngressIngressVerifyOwnershipRequest;
use Mittwald\ApiClient\Generated\V2\Clients\Domain\IngressListIngresses\IngressListIngressesDefaultResponse;
use Mittwald\ApiClient\Generated\V2\Clients\Domain\IngressListIngresses\IngressListIngressesNotFoundResponse;
Expand Down Expand Up @@ -1222,6 +1223,7 @@ public function ingressIngressVerifyOwnership(IngressIngressVerifyOwnershipReque
throw new UnexpectedResponseException(match ($httpResponse->getStatusCode()) {
400 => IngressIngressVerifyOwnershipBadRequestResponse::fromResponse($httpResponse),
404 => IngressIngressVerifyOwnershipNotFoundResponse::fromResponse($httpResponse),
412 => IngressIngressVerifyOwnershipPreconditionFailedResponse::fromResponse($httpResponse),
default => IngressIngressVerifyOwnershipDefaultResponse::fromResponse($httpResponse),
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php

declare(strict_types=1);

namespace Mittwald\ApiClient\Generated\V2\Clients\Domain\IngressIngressVerifyOwnership;

use InvalidArgumentException;
use JsonSchema\Validator;
use Mittwald\ApiClient\Client\ResponseContainer;
use Mittwald\ApiClient\Generated\V2\Schemas\Commons\Error;
use Psr\Http\Message\ResponseInterface;

class IngressIngressVerifyOwnershipPreconditionFailedResponse implements ResponseContainer
{
/**
* Schema used to validate input for creating instances of this class
*
* @var array
*/
private static array $schema = [
'type' => 'object',
'required' => [
'body',
],
'properties' => [
'body' => [
'$ref' => '#/components/schemas/de.mittwald.v1.commons.Error',
],
],
];

/**
* @var Error
*/
private Error $body;

private ResponseInterface|null $httpResponse = null;

/**
* @param Error $body
*/
public function __construct(Error $body)
{
$this->body = $body;
}

/**
* @return Error
*/
public function getBody(): Error
{
return $this->body;
}

/**
* @param Error $body
* @return self
*/
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 IngressIngressVerifyOwnershipPreconditionFailedResponse Created instance
* @throws InvalidArgumentException
*/
public static function buildFromInput(array|object $input, bool $validate = true): IngressIngressVerifyOwnershipPreconditionFailedResponse
{
$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 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class ListProjectsOKResponse implements ResponseContainer
'disableReason' => [
'$ref' => '#/components/schemas/de.mittwald.v1.project.DisableReason',
],
'disabledAt' => [
'format' => 'date-time',
'type' => 'string',
],
'enabled' => [
'type' => 'boolean',
],
Expand Down Expand Up @@ -79,6 +83,10 @@ class ListProjectsOKResponse implements ResponseContainer
'status' => [
'$ref' => '#/components/schemas/de.mittwald.v1.project.ProjectStatus',
],
'statusSetAt' => [
'format' => 'date-time',
'type' => 'string',
],
],
'required' => [
'id',
Expand All @@ -91,6 +99,7 @@ class ListProjectsOKResponse implements ResponseContainer
'isReady',
'readiness',
'status',
'statusSetAt',
],
'type' => 'object',
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class ListProjectsOKResponseBodyItem
'disableReason' => [
'$ref' => '#/components/schemas/de.mittwald.v1.project.DisableReason',
],
'disabledAt' => [
'format' => 'date-time',
'type' => 'string',
],
'enabled' => [
'type' => 'boolean',
],
Expand Down Expand Up @@ -74,6 +78,10 @@ class ListProjectsOKResponseBodyItem
'status' => [
'$ref' => '#/components/schemas/de.mittwald.v1.project.ProjectStatus',
],
'statusSetAt' => [
'format' => 'date-time',
'type' => 'string',
],
],
'required' => [
'id',
Expand All @@ -86,6 +94,7 @@ class ListProjectsOKResponseBodyItem
'isReady',
'readiness',
'status',
'statusSetAt',
],
'type' => 'object',
];
Expand Down Expand Up @@ -115,6 +124,11 @@ class ListProjectsOKResponseBodyItem
*/
private ?DisableReason $disableReason = null;

/**
* @var DateTime|null
*/
private ?DateTime $disabledAt = null;

/**
* @var bool
*/
Expand Down Expand Up @@ -162,6 +176,11 @@ class ListProjectsOKResponseBodyItem
*/
private ProjectStatus $status;

/**
* @var DateTime
*/
private DateTime $statusSetAt;

/**
* @param DateTime $createdAt
* @param string $customerId
Expand All @@ -173,8 +192,9 @@ class ListProjectsOKResponseBodyItem
* @param DeprecatedProjectReadinessStatus $readiness
* @param string $shortId
* @param ProjectStatus $status
* @param DateTime $statusSetAt
*/
public function __construct(DateTime $createdAt, string $customerId, ListProjectsOKResponseBodyItemCustomerMeta $customerMeta, string $description, bool $enabled, string $id, bool $isReady, DeprecatedProjectReadinessStatus $readiness, string $shortId, ProjectStatus $status)
public function __construct(DateTime $createdAt, string $customerId, ListProjectsOKResponseBodyItemCustomerMeta $customerMeta, string $description, bool $enabled, string $id, bool $isReady, DeprecatedProjectReadinessStatus $readiness, string $shortId, ProjectStatus $status, DateTime $statusSetAt)
{
$this->createdAt = $createdAt;
$this->customerId = $customerId;
Expand All @@ -186,6 +206,7 @@ public function __construct(DateTime $createdAt, string $customerId, ListProject
$this->readiness = $readiness;
$this->shortId = $shortId;
$this->status = $status;
$this->statusSetAt = $statusSetAt;
}

/**
Expand Down Expand Up @@ -228,6 +249,14 @@ public function getDisableReason(): ?DisableReason
return $this->disableReason ?? null;
}

/**
* @return DateTime|null
*/
public function getDisabledAt(): ?DateTime
{
return $this->disabledAt ?? null;
}

/**
* @return bool
*/
Expand Down Expand Up @@ -301,6 +330,14 @@ public function getStatus(): ProjectStatus
return $this->status;
}

/**
* @return DateTime
*/
public function getStatusSetAt(): DateTime
{
return $this->statusSetAt;
}

/**
* @param DateTime $createdAt
* @return self
Expand Down Expand Up @@ -384,6 +421,29 @@ public function withoutDisableReason(): self
return $clone;
}

/**
* @param DateTime $disabledAt
* @return self
*/
public function withDisabledAt(DateTime $disabledAt): self
{
$clone = clone $this;
$clone->disabledAt = $disabledAt;

return $clone;
}

/**
* @return self
*/
public function withoutDisabledAt(): self
{
$clone = clone $this;
unset($clone->disabledAt);

return $clone;
}

/**
* @param bool $enabled
* @return self
Expand Down Expand Up @@ -567,6 +627,18 @@ public function withStatus(ProjectStatus $status): self
return $clone;
}

/**
* @param DateTime $statusSetAt
* @return self
*/
public function withStatusSetAt(DateTime $statusSetAt): self
{
$clone = clone $this;
$clone->statusSetAt = $statusSetAt;

return $clone;
}

/**
* Builds a new instance from an input array
*
Expand All @@ -590,6 +662,10 @@ public static function buildFromInput(array|object $input, bool $validate = true
if (isset($input->{'disableReason'})) {
$disableReason = DisableReason::from($input->{'disableReason'});
}
$disabledAt = null;
if (isset($input->{'disabledAt'})) {
$disabledAt = new DateTime($input->{'disabledAt'});
}
$enabled = (bool)($input->{'enabled'});
$id = $input->{'id'};
$imageRefId = null;
Expand All @@ -608,9 +684,11 @@ public static function buildFromInput(array|object $input, bool $validate = true
}
$shortId = $input->{'shortId'};
$status = ProjectStatus::from($input->{'status'});
$statusSetAt = new DateTime($input->{'statusSetAt'});

$obj = new self($createdAt, $customerId, $customerMeta, $description, $enabled, $id, $isReady, $readiness, $shortId, $status);
$obj = new self($createdAt, $customerId, $customerMeta, $description, $enabled, $id, $isReady, $readiness, $shortId, $status, $statusSetAt);
$obj->disableReason = $disableReason;
$obj->disabledAt = $disabledAt;
$obj->imageRefId = $imageRefId;
$obj->projectHostingId = $projectHostingId;
$obj->serverId = $serverId;
Expand All @@ -632,6 +710,9 @@ public function toJson(): array
if (isset($this->disableReason)) {
$output['disableReason'] = $this->disableReason->value;
}
if (isset($this->disabledAt)) {
$output['disabledAt'] = ($this->disabledAt)->format(DateTime::ATOM);
}
$output['enabled'] = $this->enabled;
$output['id'] = $this->id;
if (isset($this->imageRefId)) {
Expand All @@ -647,6 +728,7 @@ public function toJson(): array
}
$output['shortId'] = $this->shortId;
$output['status'] = $this->status->value;
$output['statusSetAt'] = ($this->statusSetAt)->format(DateTime::ATOM);

return $output;
}
Expand Down Expand Up @@ -679,5 +761,9 @@ public function __clone()
{
$this->createdAt = clone $this->createdAt;
$this->customerMeta = clone $this->customerMeta;
if (isset($this->disabledAt)) {
$this->disabledAt = clone $this->disabledAt;
}
$this->statusSetAt = clone $this->statusSetAt;
}
}
Loading

0 comments on commit 0283b8e

Please sign in to comment.