PHPackages                             solidry/api-generator - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. solidry/api-generator

ActiveApi-generator[Authentication &amp; Authorization](/categories/authentication)

solidry/api-generator
=====================

PHP-code generator (based on OAS) for Laravel framework, with complete support of JSON-API data format

2.6.15(5y ago)32626.4k61[10 issues](https://github.com/SoliDry/api-generator/issues)MITPHPPHP &gt;=7.1

Since Dec 22Pushed 3y ago13 watchersCompare

[ Source](https://github.com/SoliDry/api-generator)[ Packagist](https://packagist.org/packages/solidry/api-generator)[ Docs](https://github.com/SoliDry/api-generator)[ RSS](/packages/solidry-api-generator/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (12)Versions (107)Used By (0)

api-generator
=============

[](#api-generator)

PHP-code generator (based on OAS) for Laravel framework, with complete support of JSON-API data format [![Tweet](https://camo.githubusercontent.com/2ae8719c2efbe82ef2938210c2dc507fffdfa7a73a1d982a01e5b27f7269af52/687474703a2f2f6a70696c6c6f72612e636f6d2f6769746875622d747769747465722d627574746f6e2f696d672f74776565742e706e67)](https://twitter.com/intent/tweet?text=Generate%20api%20code%20for%20Laravel%20and%20json-api%20based%20on%20OAS%20&url=https://github.com/RJAPI/api-generator&hashtags=php,api,oas,raml,json-api,laravel,developers)

[![Build Status](https://camo.githubusercontent.com/daac36a47ee2cb96c928e1a50c402e2d8fec49ab78015e39d92b7d930e8e257c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f536f6c694472792f6170692d67656e657261746f722f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/SoliDry/api-generator/build-status/master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/6a9e1c94f5932544265a631ebcfd586f616a1425b86518a8389929b8175bbe8a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f536f6c694472792f6170692d67656e657261746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/SoliDry/api-generator/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/e97c8593de0ffdeaf76bd48de2d0746d9e2c30bebf1b80593a0fe6e2aa6d0118/68747470733a2f2f706f7365722e707567782e6f72672f736f6c696472792f6170692d67656e657261746f722f646f776e6c6f616473)](https://packagist.org/packages/solidry/api-generator)[![Latest Stable Version](https://camo.githubusercontent.com/adfbf41b1675a5292d1545255fddae5dbc99a3f809ae3145c7bbaa69b225005a/68747470733a2f2f706f7365722e707567782e6f72672f736f6c696472792f6170692d67656e657261746f722f762f737461626c65)](https://packagist.org/packages/solidry/api-generator)[![Code Intelligence Status](https://camo.githubusercontent.com/695093907a8029ae0701a2658c371e7b746f66c309ba4beb801461f14415bd75/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f536f6c694472792f6170692d67656e657261746f722f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d6d6173746572)](https://scrutinizer-ci.com/code-intelligence)[![codecov](https://camo.githubusercontent.com/42f33104483eb61a64d69f756a0aa2125510e99345709b24dd7c08d57990bb38/68747470733a2f2f636f6465636f762e696f2f67682f536f6c694472792f6170692d67656e657261746f722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/SoliDry/api-generator)[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](https://opensource.org/licenses/MIT)

[![alt OAS logo](https://github.com/SoliDry/laravel-api/raw/master/tests/images/OpenAPI_Logo_Pantone-1.png)](https://github.com/SoliDry/laravel-api/blob/master/tests/images/OpenAPI_Logo_Pantone-1.png)[![alt Laravel logo](https://github.com/SoliDry/laravel-api/raw/master/tests/images/laravel-logo-white.png)](https://github.com/SoliDry/laravel-api/blob/master/tests/images/laravel-logo-white.png)[![alt JSON API logo](https://github.com/SoliDry/laravel-api/raw/master/tests/images/jsonapi.png)](https://github.com/SoliDry/laravel-api/blob/master/tests/images/jsonapi.png)

- [Getting started Demo](https://youtu.be/kFXVq4CGkEU)
- [CRUD Demo](https://youtu.be/eYVqn-VecQI)
- [Relation links Demo](https://youtu.be/DPvhiFOzoWE)
- [Migrations Demo](https://youtu.be/gfbdRZhFHn4)
- [API docs Demo](https://youtu.be/JAn5vQbDuHY)
- [Installation](#user-content-installation-via-composer)
    - [Configuration](#user-content-autoloading)
    - [Optional settings](#user-content-optional-settings)
    - [Running generator](#user-content-running-generator)
    - [Docker repo](#user-content-docker-repository)
- [Open API Types and Declarations](#user-content-open-api-types-and-declarations)
- [Open API Docs generator](#user-content-open-api-docs-generator)
- [Generated files content](#user-content-generated-files-content)
    - [Module Config](#user-content-module-config)
    - [Controllers](#user-content-controllers)
    - [FormRequests](#user-content-formrequests)
    - [Models](#user-content-models)
    - [Routes](#user-content-routes)
    - [Migrations](#user-content-migrations)
    - [Tests](#user-content-tests)
- [Relationships](#user-content-relationships-particular-qualities)
- [Bulk Extension](#user-content-bulk-extension)
- [Query parameters](#user-content-query-parameters)
- [Security](#user-content-security)
    - [Static access token](#user-content-static-access-token)
    - [JWT](#user-content-jwt-json-web-token)
- [Caching](#user-content-caching)
- [Soft Delete](#user-content-soft-delete)
- [Tree structures](#user-content-tree-structures)
- [Finite-state machine](#user-content-finite-state-machine)
- [Spell check](#user-content-spell-check)
- [Bit mask](#user-content-bit-mask)
- [Custom SQL](#user-content-custom-sql)
- [Custom business logic](#user-content-custom-business-logic)
- [Regeneration](#user-content-regeneration)

### Installation via composer:

[](#installation-via-composer)

First of all - create Laravel project if you didn't do that yet:

```
composer create-project --prefer-dist laravel/laravel your_app

```

then in your project directory run:

```
composer require solidry/api-generator

```

It will automatically register Laravel ServiceProvider by adding console command `api:generate` (you should see it when running `php artisan`) and also publish "laravel-modules" provider.

#### Autoloading

[](#autoloading)

By default Controllers, entities or repositories are not loaded automatically. You can autoload your modules using `psr-4`. For example :

```
{
  "autoload": {
    "psr-4": {
      "App\\": "app/",
      "Modules\\": "Modules/"
    }
  }
}
```

refresh changes by running:

```
composer dump-autoload

```

#### Optional settings

[](#optional-settings)

To provide Json API compatible error handler one can add `ErrorHandler` trait to `app/Exceptions/Handler` class and return `return $this->renderJsonApi($request, $exception);` from standard Laravel `render` method, complete example of `Handler` class will look something like this:

```
