PHP code example of uraankhayayaal / openapi-generator-lumen

1. Go to this page and download the library: Download uraankhayayaal/openapi-generator-lumen 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/ */

    

uraankhayayaal / openapi-generator-lumen example snippets


$app->register(Uraankhayayaal\OpenapiGeneratorLumen\Providers\OpenApiGeneratorProvider::class);

protected $commands = [
    \Uraankhayayaal\OpenapiGeneratorLumen\Console\Commands\OpenApiGeneratorCommand::class,
];



namespace App\Http\Requests;

use Uraankhayayaal\OpenapiGeneratorLumen\Http\Requests\BaseRequestQueryData;

final class ConfirmQuery extends BaseRequestQueryData
{
    public string $hash;

    public function rules(): array
    {
        return [
            'hash' => '

use App\Http\Requests\ConfirmQuery;
...
public function confirm(ConfirmQuery $query): UserResource
{
    ...
    $hash = $query->hash;
    ...
}



namespace App\Http\Requests;

use OpenApi\Attributes as OA;
use Uraankhayayaal\OpenapiGeneratorLumen\Http\Requests\BaseRequestFormData;

final class RegisterForm extends BaseRequestFormData
{
    public string $username;
    public string $email;
    public string $phone;
    public string $password;
    public bool $isAgreeMarketing;
    public bool $isAgreePolicy;
    #[OA\Property(property: 'file', type: 'string', format: 'binary', nullable: false)] // Use attributes or annotations for override
    public $file,

    public function rules(): array
    {
        return [
            'username' => '

use App\Http\Requests\RegisterForm;
...
public function register(RegisterForm $registerForm): JsonResource
{
    ...
    $username = $registerForm->username;
    ...
}



namespace App\Http\Responses;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class UserResource extends JsonResource
{
    /** @param string[] $roles */
    public function __construct(
        public int $id,
        public int $status,
        public string $email,
        public string $phone,
        public array $roles,
        public int $createdAt,
        public int $updatedAt,
    ) {}

    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'status' => $this->status,
            'email' => $this->email,
            'phone' => $this->phone,
            'roles' => $this->roles,
            'createdAt' => $this->createdAt,
            'updatedAt' => $this->updatedAt,
        ];
    }
}

use App\Http\Responses\UserResource;
...
public function register(): UserResource
{
    ...
}



return [
    'title' => 'API DOCUMENTATION',
    'version' => '0.0.1',
    'servers' => [
        'local' => [
            'host' => 'http://localhost:8000',
            'description' => 'Local API server',
        ],
        'prod' => [
            'host' => 'https://example.domain',
            'description' => 'Production API server',
        ],
    ],
    'auth_middleware' => 'auth',
    'export' => [
        'path' => './openapi.json',
        'format' => 'json',
    ],
];

$app->configure('openapi-generator');
bash
php artisan openapi:generate