https://github.com/phpowermove/swagger
A php library to manipulate swagger specifications
https://github.com/phpowermove/swagger
Last synced: over 1 year ago
JSON representation
A php library to manipulate swagger specifications
- Host: GitHub
- URL: https://github.com/phpowermove/swagger
- Owner: phpowermove
- License: mit
- Created: 2015-11-30T15:40:11.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2021-09-23T15:28:19.000Z (almost 5 years ago)
- Last Synced: 2025-03-29T15:21:08.594Z (over 1 year ago)
- Language: PHP
- Size: 73.2 KB
- Stars: 16
- Watchers: 1
- Forks: 18
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# swagger
[](https://packagist.org/packages/gossi/swagger)
[](https://packagist.org/packages/gossi/swagger)
[](https://packagist.org/packages/gossi/swagger)
[](http://hhvm.h4cc.de/package/gossi/swagger)
[](https://travis-ci.org/gossi/swagger)
[](https://scrutinizer-ci.com/g/gossi/swagger/?branch=master)
[](https://scrutinizer-ci.com/g/gossi/swagger/?branch=master)
A php library to manipulate [swagger](http://swagger.io)/[Open API](https://openapis.org) specifications.
## Installation
```
composer require gossi/swagger
```
## Usage
Read an `api.json` file:
```php
$swagger = Swagger::fromFile('api.json');
// or
$swagger = new Swagger($array);
```
### Collections
There are two major collections: `Paths` and `Definitions`. The API is similar for both:
```php
$paths = $swagger->getPaths();
$p = new Path('/user');
// adding
$paths->add($p);
// retrieving
if ($paths->has('/user') || $paths->contains($p)) {
$path = $paths->get('/user');
}
// removing
$paths->remove('/user');
// iterating
foreach ($paths as $path) {
// do sth with $path
}
```
Other collections are: `Headers`, `Parameters`, `Responses` and `SecurityDefinitions`.
### Models
There are a lot of models, e.g. the mentioned `Path` above. The API is well written, so it works with the auto-completion of your IDE. It is straight forward and uses the same naming scheme as the OpenAPI specification.
## Contributing
Feel free to fork and submit a pull request (don't forget the tests) and I am happy to merge.