WIP.
There are two ways to to get the generator to pick up your routes.
The first way is to decorate the controller method with the Humi\OpenApiGenerator\Attributes\OpenApi
attribute.
<?php
use Humi\OpenApiGenerator\Attributes\OpenApi;
class MyController
{
#[OpenApi]
public function index()
{
// ...
}
}
The second way is to typehint an instance of the Humi\OpenApiGenerator\RequestInterface
as the request argument. Any Laravel FormRequest will do (or really anything, as long as it has a rules
method), just add the interface to the class.
<?php
use Illuminate\Http\FormRequest;
use Humi\OpenApiGenerator\RequestInterface;
class MyRequest extends FormRequest implements RequestInterface
{
public function rules(): array
{
return [
// Some validation rules ...
];
}
}
In your controller:
<?php
class MyController
{
public function store(MyRequest $request)
{
// ...
}
}
Run the following command to generate documentation:
php artisan open-api:generate
The generated OpenAPI spec will be located in open-api.yml
at the root of your project (the file name can be configured in open-api-generator.php
).
- Add more OpenAPI data types (enum, max/min, etc.)
- Response types
- Use $refs