PHPackages                             g4t/swagger - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. g4t/swagger

ActiveLibrary[API Development](/categories/api)

g4t/swagger
===========

g4t laravel swagger

4.1.10(3mo ago)12549.3k↓50.7%16MITPHP

Since Jun 7Pushed 3mo ago4 watchersCompare

[ Source](https://github.com/hussein4alaa/laravel-g4t-swagger-auto-generate)[ Packagist](https://packagist.org/packages/g4t/swagger)[ RSS](/packages/g4t-swagger/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (10)DependenciesVersions (86)Used By (0)

Swagger Laravel Autogenerate Package
====================================

[](#swagger-laravel-autogenerate-package)

The Swagger Laravel Autogenerate Package automatically generates OpenAPI (Swagger) documentation for your Laravel APIs from route definitions, validation rules, and optional controller inference—so you spend less time maintaining specs by hand.

 [![I Stand with IRAN](./i_stand.png)](./i_stand.png)

**Documentation:**

Features
--------

[](#features)

- **Mock workflow (experimental):** optional `swagger:mock-server`.
- **Cached spec:** `swagger:cache` and `make:swagger`.
- Generates OpenAPI **3.x** JSON from your registered routes (URI, methods, middleware, tags, etc.).
- **FormRequest** rules drive request schemas and query/path parameters where applicable.
- Optional **inferred response examples** from controllers (`infer_response_examples`): literals, `JsonResource::collection` / `::make` / `new Resource`, `response()->json(...)`, and more (see `ResponseExampleExtractor`).
- Optional **inferred error examples** (`infer_error_response_examples`): `response()->json([...], status)`, `abort()`, validation-style **422** when rules warrant it.
- **Faster JSON endpoint**: when `load_from_json` is `false`, the package can serve `public/{cached_spec_path}` if it exists (`use_cached_spec_when_present`, default `true`), otherwise builds from routes on each request.
- **storage/swagger/…** JSON files can override per-route response examples when enabled in config.
- Route macros: `->description()`, `->summary()`, `->hiddenDoc()`; controller `#[SwaggerSection('…')]`.
- Optional **basic auth** for the documentation UI (configurable).

 [![I Stand with IRAN](./back.png)](./back.png)

Installation
------------

[](#installation)

```
composer require g4t/swagger
```

Usage
-----

[](#usage)

#### Video walkthrough

[](#video-walkthrough)

[![Explanatory video on how to use](https://camo.githubusercontent.com/a385df1b6ebb74c30ac21be57f782b195e687358c83868aa40c9f15db7d98112/68747470733a2f2f696d672e796f75747562652e636f6d2f76692f6249314259397441774f772f302e6a7067)](https://www.youtube.com/watch?v=bI1BY9tAwOw)

1. Publish the configuration file:

    ```
    php artisan vendor:publish --provider "G4T\Swagger\SwaggerServiceProvider"
    ```
2. Adjust **`config/swagger.php`** (title, URL prefix, versions, inference flags, **`cached_spec_path`** / **`use_cached_spec_when_present`**, etc.).
3. Open the UI at **`/{swagger.url}`** (default: `/swagger/documentation`), e.g. `https://your-app.test/swagger/documentation`.
4. The **issues** page route is configured via `swagger.issues_url` (default: `/swagger/issues`).
5. Describe a route:

    ```
    Route::get('user', [UserController::class, 'index'])->description('Get list of users with pagination.');
    ```
6. Short summary on the route:

    ```
    Route::get('user', [UserController::class, 'index'])->summary('get users.');
    ```
7. Hide an endpoint from the docs:

    ```
    Route::get('user', [UserController::class, 'index'])->hiddenDoc();
    ```
8. Controller section description:

    ```
