Skip to content

Commit 0c611b4

Browse files
authored
Merge pull request #124 from DoclerLabs/openapi3.1
openapi 3.1
2 parents a4275bc + e9ee3c0 commit 0c611b4

File tree

78 files changed

+11544
-85
lines changed

Some content is hidden

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

78 files changed

+11544
-85
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [11.0.0] - 2025.04.21
8+
### Added
9+
- Support for OpenAPI 3.1
10+
11+
### Changed
12+
- cebe/php-openapi dependency to devizzent/cebe-php-openapi
13+
714
## [10.10.1] - 2025.02.19
815
### Fixed
916
- avoid having `&` in request body when using `application/x-www-form-urlencoded`

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"ext-dom": "*",
1919
"ext-json": "*",
2020
"ext-xml": "*",
21-
"cebe/php-openapi": "^1.4",
21+
"devizzent/cebe-php-openapi": "^1.1",
2222
"docler-labs/api-client-exception": "^1.0.1 || ^2.0",
2323
"friendsofphp/php-cs-fixer": "^3.0",
2424
"guzzlehttp/psr7": "^1.6",

composer.lock

+78-71
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenApi\PetStoreApiConsumer;
6+
7+
use GuzzleHttp\Client;
8+
use OpenApi\PetStoreClient\Request\DeletePetRequest;
9+
use OpenApi\PetStoreClient\Request\FindPetsByStatusRequest;
10+
use OpenApi\PetStoreClient\Request\GetPetByIdRequest;
11+
use OpenApi\PetStoreClient\Request\UpdatePetRequest;
12+
use OpenApi\PetStoreClient\Schema\Pet;
13+
use OpenApi\PetStoreClient\SwaggerPetstoreOpenAPI31ClientFactory;
14+
use UnexpectedValueException;
15+
16+
class PetStoreApiConsumer
17+
{
18+
private $petClient;
19+
20+
public function __construct()
21+
{
22+
$this->petClient = (new SwaggerPetstoreOpenAPI31ClientFactory())
23+
->create(new Client(['base_uri' => 'http://pet.wiremock:8080']));
24+
}
25+
26+
public function findPetsByStatus(): Pet
27+
{
28+
$request = new FindPetsByStatusRequest();
29+
$request->setStatus('sold');
30+
$result = $this->petClient->findPetsByStatus($request);
31+
if ($result === null || $result->count() === 0) {
32+
throw new UnexpectedValueException('findPetsByStatus should be not null or empty');
33+
}
34+
35+
return $result->first();
36+
}
37+
38+
public function getPetById(int $petId, string $apiKey): Pet
39+
{
40+
$request = new GetPetByIdRequest($petId, $apiKey);
41+
$result = $this->petClient->getPetById($request);
42+
if ($result === null) {
43+
throw new UnexpectedValueException('getPetById should not be null');
44+
}
45+
46+
return $result;
47+
}
48+
49+
public function updatePet(Pet $pet, string $mimeType): void
50+
{
51+
$request = new UpdatePetRequest($pet, $mimeType);
52+
$result = $this->petClient->updatePet($request);
53+
if ($result === null) {
54+
printf('getPetById failed, result: %s', json_encode($result, JSON_THROW_ON_ERROR)) || exit(1);
55+
}
56+
}
57+
58+
public function deletePet(int $petId): void
59+
{
60+
$request = new DeletePetRequest($petId);
61+
$this->petClient->deletePet($request);
62+
}
63+
}

example3_1/PetStoreClient/README.md

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Swagger Petstore - OpenAPI 3.1 client
2+
3+
This client is generated using [docler-labs/api-client-generator](https://github.com/DoclerLabs/api-client-generator) based on the OpenAPI specification of the Swagger Petstore - OpenAPI 3.1.
4+
5+
You can generate the client with the following command:
6+
```bash
7+
docker run -it --rm \
8+
-v <local-path-to-api>/doc/openapi.yaml:/openapi.yaml:ro \
9+
-v <local-path-to-client>:/client \
10+
-e NAMESPACE=OpenApi\\PetStoreClient \
11+
-e OPENAPI=/openapi.yaml \
12+
-e OUTPUT_DIR=/client \
13+
-e PACKAGE=openapi/pet-store-client \
14+
-e CLIENT_PHP_VERSION=7.4 \
15+
dhlabs/api-client-generator
16+
```
17+
18+
## Usage
19+
20+
```php
21+
<?php declare(strict_types=1);
22+
23+
use OpenApi\PetStoreClient\SwaggerPetstoreOpenAPI31ClientFactory;
24+
use OpenApi\PetStoreClient\Request\UpdatePetRequest;
25+
26+
/**
27+
* If using Guzzle 6, make sure to configure Guzzle to not throw exceptions
28+
* on HTTP error status codes, or this client will violate PSR-18.
29+
* e.g. new Client(['base_uri' => $baseUri, 'http_errors' => false, ...])
30+
*/
31+
$client = ...; // any PSR-18 HTTP CLIENT
32+
33+
$factory = new SwaggerPetstoreOpenAPI31ClientFactory();
34+
$client = $factory->create($client);
35+
36+
$request = new UpdatePetRequest();
37+
$result = $client->updatePet($request);
38+
```
39+
40+
## Operations
41+
42+
### pet
43+
Endpoints:
44+
- **updatePet** - Update an existing pet by Id
45+
- **addPet** - Add a new pet to the store
46+
- **findPetsByStatus** - Multiple status values can be provided with comma separated strings
47+
- **findPetsByTags** - Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
48+
- **getPetById** - Returns a single pet
49+
- **updatePetWithForm**
50+
- **deletePet**
51+
52+
### store
53+
Endpoints:
54+
- **getInventory** - Returns a map of status codes to quantities
55+
- **placeOrder** - Place a new order in the store
56+
- **getOrderById** - For valid response try integer IDs with value &lt;= 5 or &gt; 10. Other values will generated exceptions
57+
- **deleteOrder** - For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
58+
59+
### user
60+
Endpoints:
61+
- **createUser** - This can only be done by the logged in user.
62+
- **createUsersWithListInput** - Creates list of users with given input array
63+
- **loginUser**
64+
- **logoutUser**
65+
- **getUserByName**
66+
- **updateUser** - This can only be done by the logged in user.
67+
- **deleteUser** - This can only be done by the logged in user.
68+
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "openapi/pet-store-client",
3+
"description": "Client library for Swagger Petstore - OpenAPI 3.1",
4+
"license": "Apache 2.0",
5+
"keywords": [
6+
"api-client"
7+
],
8+
"config": {
9+
"sort-packages": true
10+
},
11+
"require": {
12+
"php": "^7.4 || ^8.0",
13+
"docler-labs/api-client-exception": "^1.0 || ^2.0",
14+
"ext-dom": "*",
15+
"ext-json": "*",
16+
"guzzlehttp/psr7": "^1.6 || ^2.6",
17+
"pimple/pimple": "^3.5",
18+
"psr/container": "^1.0 || ^2.0",
19+
"psr/http-client": "^1.0"
20+
},
21+
"autoload": {
22+
"psr-4": {
23+
"OpenApi\\PetStoreClient\\": "src/"
24+
}
25+
},
26+
"suggest": {
27+
"guzzlehttp/guzzle": "PSR-18 provided by Guzzle 7",
28+
"php-http/guzzle6-adapter": "PSR-18 wrapper for Guzzle 6"
29+
}
30+
}

0 commit comments

Comments
 (0)