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.
- A valid OpenAPI specification.
- An operationId on all Operation Objects so that each route is uniquely identifiable.
composer require membrane/openapi-router
$versions = [\Membrane\OpenAPIReader\OpenAPIVersion::Version_3_0];
$reader = new \Membrane\OpenAPIReader\Reader($versions);
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);
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)