https://github.com/membrane-php/openapi-reader
https://github.com/membrane-php/openapi-reader
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/membrane-php/openapi-reader
- Owner: membrane-php
- License: other
- Created: 2023-09-01T09:13:17.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-21T19:09:14.000Z (almost 2 years ago)
- Last Synced: 2024-04-21T23:17:44.354Z (almost 2 years ago)
- Language: PHP
- Size: 221 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OpenAPI Reader
This library is intended to be used in conjunction with other Membrane libraries.
It wraps the [php-openapi](https://github.com/cebe/php-openapi) library with some additional validation, including
Membrane-specific requirements.
## Requirements
- A valid [OpenAPI specification](https://github.com/OAI/OpenAPI-Specification#readme).
- An operationId on all [Operation Objects](https://spec.openapis.org/oas/v3.1.0#operation-object) so that each route is
uniquely identifiable.
## Installation
```text
composer require membrane/openapi-router
```
## Quick Start
### Instantiate a Reader
```php
$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.
```php
// 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:
```php
// 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](https://spec.openapis.org/oas/v3.1.0#reference-object-example),
it cannot resolve references to
[Relative Documents](https://spec.openapis.org/oas/v3.1.0#relative-schema-document-example)
.
Because the OpenAPI will be read from a string, the FileFormat MUST be provided.
```php
// code to instantiate reader...
$myOpenAPI = '';
$fileFormat = \Membrane\OpenAPIReader\FileFormat::Json;
$reader->readFromString($myOpenAPI, $fileFormat)
```