erasys/openapi-php

Open API 3.0 builder and validation library for PHP that helps you write valid specs.
86,119 20
Install
composer require erasys/openapi-php
Latest Version:4.0.0
PHP:^8.2
License:MIT
Last Updated:Apr 17, 2025
Links: GitHub  ·  Packagist
Maintainer: erasys_webteam

openapi-php

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

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

This project is compliant with PSR-1, PSR-2 and PSR-4. If you notice compliance oversights, please send a patch via pull request.

Features

  • Fully documented object-oriented representation of the Open API 3.0+ specification with helper methods to write valid documents.
  • Supports Illuminate (Laravel) Jsonable and Arrayable.
  • Generates an specification in plain PHP arrays, plain objects, JSON or YAML.
  • Validates Open API documents against the Open API 3.0.x JSON Schema.

Install

Via Composer

$ composer require erasys/openapi-php

Via Git

$ git clone https://github.com/erasys/openapi-php.git

Usage

Basic example:

<?php

use erasys\OpenApi\Spec\v3 as OASv3;

$doc = new OASv3\Document(
    new OASv3\Info('My API', '1.0.0', 'My API description'),
    [
        '/foo/bar' => new OASv3\PathItem(
            [
                'get' => new OASv3\Operation(
                    [
                        '200' => new OASv3\Response('Successful response.'),
                        'default' => new OASv3\Response('Default error response.'),
                    ]
                ),
            ]
        ),
    ]
);

$yaml = $doc->toYaml();
$json = $doc->toJson();
$arr  = $doc->toArray();
$obj  = $doc->toObject();

Testing

$ composer test

or

$ vendor/bin/phpunit
$ vendor/bin/phpcs

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.

Related Packages

skopenow/oas-lumen

A package for delivering a Lumen REST API from an Open API Schema (OAS) specific...

8 0
jeandormehl/openapi-gen

Generates OpenApi specification for Laravel, Lumen or Dingo using a configuratio...

525 6
noitran/opendox

OpenApi(Swagger) 3.0 package for Lumen 5.5+ and Laravel 5.5+ with REDOC UI and S...

14,519 22
darkaonline/swagger-lume

OpenApi or Swagger integration to Lumen

2,430,302 330
darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

38,626,149 2,926