membrane / openapi-reader
Installs: 4 979
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 16
Requires
- php: ^8.1.0
- devizzent/cebe-php-openapi: ^1.1.0
Requires (Dev)
- infection/infection: ^0.29.7
- mikey179/vfsstream: ^1.6.7
- phpstan/phpstan: ^1.12.6
- phpunit/phpunit: ^10.5.36
- squizlabs/php_codesniffer: ^3.5.4
This package is auto-updated.
Last update: 2024-11-22 12:28:47 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
- A valid OpenAPI specification.
- An operationId on all Operation Objects so that each route is uniquely identifiable.
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)