Skip to content
Swagger parser for PHP
PHP
Branch: 2.0
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/Swagger
tests/Swagger
.gitignore
.travis.yml
LICENSE.md
README.md
composer.json
composer.lock
phpunit.xml.dist

README.md

Swagger Parser

Parse Swagger specification documents programmatically, and also parse data structures according to a specification.

Installation

composer require thefrozenfire/swagger:^2.0

License

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?>
You can’t perform that action at this time.