vanengers / php-openapi-client-generator
Generate a PHP client for an OPENAPI specification
v1.1.0
2024-04-21 16:53 UTC
Requires
- php: >=7.4
- ext-dom: *
- ext-json: *
- ext-xml: *
- cebe/php-openapi: ^1.4
- composer/composer: ^2.1
- docler-labs/api-client-exception: ^1.0.1 || ^2.0
- friendsofphp/php-cs-fixer: ^2.16
- guzzlehttp/psr7: ^1.6
- icecave/parity: ^3.0
- mikey179/vfsstream: ^1.6
- nikic/php-parser: ^4.10
- nyholm/psr7: ^1.3
- php-coveralls/php-coveralls: ^2.2
- phpstan/phpstan: ^0.12.32
- phpunit/phpunit: ^9.5
- pimple/pimple: ^3.3
- psr/container: ^1.0
- psr/http-client: ^1.0
- psr/http-message: ^1.0
- roave/security-advisories: dev-latest
- symfony/console: ^5.1
- symfony/filesystem: ^5.1
- symfony/yaml: ^5.1
- twig/twig: ^3.0
- webmozart/assert: ^1.11
README
Generate a PHP client for an OPENAPI specification
Installation
composer require --dev vanengers/php-openapi-client-generator
Usage
OPENAPI=http://127.0.0.1:8000/docs.json NAMESPACE=VendorName\\PackageName\\Generated OUTPUT_DIR=src/Generated ./bin/api-client-generator generate
Specify the openapi specifications JSON file
OPENAPI=http://127.0.0.1:8000/docs.json
Specify the namespace for the generated classes
NAMESPACE=VendorName\\PackageName\\Generated
Specify the output directory for the generated classes
OUTPUT_DIR=src/Generated
Run the generator
./bin/api-client-generator generate
Example client is generated; SampleClient.php
You will need to finish the implementation of the client yourself. This is for generation of the login methods, which may differ per API. And you will need to add the correct namespace to the generated classes. You can also add your own methods to save and retrieve a Saved Token.
public function login()
{ ... }
callable $saveToken = fn (string $token) => saveInterally($token);