Skip to content

Commit

Permalink
Refresh samples
Browse files Browse the repository at this point in the history
  • Loading branch information
ybelenko committed Apr 29, 2024
1 parent 9539ad3 commit 6db8e54
Show file tree
Hide file tree
Showing 33 changed files with 2,650 additions and 144 deletions.
6 changes: 6 additions & 0 deletions samples/client/echo_api/php-nextgen/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ src/Api/QueryApi.php
src/Api/QueryApiInterface.php
src/ApiException.php
src/ClientBuilder.php
src/Collection.php
src/CollectionInterface.php
src/Configuration.php
src/HeaderSelector.php
src/Model/Bird.php
Expand All @@ -53,4 +55,8 @@ src/Model/Tag.php
src/Model/TestFormObjectMultipartRequestMarker.php
src/Model/TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter.php
src/Model/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.php
src/NotFoundException.php
src/ObjectSerializer.php
src/PaginationInterface.php
src/UnauthorizedException.php
src/ValidationFailedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* The version of the OpenAPI document: 0.1.0
* Contact: team@openapitools.org
* @generated Generated by: https://openapi-generator.tech
* OpenAPI Generator version: 7.3.0-SNAPSHOT
* Generator version: 7.6.0-SNAPSHOT
*/

/**
Expand Down
275 changes: 275 additions & 0 deletions samples/client/echo_api/php-nextgen/src/Api/BodyApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -2315,6 +2315,281 @@ public function testEchoBodyPetResponseStringRequest(
);
}

/**
* {@inheritdoc}
*/
public function testEchoBodyStringEnum(
?string $body = null,
string $contentType = self::contentTypes['testEchoBodyStringEnum'][0]
): \OpenAPI\Client\Model\StringEnumRef
{
list($response) = $this->testEchoBodyStringEnumWithHttpInfo($body, $contentType);
return $response;
}

/**
* {@inheritdoc}
*/
public function testEchoBodyStringEnumWithHttpInfo(
?string $body = null,
string $contentType = self::contentTypes['testEchoBodyStringEnum'][0]
): array
{
$request = $this->testEchoBodyStringEnumRequest($body, $contentType);

try {
$options = $this->createHttpClientOption();
try {
$response = $this->client->send($request, $options);
} catch (RequestException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
(int) $e->getCode(),
$e->getResponse() ? $e->getResponse()->getHeaders() : null,
$e->getResponse() ? (string) $e->getResponse()->getBody() : null
);
} catch (ConnectException $e) {
throw new ApiException(
"[{$e->getCode()}] {$e->getMessage()}",
(int) $e->getCode(),
null,
null
);
}

$statusCode = $response->getStatusCode();

if ($statusCode < 200 || $statusCode > 299) {
throw new ApiException(
sprintf(
'[%d] Error connecting to the API (%s)',
$statusCode,
(string) $request->getUri()
),
$statusCode,
$response->getHeaders(),
(string) $response->getBody()
);
}

switch($statusCode) {
case 200:
if ('\OpenAPI\Client\Model\StringEnumRef' === '\SplFileObject') {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ('\OpenAPI\Client\Model\StringEnumRef' !== 'string') {
try {
$content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
} catch (\JsonException $exception) {
throw new ApiException(
sprintf(
'Error JSON decoding server response (%s)',
$request->getUri()
),
$statusCode,
$response->getHeaders(),
$content
);
}
}
}

return [
ObjectSerializer::deserialize($content, '\OpenAPI\Client\Model\StringEnumRef', []),
$response->getStatusCode(),
$response->getHeaders()
];
}

$returnType = '\OpenAPI\Client\Model\StringEnumRef';
if ($returnType === '\SplFileObject') {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
try {
$content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
} catch (\JsonException $exception) {
throw new ApiException(
sprintf(
'Error JSON decoding server response (%s)',
$request->getUri()
),
$statusCode,
$response->getHeaders(),
$content
);
}
}
}

return [
ObjectSerializer::deserialize($content, $returnType, []),
$response->getStatusCode(),
$response->getHeaders()
];

} catch (ApiException $e) {
switch ($e->getCode()) {
case 200:
$data = ObjectSerializer::deserialize(
$e->getResponseBody(),
'\OpenAPI\Client\Model\StringEnumRef',
$e->getResponseHeaders()
);
$e->setResponseObject($data);
break;
}
throw $e;
}
}

/**
* {@inheritdoc}
*/
public function testEchoBodyStringEnumAsync(
?string $body = null,
string $contentType = self::contentTypes['testEchoBodyStringEnum'][0]
): PromiseInterface
{
return $this->testEchoBodyStringEnumAsyncWithHttpInfo($body, $contentType)
->then(
function ($response) {
return $response[0];
}
);
}

/**
* {@inheritdoc}
*/
public function testEchoBodyStringEnumAsyncWithHttpInfo(
$body = null,
string $contentType = self::contentTypes['testEchoBodyStringEnum'][0]
): PromiseInterface
{
$returnType = '\OpenAPI\Client\Model\StringEnumRef';
$request = $this->testEchoBodyStringEnumRequest($body, $contentType);

return $this->client
->sendAsync($request, $this->createHttpClientOption())
->then(
function ($response) use ($returnType) {
if ($returnType === '\SplFileObject') {
$content = $response->getBody(); //stream goes to serializer
} else {
$content = (string) $response->getBody();
if ($returnType !== 'string') {
$content = json_decode($content);
}
}

return [
ObjectSerializer::deserialize($content, $returnType, []),
$response->getStatusCode(),
$response->getHeaders()
];
},
function ($exception) {
$response = $exception->getResponse();
$statusCode = $response->getStatusCode();
throw new ApiException(
sprintf(
'[%d] Error connecting to the API (%s)',
$statusCode,
$exception->getRequest()->getUri()
),
$statusCode,
$response->getHeaders(),
(string) $response->getBody()
);
}
);
}

/**
* {@inheritdoc}
*/
public function testEchoBodyStringEnumRequest(
$body = null,
string $contentType = self::contentTypes['testEchoBodyStringEnum'][0]
): Request
{



$resourcePath = '/echo/body/string_enum';
$formParams = [];
$queryParams = [];
$headerParams = [];
$httpBody = '';
$multipart = false;





$headers = $this->headerSelector->selectHeaders(
['application/json', ],
$contentType,
$multipart
);

// for model (json/xml)
if (isset($body)) {
if (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the body
$httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($body));
} else {
$httpBody = $body;
}
} elseif (count($formParams) > 0) {
if ($multipart) {
$multipartContents = [];
foreach ($formParams as $formParamName => $formParamValue) {
$formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
foreach ($formParamValueItems as $formParamValueItem) {
$multipartContents[] = [
'name' => $formParamName,
'contents' => $formParamValueItem
];
}
}
// for HTTP post (form)
$httpBody = new MultipartStream($multipartContents);

} elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
# if Content-Type contains "application/json", json_encode the form parameters
$httpBody = \GuzzleHttp\Utils::jsonEncode($formParams);
} else {
// for HTTP post (form)
$httpBody = ObjectSerializer::buildQuery($formParams);
}
}


$defaultHeaders = [];
if ($this->config->getUserAgent()) {
$defaultHeaders['User-Agent'] = $this->config->getUserAgent();
}

$headers = array_merge(
$defaultHeaders,
$headerParams,
$headers
);

$operationHost = $this->config->getHost();
$query = ObjectSerializer::buildQuery($queryParams);
return new Request(
'POST',
$operationHost . $resourcePath . ($query ? "?{$query}" : ''),
$headers,
$httpBody
);
}

/**
* {@inheritdoc}
*/
Expand Down
Loading

0 comments on commit 6db8e54

Please sign in to comment.