PHP code example of savionicodemos / laravel-auto-swagger

1. Go to this page and download the library: Download savionicodemos/laravel-auto-swagger library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

savionicodemos / laravel-auto-swagger example snippets


/**
 * @Request({
 *    "summary": "Title of the route",
 *    "description": "This is a longer description for the route which will be visible once the panel is expanded",
 *    "tags": ["Authentication","Users"]
 * })
 * 
 */

/**
* You can also do this, first line will be "summary"
*
* And anything 1 * apart from the "summary" will count as "description"
*
* @Request({
*     "summary": "Title of the route", // <- If you add here, this will overwrite the summary from above.
*     "description": "A short description", // <- If you need a longer one, just use the comment itself
*     "tags": ["Authentication","Users"] // <- This Request will be used in this two tags section
* })
*/
public function someMethod(Request $request) {}

/**
* @Response({
*     "code": 200,
*     "description": "Return user model",
*     "ref": "User"
* })
* @Response({
*     "code": 400,
*     "description": "Bad Request",
*     "ref": "APIError[]" // <- An Array of APIError, can be a custom Schema
* })
* @Response({
*     "code": "302",
*     "description": "Redirect"
* })
* @Response({
*     "code": 500,
*     "description": "Internal Server Error"
* })
*/
public function someMethod(Request $request) {}

/**
 * You can also refer object directly
 * 
 * 
 * @Response({
 *     "code": 200,
 *     "description": "Direct user model reference",
 *     "ref": "#/components/schemas/User" // <- Full Schema path
 * })
 */
public function someMethod2(Request $request) {}

/**
 * Using P schema builder for Laravel Pagination
 * 
 * @Response({
 *     "code": 200,
 *     "description": "A laravel pagination instance with User model",
 *     "ref": "P(User)" // <- Using Schema Builder
 * })
 */
public function someMethod3(Request $request) {}

$rules = [
    'locale'        =>  'swagger_default:en_GB'
];

$rules = [
    'currency'        =>  'swagger_example:EUR'
];

$rules = [
    'limit'         =>  'swagger_description:Limit the number of items to return'
];

$rules = [
    // This will simply display the 'minimum' value in the documentation
    'page'          =>  'swagger_default:1|swagger_min:1', 
    // This will also fail if the `page` parameter will be less than 1
    'page'          =>  'swagger_default:1|swagger_min:1:fail'
];

$rules = [
    // This will simply display the 'maximum' value in the documentation
    'take'          =>  'swagger_default:1|swagger_min:1|swagger_max:50',
    // This will also fail if the `take` parameter will be greater than 50
    'take'          =>  'swagger_default:1|swagger_min:1|swagger_max:50:fail'
];
shell
php artisan vendor:publish --provider "AutoSwagger\Docs\SwaggerServiceProvider"