API client generator is a console application capable of auto-generating a PSR18/PSR7 compliant API client based on OpenAPI v3 specification according to PHP best practices and your code style standards.
allOf
, oneOf
, anyOf
OpenAPI parameters.Check out example directory to see the code generated by api-client-generator.
Try it out:
cd example && \
composer install && \
php test-example.php
$ docker run -it \
-v {path-to-specification}/openapi.yaml:/openapi.yaml:ro \
-v {path-to-client}/some-api-client:/client \
-e NAMESPACE=Group\\SomeApiClient \
-e OPENAPI=/openapi.yaml \
-e OUTPUT_DIR=/client \
-e PACKAGE=group/some-api-client \
dhlabs/api-client-generator
Preconditions: PHP 7.4
Clone the repository and run:
OPENAPI={path-to-specification}/openapi.yaml NAMESPACE=Group\SomeApiClient PACKAGE=group/some-api-client OUTPUT_DIR={path-to-client}/generated ./bin/api-client-generator generate
The following environment variables are available:
Variable | Required | Default | Enum | Example | Description |
---|---|---|---|---|---|
NAMESPACE |
yes | Group\SomeApiClient | |||
PACKAGE |
yes | group/some-api-client | |||
OPENAPI |
yes | /api/openapi.yaml | |||
OUTPUT_DIR |
yes | /client | |||
CODE_STYLE |
no | {path-to-repository}/.php-cs-fixer.php.dist | /client/myCodeStyle.php | ||
SOURCE_DIR |
no | src | src | ||
CLIENT_PHP_VERSION |
no | 7.4 | 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3 | 7.4 | |
COMPOSER_JSON_TEMPLATE_DIR |
no | {path-to-repository}/template/composer.json.twig | /path/composer.json.twig | ||
README_MD_TEMPLATE_DIR |
no | {path-to-repository}/template/README.md.twig | /path/README.md.twig | ||
HTTP_MESSAGE |
no | guzzle | guzzle, nyholm | nyholm | |
CONTAINER |
no | pimple | pimple | pimple | |
INCLUDE_TAGS |
no | tag1,tag2,tag3 | tag whitelist to select generated operations | ||
EXCLUDE_TAGS |
no | tag1,tag2,tag3 | tag blacklist to select generated operations |
$ composer install
$ make test
(check make
for all available routines).