swagger-php
Generate interactive OpenAPI documentation for your RESTful API using doctrine annotations.
For a full list of supported annotations, please have look at the OpenApiAnnotations namespace or the documentation website.
Features
Compatible with the OpenAPI 3.0 specification.
Extracts information from code & existing phpdoc annotations.
Command-line interface available.
Documentation site with a getting started guide.
Exceptional error reporting (with hints, context)
Installation (with Composer)
composer require zircote/swagger-php
For cli usage from anywhere install swagger-php globally and make sure to place the ~/.composer/vendor/bin directory in your PATH so the openapi executable can be located by your system.
composer global require zircote/swagger-php
Usage
Add annotations to your php files.
/**
* @OAInfo(title=”My First API”, version=”0.1″)
*/
/**
* @OAGet(
* path=”/api/resource.json”,
* @OAResponse(response=”200″, description=”An example resource”)
* )
*/
Visit the Documentation website for the Getting started guide or look at the Examples directory for more examples.
Usage from php
Generate always-up-to-date documentation.
toYaml();
Documentation of how to use the Generator class can be found in the Generator Migration guide.
Usage from the Command Line Interface
The openapi command line interface can be used to generate the documentation to a static yaml/json file.
./vendor/bin/openapi –help
Usage from the Deserializer
Generate the OpenApi annotation object from a json string, which makes it easier to manipulate objects programmatically.
deserialize($jsonString, ‘OpenApiAnnotationsOpenApi’);
echo $openapi->toJson();
Usage from docker
Generate the swagger documentation to a static json file.
docker run -v “$PWD”:/app -it tico/swagger-php –help
More on OpenApi & Swagger
https://swagger.io
https://www.openapis.org
OpenApi Documentation
OpenApi Specification
Related projects
Contributing
Feel free to submit Github Issues
or pull requests.
The documentation website is build from the docs folder with vuepress.
Make sure pull requests pass PHPUnit
and PHP-CS-Fixer (PSR-2) tests.
To run both unit tests and linting execute:
composer test
Running unit tests only:
./bin/phpunit
Running linting only:
composer lint
To make php-cs-fixer fix linting errors:
composer cs