PHP code example of digit-soft / laravel-swagger-generator

1. Go to this page and download the library: Download digit-soft/laravel-swagger-generator 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/ */

    

digit-soft / laravel-swagger-generator example snippets


/**
 * Controller method PHPDoc
 *
 * @OA\Response(true,contentType="application/json",description="Boolean response")
 *
 * @param Request $request
 * @return \Illuminate\Http\JsonResponse
 */

/**
 * Controller method PHPDoc
 *
 * @OA\ResponseJson({"key":"value"},status=201,description="User data response")
 *
 * @param Request $request
 * @return \Illuminate\Http\JsonResponse
 */

/**
 * Controller method PHPDoc
 *
 * @OA\ResponseJson({
 *      @OA\ResponseParam("key",type="string",example="value",description="Some parameter"),
 * },status=201,description="User data response")
 *
 * @param Request $request
 * @return \Illuminate\Http\JsonResponse
 */

/**
 * Controller method PHPDoc
 *
 * @OA\ResponseClass("App\User",description="User model response")
 *
 * @param Request $request
 * @return \Illuminate\Http\JsonResponse
 */

/**
 * @OA\ResponseClass("App\User",with={"profile"},status=201)
 */

/**
 * @OA\ResponseClass("App\User",asList=true)
 */

/**
 * @OA\ResponseClass("App\User",asPagedList=true)
 */

/**
 * @OA\ResponseError(403) // Forbidden
 * @OA\ResponseError(404) // Not found
 * @OA\ResponseError(422) // Validation error
 */

/**
 * @OA\RequestBodyJson({
 *   @OA\RequestParam("first_name",type="string",description="User name"),
 *   @OA\RequestParam("email",type="string",description="User email"),
 *   @OA\RequestParamArray("phones",items="string",description="User phones array"),
 * })
 */

/**
 * @OA\Tag("Tag-name")
 */

/**
 * @OA\Secured()
 */

/**
 * @OA\Property("notification_settings",type="object",example={"marketing":false,"user_actions":true},description="User notification settings")
 */

/**
 * @OA\PropertyIgnore("property_name")
 */

namespace App\Models;

use OA;

/**
 * Test model class
 *
 * @OA\Property("id",type="integer",description="Primary key")
 *
 * @property string $name String name
 */
class TestModel {}



namespace App\Components\Annotations\Swagger;

use OA\DescriptionExtender;
use Doctrine\Common\Annotations\Annotation;
use Doctrine\Common\Annotations\Annotation\{Attribute, Attributes};

/**
 * Describes needed permission
 * @Annotation
 * @Attributes({
 *  @Attribute("value",type="string"),
 * })
 * @package App\Components\Annotations\Swagger
 */
class Permission extends DescriptionExtender
{
    /**
     * @inheritdoc
     */
    public function __toString()
    {
        return '**Permission:** `' . $this->value . '`';
    }
}


use App\Components\Annotations\Swagger as SWA;


/**
 * Controller method PHPDoc
 *
 * @OA\ResponseClass("App\User",description="User model response")
 * @SWA\Permission("articles.can-update")
 *
 * @param Request $request
 * @return \Illuminate\Http\JsonResponse
 */
bash
php artisan vendor:publish --provider="DigitSoft\Swagger\SwaggerGeneratorServiceProvider" --tag="config"
bash
php artisan swagger:generate
bash
php artisan swagger:generate --diagnose