Go to file
Martin Rademacher 006bd7fc75
Clean up invalid args (#922)
* Use raw phpunit command instead of action
* Remove invalid/redundant args from security checker
2021-03-26 10:09:09 +13:00
.github/workflows Clean up invalid args (#922) 2021-03-26 10:09:09 +13:00
Examples Add bearer auth security example (#914) 2021-03-12 13:01:00 +13:00
bin Configurable File Patterns added 2018-11-30 11:29:55 +01:00
docs fix(#909): Add Swag It PHP to Related Projects (#912) 2021-03-11 13:02:09 +13:00
src Fix errors with php < 8 (#924) 2021-03-26 10:07:47 +13:00
tests Ignore PHP8 attributes (#907) 2021-03-03 10:26:25 +13:00
.gitignore doc: Updated vuepress to use local version 2020-09-05 09:59:11 +02:00
.php_cs.dist Switch `concat_space` to default (no space) 2020-07-30 13:18:45 +12:00
Changelog.md Document the changelog on the github releases page 2018-05-22 11:00:17 +02: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 Github action CI migration (#886) 2021-01-06 08:46:26 +13:00
composer.json Document validation of generated Example specs (#898) 2021-01-08 11:11:48 +13:00
phpunit.xml.dist Github action CI migration (#886) 2021-01-06 08:46:26 +13:00
psalm.xml Typehint and phpdoc improvements based on phpstan 2020-09-07 15:18:08 +12:00

README.md

Build Status Total Downloads License

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

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