|
| 1 | +# Swagger PHP module |
| 2 | + |
| 3 | +## Description |
| 4 | + |
| 5 | +Swagger PHP module adapted for Mezzio/Laminas. |
| 6 | + |
| 7 | +## Requirements |
| 8 | + |
| 9 | +- PHP >7.4 |
| 10 | +- Mezzio\Template\TemplateRendererInterface |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | + |
| 15 | +The preferred way to install this wrapper is through [composer](http://getcomposer.org/download/). |
| 16 | + |
| 17 | +```bash |
| 18 | +php composer.phar require genxoft/php-swagger-module |
| 19 | +``` |
| 20 | + |
| 21 | +or |
| 22 | + |
| 23 | +```bash |
| 24 | +composer require genxoft/php-swagger-module |
| 25 | +``` |
| 26 | + |
| 27 | +or add to the require section of `composer.json` |
| 28 | + |
| 29 | +``` |
| 30 | +"genxoft/php-swagger-module" : "*" |
| 31 | +``` |
| 32 | + |
| 33 | +## Setup |
| 34 | + |
| 35 | +After installation of the package, you need to complete the following steps to use PHP Swagger module: |
| 36 | + |
| 37 | +1. Add ```\Genxoft\SwaggerPhpModule\ConfigProvider::class``` to your config aggregator |
| 38 | +2. Add and customize (if necessary) configuration (add file ```php-swagger.global.php``` into ```config/autoload```) |
| 39 | +```php |
| 40 | +<?php |
| 41 | +return [ |
| 42 | + 'swagger_php' => [ |
| 43 | + 'scanDirs' => [ |
| 44 | + __DIR__ . '/module' |
| 45 | + ], |
| 46 | + 'jsonUrl' => '/api-oas-docs/json', |
| 47 | + ], |
| 48 | + 'routes' => [ |
| 49 | + 'swagger_php.route.json' => [ |
| 50 | + 'path' => '/api-oas-docs/json', |
| 51 | + 'middleware' => [ |
| 52 | + \Genxoft\SwaggerPhpModule\Handler\JsonAction::class, |
| 53 | + ], |
| 54 | + 'allowed_methods' => ['GET'], |
| 55 | + ], |
| 56 | + 'swagger_php.route.ui' => [ |
| 57 | + 'path' => '/api-oas-docs/ui', |
| 58 | + 'middleware' => [ |
| 59 | + \Genxoft\SwaggerPhpModule\Handler\UiAction::class, |
| 60 | + ], |
| 61 | + 'allowed_methods' => ['GET'], |
| 62 | + ], |
| 63 | + ], |
| 64 | +]; |
| 65 | +``` |
| 66 | + |
| 67 | +## Open Api Swagger 3 example annotation |
| 68 | + |
| 69 | +Api server description |
| 70 | + |
| 71 | +```php |
| 72 | +/** |
| 73 | + * @OA\Info( |
| 74 | + * version="1.0", |
| 75 | + * title="Application API", |
| 76 | + * description="Server - Mobile app API", |
| 77 | + * @OA\Contact( |
| 78 | + * name="John Smith", |
| 79 | + * email="john@example.com", |
| 80 | + * ), |
| 81 | + * ), |
| 82 | + * @OA\Server( |
| 83 | + * url="https://example.com/api", |
| 84 | + * description="main server", |
| 85 | + * ) |
| 86 | + * @OA\Server( |
| 87 | + * url="https://dev.example.com/api", |
| 88 | + * description="dev server", |
| 89 | + * ) |
| 90 | + */ |
| 91 | +... |
| 92 | + ``` |
| 93 | + |
| 94 | +Handler annotation |
| 95 | + |
| 96 | +```php |
| 97 | +/** |
| 98 | + * @OA\Get(path="/", |
| 99 | + * summary="Handshake", |
| 100 | + * tags={"handshake"}, |
| 101 | + * @OA\Parameter( |
| 102 | + * name="access-token", |
| 103 | + * in="header", |
| 104 | + * required=false, |
| 105 | + * @OA\Schema( |
| 106 | + * type="string" |
| 107 | + * ) |
| 108 | + * ), |
| 109 | + * @OA\Response( |
| 110 | + * response=200, |
| 111 | + * description="Returns Hello object", |
| 112 | + * @OA\MediaType( |
| 113 | + * mediaType="application/json", |
| 114 | + * @OA\Schema(ref="#/components/schemas/Hello"), |
| 115 | + * ), |
| 116 | + * ), |
| 117 | + * ) |
| 118 | + */ |
| 119 | +class HelloHandler implements RequestHandlerInterface |
| 120 | +{ |
| 121 | +... |
| 122 | +``` |
| 123 | +Model annotation |
| 124 | +```php |
| 125 | +/** |
| 126 | + *@OA\Schema( |
| 127 | + * schema="Hello", |
| 128 | + * @OA\Property( |
| 129 | + * property="message", |
| 130 | + * type="string", |
| 131 | + * description="Text message" |
| 132 | + * ), |
| 133 | + * @OA\Property( |
| 134 | + * property="time", |
| 135 | + * type="integer", |
| 136 | + * description="Server current Unix time" |
| 137 | + * ), |
| 138 | + * @OA\Property( |
| 139 | + * property="date", |
| 140 | + * type="string", |
| 141 | + * format="date-time", |
| 142 | + * description="Server current date time" |
| 143 | + * ) |
| 144 | + *) |
| 145 | + */ |
| 146 | +class HelloModel |
| 147 | +{ |
| 148 | +... |
| 149 | +``` |
| 150 | + |
| 151 | +## Screenshot |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | +## Donate |
| 156 | +<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=2PURUX2SHUD9E"><img src="https://www.paypalobjects.com/en_US/RU/i/btn/btn_donateCC_LG.gif"></a> |
| 157 | + |
| 158 | +## LICENSE |
| 159 | +This curl wrapper is released under the [MIT license](https://github.com/genxoft/php-swagger-module/LICENSE.md). |
0 commit comments