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.
$book = Schema::object('Book')
->properties(
Schema::string('title'),
Schema::string('subtitle')->nullable(),
)
->required('title');
$book->toJson();
{
"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.
Compatibility
Pure PHP, no framework: a script, a command, a Symfony or Laravel application.
| Version | PHP | Status |
|---|---|---|
| 1.x | ^8.2 | Active |
Start with OpenAPI Writer
Install it, follow the quick start, and see your first result in minutes.