PHPackages                             swisnl/openapi-spec-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. [API Development](/categories/api)
4. /
5. swisnl/openapi-spec-generator

ActiveLibrary[API Development](/categories/api)

swisnl/openapi-spec-generator
=============================

Creates Open API spec for a Laravel JSON:API

0.8.0(1y ago)2338.1k↓13.4%12[1 issues](https://github.com/swisnl/openapi-spec-generator/issues)[5 PRs](https://github.com/swisnl/openapi-spec-generator/pulls)Apache-2.0PHPPHP ^8.1CI passing

Since Jun 27Pushed 1y ago3 watchersCompare

[ Source](https://github.com/swisnl/openapi-spec-generator)[ Packagist](https://packagist.org/packages/swisnl/openapi-spec-generator)[ Docs](https://github.com/swisnl/openapi-spec-generator)[ RSS](/packages/swisnl-openapi-spec-generator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (10)Versions (11)Used By (0)

OpenAPI v3 Spec Generator
=========================

[](#openapi-v3-spec-generator)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1f20dba93681fb662f8d783fa5ae065c18309188ea6f918fd63253522f8c1517/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737769736e6c2f6f70656e6170692d737065632d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/swisnl/openapi-spec-generator)[![Software License](https://camo.githubusercontent.com/3fdc1c5159b41a20b9273789df48bb2d03cb3e433900eb77d95bcad2f02f1722/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f737769736e6c2f6f70656e6170692d737065632d67656e657261746f723f7374796c653d666c61742d737175617265)](LICENSE.md)[![Buy us a tree](https://camo.githubusercontent.com/cec0a9b35a1c3235bdbe0d13ea8fbd866a23e30280ad6ca27078c1fd4ac1b709/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54726565776172652d2546302539462538432542332d6c69676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://plant.treeware.earth/swisnl/openapi-spec-generator)[![Build Status](https://camo.githubusercontent.com/99c718c74d1edb8390c462029936d8ebef60c7236b3e88d27523e5524d417305/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f737769736e6c2f6f70656e6170692d737065632d67656e657261746f722f74657374732e796d6c3f6c6162656c3d7465737473266272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://github.com/swisnl/openapi-spec-generator/actions/workflows/tests.yml)[![Total Downloads](https://camo.githubusercontent.com/828da046bc6a66c961e7f8b18e40281b30f933549db4c65fd3389fb131105ae7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f737769736e6c2f6f70656e6170692d737065632d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/swisnl/openapi-spec-generator)[![Maintained by SWIS](https://camo.githubusercontent.com/af0a8c6f2ea8b54aca03b7ca581e67c034ad17066e75fffeb068e8d5341bbae1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2546302539462539412538302d6d61696e7461696e65642532306279253230535749532d2532333037333741392e7376673f7374796c653d666c61742d737175617265)](https://www.swis.nl)

Designed to work with [Laravel JSON:API](https://laraveljsonapi.io/)

!!! Disclaimer: this project is work in progress and likely contains many bugs, etc !!!

What it can and can't
---------------------

[](#what-it-can-and-cant)

### Can

[](#can)

- Generate Schemas/Responses/Request/Errors for all default [Laravel JSON:API](https://laraveljsonapi.io/) routes
- Use a seeded database to generate examples

### Can't yet

[](#cant-yet)

- Customisation of the generation
- Generation for custom actions
- Generation for custom filters
- Generation for anything custom
- Generation for MorphTo relations (MorphToMany works)
- Generation of Pagination Meta
- Generation of Includes
- Generation of Authentication/Authorization

TODO
----

[](#todo)

- Command to generate to storage folder
- Get basic test suite running with GitHub Actions
- Add extra operation descriptions via config
- Add in tags &amp; x-tagGroups (via config)
- Add tests (Use the dummy by laraveljsonapi to integrate all features)
- Add custom actions
- Split schemas/requests/responses by action
- Consider field attributes
    - bool readonly
    - bool hidden
    - closure based readonly (create/update)
    - closure based hidden
- List sortable fields
- Fix includes and relations
    - Add relationship routes
    - Add includes
- Add authentication
- Add custom queries/filters
- Add a way to document custom actions
- Tidy up the code!!
- Replace `cebe/php-openapi` with `goldspecdigital/oooas`
- Move to an architecture inspired by `vyuldashev/laravel-openapi`
- Use php8 attributes on actions/classes to generate custom docs

🙏 Based upon initial prototype by [martianatwork](https://github.com/martianatwork), [glennjacobs](https://github.com/glennjacobs) and [byte-it](https://github.com/byte-it).

Install
-------

[](#install)

Via Composer

```
composer require swisnl/openapi-spec-generator

```

Publish the config file

```
php artisan vendor:publish --provider="LaravelJsonApi\OpenApiSpec\OpenApiServiceProvider"

```

Usage
-----

[](#usage)

Generate the Open API spec

```
php artisan jsonapi:openapi:generate v1

```

Note that a seeded DB is required! The seeded data will be used to generate Samples.

### Descriptions

[](#descriptions)

It's possible to add descriptions to your endpoints by implementing the DescribesEndpoints interface. The added method receives the generated route name as a parameter. This can be used to generate descriptions for all your schema endpoints.

```
class Post extends Schema implements DescribesEndpoints
{
    public function describeEndpoint(string $endpoint) {
        if ($endpoint === 'v1.posts.index') {
            return 'Description for index method';
        }

        return 'Default description';
    }
}
```

Generating Documentation
------------------------

[](#generating-documentation)

### [Speccy](https://github.com/wework/speccy)

[](#speccy)

A quick way to preview your documentation is to use [`speccy serve` command](https://github.com/wework/speccy#serve-command).

Ensure you have installed Speccy globally and then you can use the following command:

```
speccy serve storage/app/v1_openapi.yaml
```

> Warning: Seems like [Speccy](https://speccy.io) is abandoned ([wework/speccy#485](https://github.com/wework/speccy/issues/485)).

### [Laravel Stoplight Elements](https://github.com/JustSteveKing/laravel-stoplight-elements)

[](#laravel-stoplight-elements)

Easily publish your API documentation in a local route by using your OpenAPI document in your Laravel Application directly.

> For this to work, you have to generate your spec in a public-available location, like the local 'public' disk available in Laravel applications:
>
> ```
> OPEN_API_SPEC_GENERATOR_FILESYSTEM_DISK='public'
> ```

After [installing it](https://github.com/JustSteveKing/laravel-stoplight-elements#laravel-stoplight-elements), you should set its url config: `STOPLIGHT_OPENAPI_PATH`. For example, if you're using the 'public' disk:

```
OPEN_API_SPEC_GENERATOR_FILESYSTEM_DISK='public'

# '/storage' is the default 'public' URL.
STOPLIGHT_OPENAPI_PATH='/storage/v1_openapi.json'
```

> Note: If you need a more dynamic way to get access to the spec URL (for example, in S3 you may need to use [temporary URLs](https://laravel.com/docs/filesystem#temporary-urls)), you can publish its Blade template and [replace some lines ](https://github.com/JustSteveKing/laravel-stoplight-elements/blob/2.0.0/resources/views/docs.blade.php#L14) to generate your own URI. Also, you may need to add an Fetch interceptor to integrate it with your authentication methods.

With its default route, ¡you just need to access to your `/api/docs` route to preview your specs! ![:bowtie:](https://github.githubassets.com/images/icons/emoji/bowtie.png ":bowtie:")

Check [its configuration docs](https://github.com/JustSteveKing/laravel-stoplight-elements#configuration) for further options.

### [Standalone Stoplight Elements Web Component](https://github.com/stoplightio/elements#web-component)

[](#standalone-stoplight-elements-web-component)

In addition to previous Laravel package, you can use the Stoplight Elements by yourself. It is available as React Component, or Web Component, making it easier for integrating into existing Content Management Systems with their own navigation.

This is useful when you need more advanced customizations in the routing system, integrate it in your existing Vue|React|Vanilla application, or publish it as a non-laravel static HTML site. But... you have to setup it manually. 😅

#### Web component integrated in your Vue application

[](#web-component-integrated-in-your-vue-application)

You can [follow the instructions](https://github.com/stoplightio/elements/blob/main/docs/getting-started/elements/html.md) to use the standalone Web Component, grab it into a blade template and armor your view.

It has [advanced options](https://github.com/stoplightio/elements/blob/main/docs/getting-started/elements/elements-options.md), like `tryItCredentialPolicy="same-origin"` to use your cookie-based authentication (like [Sanctum](https://github.com/laravel/sanctum/)).

Also, in your Blade view or Vue's app initializer, as this package uses [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) you can add interceptors to customize the "try it out" feature, like adding default headers for `Content-Type` and/or `Accept` to be `'application/vnd.api+json'` to your requests.

### Other options

[](#other-options)

You can check a more exhaustive list of options available at

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Glenn Jacobs](https://github.com/glennjacobs)
- [Johannes Kees](https://github.com/byte-it)
- [Björn Brala](https://github.com/bbrala)
- [Rien van Velzen](https://github.com/Rockheep)
- [All Contributors](../../contributors)

License
-------

[](#license)

Apache License 2.0. All notable changes to the original work can be found in [CHANGELOG](CHANGELOG.md). Please see [License File](LICENSE.md) for more information.

This package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/swisnl/openapi-spec-generator) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

SWIS ❤️ Open Source
-------------------

[](#swis-heart-open-source)

[SWIS](https://www.swis.nl) is a web agency from Leiden, the Netherlands. We love working with open source software.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance41

Moderate activity, may be stable

Popularity41

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~145 days

Recently: every ~173 days

Total

10

Last Release

472d ago

PHP version history (3 changes)0.0.1PHP ^8.0

0.3.0PHP &gt;=7.4|^8.0

0.8.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8734305?v=4)[SWIS](/maintainers/swisnl)[@swisnl](https://github.com/swisnl)

---

Top Contributors

[![JaZo](https://avatars.githubusercontent.com/u/3475007?v=4)](https://github.com/JaZo "JaZo (37 commits)")[![Rocksheep](https://avatars.githubusercontent.com/u/1311371?v=4)](https://github.com/Rocksheep "Rocksheep (21 commits)")[![bbrala](https://avatars.githubusercontent.com/u/3294970?v=4)](https://github.com/bbrala "bbrala (21 commits)")[![Westie](https://avatars.githubusercontent.com/u/117472?v=4)](https://github.com/Westie "Westie (6 commits)")[![pjotrvdh](https://avatars.githubusercontent.com/u/2292196?v=4)](https://github.com/pjotrvdh "pjotrvdh (6 commits)")[![nelson6e65](https://avatars.githubusercontent.com/u/9272498?v=4)](https://github.com/nelson6e65 "nelson6e65 (4 commits)")[![captnCC](https://avatars.githubusercontent.com/u/5840945?v=4)](https://github.com/captnCC "captnCC (2 commits)")[![maartenpaauw](https://avatars.githubusercontent.com/u/4550875?v=4)](https://github.com/maartenpaauw "maartenpaauw (2 commits)")

---

Tags

laravelopenapigeneratorJSON-APIswisnlopenapi-spec-generatoropenapi-spec

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/swisnl-openapi-spec-generator/health.svg)

```
[![Health](https://phpackages.com/badges/swisnl-openapi-spec-generator/health.svg)](https://phpackages.com/packages/swisnl-openapi-spec-generator)
```

###  Alternatives

[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

2.9k34.0M112](/packages/darkaonline-l5-swagger)[darkaonline/swagger-lume

OpenApi or Swagger integration to Lumen

3372.3M3](/packages/darkaonline-swagger-lume)[solidry/api-generator

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

32626.4k](/packages/solidry-api-generator)[erasys/openapi-php

Open API 3.0 builder and validation library for PHP that helps you write valid specs.

2080.3k5](/packages/erasys-openapi-php)[onmoon/openapi-server-bundle

Symfony bundle to create a fully-featured API server from an OpenAPI v3 specification

1117.7k](/packages/onmoon-openapi-server-bundle)[dystcz/lunar-api

Dystore API layer for Lunar e-commerce package

411.1k3](/packages/dystcz-lunar-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
