Skip to content

Commit 0e72f16

Browse files
authored
Merge pull request #86 from Yarre/support-optional-nullable
Support optional nullable
2 parents f6c6ac4 + 00ca723 commit 0e72f16

File tree

81 files changed

+1288
-446
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1288
-446
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions

README.md

Lines changed: 1 addition & 0 deletions
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace OpenApi\PetStoreApiConsumer;
4+
5+
use GuzzleHttp\Client;
6+
use OpenApi\PetStoreClient\Request\DeletePetRequest;
7+
use OpenApi\PetStoreClient\Request\FindPetsByStatusRequest;
8+
use OpenApi\PetStoreClient\Request\GetPetByIdRequest;
9+
use OpenApi\PetStoreClient\Request\UpdatePetRequest;
10+
use OpenApi\PetStoreClient\Schema\Pet;
11+
use OpenApi\PetStoreClient\SwaggerPetstoreOpenAPI3ClientFactory;
12+
use UnexpectedValueException;
13+
14+
class PetStoreApiConsumer
15+
{
16+
private $petClient;
17+
18+
public function __construct()
19+
{
20+
$this->petClient = (new SwaggerPetstoreOpenAPI3ClientFactory())
21+
->create(new Client(['base_uri' => 'http://pet.wiremock:8080']));
22+
}
23+
24+
public function findPetsByStatus(): Pet
25+
{
26+
$request = new FindPetsByStatusRequest();
27+
$request->setStatus('sold');
28+
$result = $this->petClient->findPetsByStatus($request);
29+
if ($result === null || $result->count() === 0) {
30+
throw new UnexpectedValueException('findPetsByStatus should be not null or empty');
31+
}
32+
33+
return $result->first();
34+
}
35+
36+
public function getPetById(int $petId): Pet
37+
{
38+
$request = new GetPetByIdRequest($petId);
39+
$result = $this->petClient->getPetById($request);
40+
if ($result === null) {
41+
throw new UnexpectedValueException('getPetById should not be null');
42+
}
43+
44+
return $result;
45+
}
46+
47+
public function updatePet(Pet $pet, string $mimeType): void
48+
{
49+
$request = new UpdatePetRequest($pet, $mimeType);
50+
$result = $this->petClient->updatePet($request);
51+
if ($result === null) {
52+
printf('getPetById failed, result: %s', json_encode($result, JSON_THROW_ON_ERROR)) || exit(1);
53+
}
54+
}
55+
56+
public function deletePet(int $petId): void
57+
{
58+
$request = new DeletePetRequest($petId);
59+
$this->petClient->deletePet($request);
60+
}
61+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"require": {
1212
"php": ">=7.4",
13-
"docler-labs/api-client-exception": "^1.0",
13+
"docler-labs/api-client-exception": "^1.0|^2.0",
1414
"ext-dom": "*",
1515
"ext-json": "*",
1616
"guzzlehttp/psr7": "^1.6",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,11 @@
10891089
"pending",
10901090
"sold"
10911091
]
1092+
},
1093+
"chipped": {
1094+
"type": "boolean",
1095+
"description": "Is pet is chipped or not. Null means there is no information",
1096+
"nullable": true
10921097
}
10931098
},
10941099
"xml": {
File renamed without changes.

example/gen/src/Request/AuthenticationCredentials.php renamed to example/PetStoreClient/src/Request/AuthenticationCredentials.php

File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)