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 May 7, 2024
1 parent f2d2294 commit 72bce88
Show file tree
Hide file tree
Showing 24 changed files with 1,497 additions and 1,720 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class CheckDomainTransferabilityRequest
],
'required' => [
'domain',
'authCode',
],
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,21 @@ class CheckDomainTransferabilityRequestBody
],
'required' => [
'domain',
'authCode',
],
];

private string $authCode;
private ?string $authCode = null;

private string $domain;

public function __construct(string $authCode, string $domain)
public function __construct(string $domain)
{
$this->authCode = $authCode;
$this->domain = $domain;
}

public function getAuthCode(): string
public function getAuthCode(): ?string
{
return $this->authCode;
return $this->authCode ?? null;
}

public function getDomain(): string
Expand All @@ -62,6 +60,14 @@ public function withAuthCode(string $authCode): self
return $clone;
}

public function withoutAuthCode(): self
{
$clone = clone $this;
unset($clone->authCode);

return $clone;
}

public function withDomain(string $domain): self
{
$validator = new Validator();
Expand Down Expand Up @@ -91,11 +97,14 @@ public static function buildFromInput(array|object $input, bool $validate = true
static::validateInput($input);
}

$authCode = $input->{'authCode'};
$authCode = null;
if (isset($input->{'authCode'})) {
$authCode = $input->{'authCode'};
}
$domain = $input->{'domain'};

$obj = new self($authCode, $domain);

$obj = new self($domain);
$obj->authCode = $authCode;
return $obj;
}

Expand All @@ -107,7 +116,9 @@ public static function buildFromInput(array|object $input, bool $validate = true
public function toJson(): array
{
$output = [];
$output['authCode'] = $this->authCode;
if (isset($this->authCode)) {
$output['authCode'] = $this->authCode;
}
$output['domain'] = $this->domain;

return $output;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php

declare(strict_types=1);

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

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

class CreateDomainAuthCodePreconditionFailedResponse implements ResponseContainer
{
/**
* Schema used to validate input for creating instances of this class
*/
private static array $schema = [
'type' => '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 CreateDomainAuthCodePreconditionFailedResponse Created instance
* @throws InvalidArgumentException
*/
public static function buildFromInput(array|object $input, bool $validate = true): CreateDomainAuthCodePreconditionFailedResponse
{
$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;
}
}
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 @@ -39,6 +39,7 @@
use Mittwald\ApiClient\Generated\V2\Clients\Domain\CreateDomainAuthCode\CreateDomainAuthCodeCreatedResponse;
use Mittwald\ApiClient\Generated\V2\Clients\Domain\CreateDomainAuthCode\CreateDomainAuthCodeDefaultResponse;
use Mittwald\ApiClient\Generated\V2\Clients\Domain\CreateDomainAuthCode\CreateDomainAuthCodeNotFoundResponse;
use Mittwald\ApiClient\Generated\V2\Clients\Domain\CreateDomainAuthCode\CreateDomainAuthCodePreconditionFailedResponse;
use Mittwald\ApiClient\Generated\V2\Clients\Domain\CreateDomainAuthCode\CreateDomainAuthCodeRequest;
use Mittwald\ApiClient\Generated\V2\Clients\Domain\DeclareNameserversV2Deprecated\DeclareNameserversV2DeprecatedBadRequestResponse;
use Mittwald\ApiClient\Generated\V2\Clients\Domain\DeclareNameserversV2Deprecated\DeclareNameserversV2DeprecatedDefaultResponse;
Expand Down Expand Up @@ -703,6 +704,7 @@ public function createDomainAuthCode(CreateDomainAuthCodeRequest $request): Crea
throw new UnexpectedResponseException(match ($httpResponse->getStatusCode()) {
400 => CreateDomainAuthCodeBadRequestResponse::fromResponse($httpResponse),
404 => CreateDomainAuthCodeNotFoundResponse::fromResponse($httpResponse),
412 => CreateDomainAuthCodePreconditionFailedResponse::fromResponse($httpResponse),
default => CreateDomainAuthCodeDefaultResponse::fromResponse($httpResponse),
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use InvalidArgumentException;
use JsonSchema\Validator;
use Mittwald\ApiClient\Client\ResponseContainer;
use Mittwald\ApiClient\Generated\V2\Schemas\Ingress\Ingress;
use Mittwald\ApiClient\Generated\V2\Schemas\Ingress\IngressDeprecated;
use Psr\Http\Message\ResponseInterface;

class IngressListIngressesV2DeprecatedOKResponse implements ResponseContainer
Expand All @@ -23,38 +23,38 @@ class IngressListIngressesV2DeprecatedOKResponse implements ResponseContainer
'properties' => [
'body' => [
'items' => [
'$ref' => '#/components/schemas/de.mittwald.v1.ingress.Ingress',
'$ref' => '#/components/schemas/de.mittwald.v1.ingress.IngressDeprecated',
],
'type' => 'array',
],
],
];

/**
* @var Ingress[]
* @var IngressDeprecated[]
*/
private array $body;

private ResponseInterface|null $httpResponse = null;

/**
* @param Ingress[] $body
* @param IngressDeprecated[] $body
*/
public function __construct(array $body)
{
$this->body = $body;
}

/**
* @return Ingress[]
* @return IngressDeprecated[]
*/
public function getBody(): array
{
return $this->body;
}

/**
* @param Ingress[] $body
* @param IngressDeprecated[] $body
*/
public function withBody(array $body): self
{
Expand All @@ -79,7 +79,7 @@ public static function buildFromInput(array|object $input, bool $validate = true
static::validateInput($input);
}

$body = array_map(fn (array|object $i): Ingress => Ingress::buildFromInput($i, validate: $validate), $input->{'body'});
$body = array_map(fn (array|object $i): IngressDeprecated => IngressDeprecated::buildFromInput($i, validate: $validate), $input->{'body'});

$obj = new self($body);

Expand All @@ -94,7 +94,7 @@ public static function buildFromInput(array|object $input, bool $validate = true
public function toJson(): array
{
$output = [];
$output['body'] = array_map(fn (Ingress $i): array => $i->toJson(), $this->body);
$output['body'] = array_map(fn (IngressDeprecated $i): array => $i->toJson(), $this->body);

return $output;
}
Expand Down
Loading

0 comments on commit 72bce88

Please sign in to comment.