v1.0.0is out

OpenAPI Writer

Framework-agnostic, fluent and immutable PHP builder for OpenAPI 3.0, 3.1 and 3.2 documents, written as JSON or YAML and validated.

PHP
$book = Schema::object('Book')
    ->properties(
        Schema::string('title'),
        Schema::string('subtitle')->nullable(),
    )
    ->required('title');

$book->toJson();
$book->toJson() — OpenAPI 3.1.2
{
  "type": "object",
  "required": ["title"],
  "properties": {
    "title": { "type": "string" },
    "subtitle": { "type": ["string", "null"] }
  }
}

Why OpenAPI Writer

Hand-written OpenAPI arrays drift from the specification and break at each version. Describe your API once with PHP objects; the library writes what each version expects, and checks it.

One model, every version

3.0.0 to 3.0.4, 3.1.0 to 3.1.2 and 3.2.0 from the same objects: $book->toJson('3.0.4') writes the subtitle as "nullable": true.

Differences converted

nullable, exclusiveMinimum, examples and the rest are rewritten for the target version, and every change is reported.

Validated

Against the official schema of the version, plus ten semantic rules, before your users find the errors.

JSON, YAML or array

Stable key order for small diffs, from the whole document down to a single schema.

Compatibility

Pure PHP, no framework: a script, a command, a Symfony or Laravel application.

VersionPHPStatus
1.x^8.2Active

Start with OpenAPI Writer

Install it, follow the quick start, and see your first result in minutes.

Works with

Laravel OpenAPI Generator
Generates OpenAPI 3.0, 3.1 and 3.2 documents from a Laravel application, its routes, form requests and resources.
v1.2.0ark4ne/laravel-openapi-generator