specdocular/php-openapi

Object-oriented OpenAPI implementation for PHP

Installs: 268

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/specdocular/php-openapi

v0.1.0 2026-02-13 09:03 UTC

This package is auto-updated.

Last update: 2026-02-13 10:59:34 UTC


README

Latest Version on Packagist PHP Version Tests codecov Code Style

An object-oriented OpenAPI 3.1.x builder for PHP. Build complete API specifications with a fluent, chainable API that hides the complexity of the OpenAPI specification.

Installation

composer require specdocular/php-openapi

Usage

use Specdocular\OpenAPI\Schema\Objects\OpenAPI\OpenAPI;
use Specdocular\OpenAPI\Schema\Objects\Info\Info;
use Specdocular\OpenAPI\Schema\Objects\PathItem\PathItem;
use Specdocular\OpenAPI\Schema\Objects\Operation\Operation;
use Specdocular\OpenAPI\Schema\Objects\Schema\Schema;
use Specdocular\JsonSchema\Draft202012\Keywords\Properties\Property;

$openApi = OpenAPI::v311(
    Info::create('Pet Store', '1.0.0')
        ->description('A sample Pet Store API')
);

// Define schemas
$petSchema = Schema::object()
    ->properties(
        Property::create('id', Schema::string()->format('uuid')),
        Property::create('name', Schema::string()),
    )
    ->required('id', 'name');

// Export as JSON
$json = json_encode($openApi, JSON_PRETTY_PRINT);

Features

  • Fluent, chainable API for all OpenAPI 3.1.x objects
  • Full support for Paths, Operations, Schemas, Responses, Request Bodies, Parameters, Security Schemes, and more
  • Automatic component reference collection and management
  • Built on specdocular/php-json-schema for schema definitions
  • Framework-agnostic — no dependencies on Laravel or any framework

Related Packages

Package Description
specdocular/php-json-schema JSON Schema Draft 2020-12 builder (foundation)
specdocular/laravel-openapi Laravel integration for OpenAPI generation (uses this package)
specdocular/laravel-rules-to-schema Convert Laravel validation rules to JSON Schema

License

MIT. See LICENSE for details.