miladev / lara-swagger
Swagger model generator based on Laravel migrations
Requires
- php: ^8.2
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.5|^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A Swagger model generator based on migrations
if you bored to create swagger models from your laravel application this package can help you.
Installation
You can install the package via composer:
composer require miladev/lara-swagger
Usage
php artisan lswagger:generate
This command will create a swagger_models.json file in the current working directory containing all models of your Laravel application.
Enum columns
$table->enum('col', ['a', 'b', 'c']) columns are emitted as an OpenAPI-style enum:
{
"col": {
"type": "string",
"enum": ["a", "b", "c"]
}
}
Foreign-key columns ($table->foreign(...)) are skipped.
Testing
This package uses PHPUnit and Orchestra Testbench.
- Prerequisites: PHP 8.2+ and Composer
- Install dev dependencies:
composer install
If you do not have a global Composer installed, you can use a local PHAR inside the project:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php composer-setup.php --install-dir=. --filename=composer.phar php -r "unlink('composer-setup.php');" php composer.phar install
- Run the tests:
composer test # or vendor/bin/phpunit # or a specific test file vendor/bin/phpunit tests/Feature/CreateSwaggerCommandTest.php
If you run tests from an IDE, ensure the working directory is the project root so the generated swagger_models.json can be found.
Roadmap
- Support all kind of migrations (Rename, Delete, ...)
If you want to contribute, open a pull request by following Laravel contribution guide.
License
The MIT License (MIT). Please see License File for more information.