thefrozenfire / swagger
Swagger parser for PHP
Installs: 102 245
Dependents: 2
Suggesters: 0
Security: 0
Stars: 28
Watchers: 4
Forks: 16
Open Issues: 3
Requires
- php: ^5.5
Requires (Dev)
- phpunit/phpunit: ~3.7.22
- satooshi/php-coveralls: ~0.6
README
Parse Swagger specification documents programmatically, and also parse data structures according to a specification.
Installation
composer require thefrozenfire/swagger:^2.0
License
- see LICENSE file
Use
Describe an Operation
<?php $spec = file_get_contents('http://petstore.swagger.io/v2/swagger.json'); $decodedSpec = json_decode($spec); $document = new Swagger\Document($decodedSpec); $operation = $document->getOperationById('addPet'); ?> Operation ID: <?=$operation->getOperationId()?> Tags: <?=implode(', ', $operation->getTags())?> Summary: <?=$operation->getSummary()?> Description: <?=$operation->getDescription()?> External Documentation: <?=$operation->getExternalDocs()?>
Parse a data structure
<?php $spec = file_get_contents('http://petstore.swagger.io/v2/swagger.json'); $decodedSpec = json_decode($spec); $dataToParse = '...'; $document = new Swagger\Document($decodedSpec); $schemaResolver = $document->getSchemaResolver(); $dataType = $document->getSchemaForOperationResponse( 'getPetById', 200 ); $schemaObject = $schemaResolver->parseType($dataType, $dataToParse); ?> Pet name: <?=$schemaObject->getProperty('name')?> Pet status: <?=$schemaObject->status?>