PHP code example of danialzash / laravel-openapi-generator

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

    

danialzash / laravel-openapi-generator example snippets


'info' => [
    'title' => env('OPENAPI_TITLE', 'API Documentation'),
    'version' => env('OPENAPI_VERSION', '1.0.0'),
    'description' => '',
],

'route_filters' => [
    ' ['_ignition', 'sanctum'],
    'exclude_middleware' => ['web'],
],

'security_schemes' => [
    'bearerAuth' => [
        'type' => 'http',
        'scheme' => 'bearer',
        'bearerFormat' => 'JWT',
        'middleware' => ['auth:sanctum', 'auth:api'],
    ],
],

'response_macros' => [
    'show' => ['status' => 200, 'description' => 'Successful response'],
    'created' => ['status' => 201, 'description' => 'Resource created'],
],

use Verge\OpenAPIGenerator\Models\RouteMetadata;

$route = RouteMetadata::findByRoute('GET', '/api/users');
$route->update([
    'summary' => 'List all users',
    'description' => 'Retrieve a paginated list of all users in the system.',
    'tags' => ['Users', 'Admin'],
    'request_body_example' => ['name' => 'John Doe'],
]);

use Verge\OpenAPIGenerator\Models\SchemaDefinition;

SchemaDefinition::create([
    'name' => 'UserResponse',
    'schema' => [
        'type' => 'object',
        'properties' => [
            'id' => ['type' => 'string', 'format' => 'uuid'],
            'name' => ['type' => 'string'],
            'email' => ['type' => 'string', 'format' => 'email'],
        ],
    ],
    'description' => 'User response object',
]);

use Verge\OpenAPIGenerator\Builders\OpenAPIBuilder;

$builder = app(OpenAPIBuilder::class);

// Build the specification
$spec = $builder->build();

// Get as YAML
$yaml = $builder->toYaml();

// Get as JSON
$json = $builder->toJson();

// Save to file
$builder->save('/path/to/openapi.yaml', 'yaml');

// Get statistics
$stats = $builder->getStatistics();
bash
php artisan vendor:publish --tag=openapi-generator-config
bash
php artisan migrate
bash
# Check sync status
php artisan openapi:sync

# Remove orphaned entries
php artisan openapi:sync --clean

# Initialize security schemes from config
php artisan openapi:sync --init-security