membrane/openapi-reader

2.1.1 2024-11-07 12:44 UTC

README

This library is intended to be used in conjunction with other Membrane libraries.

It wraps the php-openapi library with some additional validation, including Membrane-specific requirements.

Requirements

Installation

composer require membrane/openapi-router

Quick Start

Instantiate a Reader

$versions = [\Membrane\OpenAPIReader\OpenAPIVersion::Version_3_0];

$reader = new \Membrane\OpenAPIReader\Reader($versions);

Read From An Absolute File Path

This method is the main use-case of the reader and is capable of resolving all references.

If your file path contains the file extension then the reader can use this to determine which language the OpenAPI is written in.

// code to instantiate reader... 

$reader->readFromAbsoluteFilePath('~/path/to/my-openapi.yaml');

Otherwise, you may ensure it reads the file as a specific format by providing a second argument:

// code to instantiate reader... 

$fileFormat = \Membrane\OpenAPIReader\FileFormat::Json;

$reader->readFromAbsoluteFilePath('my-openapi', $fileFormat);

Read From A String

This method is only capable of resolving Reference Objects, it cannot resolve references to Relative Documents .

Because the OpenAPI will be read from a string, the FileFormat MUST be provided.

// code to instantiate reader... 

$myOpenAPI = '<Insert your OpenAPI Spec here>';
$fileFormat = \Membrane\OpenAPIReader\FileFormat::Json;

$reader->readFromString($myOpenAPI, $fileFormat)