appserver-io / swagger-php
swagger-php - Generate interactive documentation for your RESTful API using phpdoc annotations
Requires
- php: >=7.0
- doctrine/annotations: *
- symfony/finder: >=2.2
- symfony/yaml: >=3.3
Requires (Dev)
- phpunit/phpunit: >=6.3
- squizlabs/php_codesniffer: >=3.3
- zendframework/zend-form: <2.8
- dev-master
- 3.0.2
- 3.0.1
- 3.0.0
- 2.x-dev
- 2.0.13
- 2.0.12
- 2.0.11
- 2.0.10
- 2.0.9
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.0.0
- 0.9.6
- 0.9.5
- 0.9.4
- 0.9.3
- 0.9.2
- 0.9.1
- 0.9.0
- 0.8.3
- 0.8.2
- 0.8.1
- 0.8.0
- 0.7.3
- 0.7.2
- 0.7.1
- 0.7.0
- 0.6.1
- 0.6.0
- 0.4.3
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.0
- 0.2.1
- 0.1.0
- dev-example-dynamic-references
This package is auto-updated.
Last update: 2024-10-21 20:21:53 UTC
README
swagger-php
Generate interactive OpenAPI documentation for your RESTful API using doctrine annotations.
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.
/** * @OA\Info(title="My First API", version="0.1") */ /** * @OA\Get( * path="/api/resource.json", * @OA\Response(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.
<?php require("vendor/autoload.php"); $openapi = \OpenApi\scan('/path/to/project'); header('Content-Type: application/x-yaml'); echo $openapi->toYaml();
Usage from the Command Line Interface
Generate the documentation to a static 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.
<?php use OpenApi\Serializer; $serializer = new Serializer(); $openapi = $serializer->deserialize($jsonString, 'OpenApi\Annotations\OpenApi'); 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_CodeSniffer (PSR-2) tests.
To run both unittests and linting execute:
composer test
Running only unittests:
./bin/phpunit
Running only linting:
./bin/phpcs -p --extensions=php --standard=PSR2 --error-severity=1 --warning-severity=0 ./src ./tests