Skip to content

Getting Started

HusseinAlaa edited this page Aug 16, 2023 · 3 revisions

Getting Started

Getting started with the "laravel-g4t-swagger-auto-generate" package is a breeze. Before you begin, ensure you have the following prerequisites in place:

Laravel framework (version X.X or higher)

PHP (version X.X or higher)

Composer (for package installation)

To install the package, follow these steps:

1- Open your terminal and navigate to your Laravel project's root directory.

2- Run the following command to install the package:

composer require hussein4alaa/laravel-g4t-swagger-auto-generate

3- Next, publish the package's configuration file:

php artisan vendor:publish --provider="Hussein4alaa\Swagger\SwaggerServiceProvider"

Configure the package by editing the config/swagger.php file. This file allows you to define settings related to your API documentation.

Configuration

The configuration of the "laravel-g4t-swagger-auto-generate" package plays a crucial role in defining how your API documentation is generated. The swagger.php configuration file, located in the config directory of the package, offers various options to customize the behavior of the Swagger documentation generation process. Let's dive into the available configuration options:

// config/swagger.php

/*
|--------------------------------------------------------------------------
| API Title
|--------------------------------------------------------------------------
|
| The title of your API documentation.
|
*/

'title' => 'My Laravel API Documentation',

/*
|--------------------------------------------------------------------------
| API Version
|--------------------------------------------------------------------------
|
| The version of your API.
|
*/

'version' => '1.0',

/*
|--------------------------------------------------------------------------
| Base Path
|--------------------------------------------------------------------------
|
| The base path of your API endpoints.
|
*/

'base_path' => '/api',

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Define the routes that you want to include in the Swagger documentation.
| You can use wildcards and route names to specify routes.
|
*/

'routes' => [
    'api/*', // Include all routes under the 'api' middleware group
],

/*
|--------------------------------------------------------------------------
| API Information
|--------------------------------------------------------------------------
|
| Additional information about your API, such as contact information and
| description. This will be displayed in the Swagger documentation.
|
*/

'info' => [
    'contact' => [
        'email' => '[email protected]',
    ],
    'description' => 'This is an API documentation for the My Laravel API.',
],

/*
|--------------------------------------------------------------------------
| Security Definitions
|--------------------------------------------------------------------------
|
| Define security schemes for your API. You can use apiKey, basicAuth, etc.
|
*/

'security' => [
    'apiKey' => [],
],

// ...other configuration options

In this configuration file, you can modify the 'title', 'version', 'base_path', and 'routes' options to fit your project's specifics.

Additionally, the 'info' section allows you to provide contact information and a description that will be displayed in the Swagger documentation.

The 'security' section enables you to define security schemes if required.

Remember to tailor the configuration settings to your project's requirements and consider adding explanatory comments for each option to guide users and contributors effectively.

Clone this wiki locally