pandaleague/openapibuilder

Maintainers

Package info

github.com/pandaleague/OpenApiBuilder

pkg:composer/pandaleague/openapibuilder

Transparency log

Statistics

Installs: 3 194

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

1.0.0 2026-06-15 12:31 UTC

README

A small, fluent PHP library for assembling OpenAPI 3.0 specifications as PHP arrays — ready to encode to JSON or YAML.

Requirements

  • PHP 8.3+
  • illuminate/contracts ^11 || ^12

Installation

composer require pandaleague/openapibuilder

Quick example

use PandaLeague\OpenApiBuilder\{
    OpenApi, Info, Path, Operation, Parameter, Response, MediaType, Schema
};

$listPets = (new Operation())
    ->tag('Pets')
    ->summary('List pets')
    ->operationId('listPets')
    ->parameter(
        new Parameter('limit', Parameter::IN_QUERY, new Schema(['type' => 'integer']))
    )
    ->response(
        200,
        (new Response('A list of pets'))
            ->content(
                'application/json',
                (new MediaType())->schema(new Schema([
                    'type'  => 'array',
                    'items' => ['$ref' => '#/components/schemas/Pet'],
                ]))
            )
    );

$openApi = new OpenApi(
    '3.0.0',
    new Info('Pet Store API', '1.0.0'),
    ['/pets' => (new Path())->get($listPets)]
);

echo json_encode($openApi->toArray(), JSON_PRETTY_PRINT);

All builder classes implement Illuminate\Contracts\Support\Arrayable, so toArray() produces the final spec.

Development

Install dev dependencies and run the test suite:

composer install
composer test

License

MIT