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 Apr 30, 2024
1 parent 08dbc71 commit f2d2294
Show file tree
Hide file tree
Showing 5 changed files with 739 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Generated/V2/Clients/Contract/ContractClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
use Mittwald\ApiClient\Generated\V2\Clients\Contract\OrderGetOrder\OrderGetOrderRequest;
use Mittwald\ApiClient\Generated\V2\Clients\Contract\OrderListCustomerOrders\OrderListCustomerOrdersOKResponse;
use Mittwald\ApiClient\Generated\V2\Clients\Contract\OrderListCustomerOrders\OrderListCustomerOrdersRequest;
use Mittwald\ApiClient\Generated\V2\Clients\Contract\OrderListOrders\OrderListOrdersOKResponse;
use Mittwald\ApiClient\Generated\V2\Clients\Contract\OrderListOrders\OrderListOrdersRequest;
use Mittwald\ApiClient\Generated\V2\Clients\Contract\OrderListProjectOrders\OrderListProjectOrdersOKResponse;
use Mittwald\ApiClient\Generated\V2\Clients\Contract\OrderListProjectOrders\OrderListProjectOrdersRequest;
use Mittwald\ApiClient\Generated\V2\Clients\Contract\OrderPreviewOrder\OrderPreviewOrderRequest;
Expand Down Expand Up @@ -297,6 +299,17 @@ public function orderGetOrder(OrderGetOrderRequest $request): OrderGetOrderOKRes
* @param OrderListCustomerOrdersRequest $request An object representing the request for this operation
*/
public function orderListCustomerOrders(OrderListCustomerOrdersRequest $request): OrderListCustomerOrdersOKResponse;
/**
* Get list of Orders.
*
* The list of Orders the User has access to.
*
* @see https://developer.mittwald.de/reference/v2/#tag/Contract/operation/order-list-orders
* @throws GuzzleException
* @throws UnexpectedResponseException
* @param OrderListOrdersRequest $request An object representing the request for this operation
*/
public function orderListOrders(OrderListOrdersRequest $request): OrderListOrdersOKResponse;
/**
* Get list of Orders of a Project.
*
Expand Down
25 changes: 25 additions & 0 deletions src/Generated/V2/Clients/Contract/ContractClientImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
use Mittwald\ApiClient\Generated\V2\Clients\Contract\OrderListCustomerOrders\OrderListCustomerOrdersDefaultResponse;
use Mittwald\ApiClient\Generated\V2\Clients\Contract\OrderListCustomerOrders\OrderListCustomerOrdersOKResponse;
use Mittwald\ApiClient\Generated\V2\Clients\Contract\OrderListCustomerOrders\OrderListCustomerOrdersRequest;
use Mittwald\ApiClient\Generated\V2\Clients\Contract\OrderListOrders\OrderListOrdersDefaultResponse;
use Mittwald\ApiClient\Generated\V2\Clients\Contract\OrderListOrders\OrderListOrdersOKResponse;
use Mittwald\ApiClient\Generated\V2\Clients\Contract\OrderListOrders\OrderListOrdersRequest;
use Mittwald\ApiClient\Generated\V2\Clients\Contract\OrderListProjectOrders\OrderListProjectOrdersDefaultResponse;
use Mittwald\ApiClient\Generated\V2\Clients\Contract\OrderListProjectOrders\OrderListProjectOrdersOKResponse;
use Mittwald\ApiClient\Generated\V2\Clients\Contract\OrderListProjectOrders\OrderListProjectOrdersRequest;
Expand Down Expand Up @@ -671,6 +674,28 @@ public function orderListCustomerOrders(OrderListCustomerOrdersRequest $request)
});
}

/**
* Get list of Orders.
*
* The list of Orders the User has access to.
*
* @see https://developer.mittwald.de/reference/v2/#tag/Contract/operation/order-list-orders
* @throws GuzzleException
* @throws UnexpectedResponseException
* @param OrderListOrdersRequest $request An object representing the request for this operation
*/
public function orderListOrders(OrderListOrdersRequest $request): OrderListOrdersOKResponse
{
$httpRequest = new Request(OrderListOrdersRequest::method, $request->buildUrl());
$httpResponse = $this->client->send($httpRequest, $request->buildRequestOptions());
if ($httpResponse->getStatusCode() === 200) {
return OrderListOrdersOKResponse::fromResponse($httpResponse);
}
throw new UnexpectedResponseException(match ($httpResponse->getStatusCode()) {
default => OrderListOrdersDefaultResponse::fromResponse($httpResponse),
});
}

/**
* Get list of Orders of a Project.
*
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\Contract\OrderListOrders;

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

class OrderListOrdersDefaultResponse 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 OrderListOrdersDefaultResponse Created instance
* @throws InvalidArgumentException
*/
public static function buildFromInput(array|object $input, bool $validate = true): OrderListOrdersDefaultResponse
{
$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;
}
}
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\Contract\OrderListOrders;

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

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

/**
* @var CustomerOrder[]
*/
private array $body;

private ResponseInterface|null $httpResponse = null;

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

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

/**
* @param CustomerOrder[] $body
*/
public function withBody(array $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 OrderListOrdersOKResponse Created instance
* @throws InvalidArgumentException
*/
public static function buildFromInput(array|object $input, bool $validate = true): OrderListOrdersOKResponse
{
$input = is_array($input) ? Validator::arrayToObjectRecursive($input) : $input;
if ($validate) {
static::validateInput($input);
}

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

$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'] = array_map(fn (CustomerOrder $i): array => $i->toJson(), $this->body);

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;
}
}
Loading

0 comments on commit f2d2294

Please sign in to comment.