uuf6429/oas-php

OpenAPI Specification PHP implementation

v0.1-alpha 2020-03-25 19:21 UTC

This package is auto-updated.

Last update: 2024-11-06 09:40:17 UTC


README

Minimum PHP Version License Packagist

OAS-PHP: PHP Implementation of the OpenAPI Spec.

This library is an implementation of the OpenAPI v3 specification.

Usage

This library is just a bunch of value objects. The main entry point, (as is the case with the specification), is the Document class:

$document = new \uuf6429\OpenAPI\Spec\Document();
$path = new \uuf6429\OpenAPI\Path();
$document->paths->set('/resource', $path);

Rendering

Ideally, it should be render with a YAML serializer (such as symfony's). Since YAML is a superset of JSON, one can also do:

$document = new Document();
$json = json_encode($document, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT);

// save to file
file_put_contents('openapi.yaml', $json);

// or serve it out
header('Content-Type: application/x-yaml');
echo $json;

Why?

This library isn't better than the multitude of generators and whatnot out there. The idea is that existing and new PHP-based tools that handle OpenAPI could/should use this implementation instead of having their own version of OpenAPI spec.