Go to file
Akihito Koriyama 8aa11f3f98
Update README (v2) (#1477)
2023-09-15 09:37:40 +12:00
.github/workflows Migrate CI from travis to GH action for 2.x (#1475) 2023-09-07 10:46:39 +12:00
Examples Example dynamic references (#463) 2017-11-27 07:46:52 +01:00
bin Added OperationId Processor & cli option: --processor 2018-01-26 11:07:40 +01:00
docs Add related project in v2: OpenAPI-Symfony-Routing 2020-06-12 12:22:21 +02:00
src Fix deprecated error in PHP 8.1/8.2 (#1474) 2023-09-13 10:12:26 +12:00
tests Fix deprecated error in PHP 8.1/8.2 (#1474) 2023-09-13 10:12:26 +12:00
.gitattributes add .gitattributes to remove test files from dist packages 2020-06-12 12:27:01 +02:00
.gitignore drop unsupported php versions, fix compatibility with php 8 2020-11-26 15:34:25 +01:00
Changelog.md Released 2.0.13 2017-12-01 10:22:05 +01:00
LICENSE-2.0.txt Started the rewrite which will be compatible with Swagger v2.0 Spec 2015-01-16 18:10:11 +01:00
README.md Update README (v2) (#1477) 2023-09-15 09:37:40 +12:00
VERSION Released 2.0.16 2020-05-10 15:42:24 +02:00
composer.json Migrate CI from travis to GH action for 2.x (#1475) 2023-09-07 10:46:39 +12:00
phpunit.xml.dist drop unsupported php versions, fix compatibility with php 8 2020-11-26 15:34:25 +01:00

README.md

build Total Downloads License

swagger-php

Generate interactive Swagger documentation for your RESTful API using doctrine annotations.

Features

  • Compatible with the Swagger 2.0 specification.
  • Exceptional error reporting (with hints, context)
  • Extracts information from code & existing phpdoc annotations.
  • Command-line interface available.

Installation (with Composer)

composer require zircote/swagger-php ^2

For cli usage from anywhere install swagger-php globally and make sure to place the ~/.composer/vendor/bin directory in your PATH so the swagger executable can be located by your system.

composer global require zircote/swagger-php ^2

Usage

Add annotations to your php files.

/**
 * @SWG\Info(title="My First API", version="0.1")
 */

/**
 * @SWG\Get(
 *     path="/api/resource.json",
 *     @SWG\Response(response="200", description="An example resource")
 * )
 */

See the Getting started guide and Examples directory for more examples.

Usage from php

Generate always-up-to-date documentation.

<?php
require("vendor/autoload.php");
$swagger = \Swagger\scan('/path/to/project');
header('Content-Type: application/json');
echo $swagger;

Usage from the Command Line Interface

Generate the swagger documentation to a static json file.

./vendor/bin/swagger --help

Usage from the Deserializer

Generate the swagger annotation object from a json string, which makes it easier to manipulate swagger object programmatically.

<?php

use Swagger\Serializer;

$serializer = new Serializer();
$swagger = $serializer->deserialize($jsonString, 'Swagger\Annotations\Swagger');
echo $swagger;

Usage from docker

Generate the swagger documentation to a static json file.

docker run -v "$PWD":/app -it tico/swagger-php --help

More on Swagger

Contributing

Feel free to submit Github Issues or pull requests.

The documentation website resides within the gh-pages branch.

Make sure pull requests pass PHPUnit and PHP_CodeSniffer (PSR-2) tests.

Running tests can be done with this command in the root of the project:

./bin/phpunit

To run the phpcs tests on your local machine execute:

./bin/phpcs -p --extensions=php --standard=PSR2 --error-severity=1 --warning-severity=0 ./src ./tests

To run both unittests and linting execute:

composer test