v1.2.0is out

Laravel OpenAPI Generator

Generates OpenAPI 3.0, 3.1 and 3.2 documents from a Laravel application, its routes, form requests and resources.

StoreBookRequest::rules()
return [
    'title' => 'required|string|max:255',
    'price' => 'required|numeric|min:0',
    'tags' => 'array',
    'tags.*' => 'string|distinct',
];
the schema of the request body
{
  "type": "object",
  "required": ["title", "price"],
  "properties": {
    "title": { "type": "string", "maxLength": 255 },
    "price": { "type": "number", "minimum": 0 },
    "tags": {
      "type": "array",
      "items": { "type": "string" },
      "uniqueItems": true
    }
  }
}

Why Laravel OpenAPI Generator

A hand-written OpenAPI file is out of date at the next pull request. Your application already says what its API accepts and returns; the generator reads it and writes the document, in OpenAPI 3.0, 3.1 or 3.2, one document per API or per audience.

Read from the code

Routes, middlewares, return types and PHPDoc are the documentation; attributes complete what cannot be inferred.

Bodies from the validation rules

Every rule of your form requests becomes a constraint of the schema, and the 422 is documented.

Responses from your resources

Resources run on sampled models, inside a transaction rolled back at the end: the schema is what the API returns.

Checked in CI

Diagnostics by route, and --strict fails the build when the documentation degrades.

Compatibility

A Laravel package: php artisan openapi:generate writes every document of the configuration.

VersionPHP Laravel Status
1.x^8.3^13.0Active
0.6^8.1^10.0 || ^11.0 || ^12.0 || ^13.0End of life

Start with Laravel OpenAPI Generator

Install it, follow the quick start, and see your first result in minutes.

Works with

Laravel JSON:API
JSON:API 1.1 resources for Laravel, with typed values, validated includes and fieldsets, and API revisions.
v3.0.0ark4ne/laravel-json-api
Laravel API Revisions
Typed schemas for Laravel resources and form requests, evolved through dated API revisions, Stripe-style.
v1.0.0ark4ne/laravel-api-revisions
OpenAPI Writer
Framework-agnostic, fluent and immutable PHP builder for OpenAPI 3.0, 3.1 and 3.2 documents, written as JSON or YAML and validated.
v1.0.0ark4ne/openapi-writer