定制 thefrozenfire/swagger 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

thefrozenfire/swagger

最新稳定版本:2.0.10

Composer 安装命令:

composer require thefrozenfire/swagger

包简介

Swagger parser for PHP

README 文档

README

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?>

统计信息

  • 总下载量: 103.36k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 29
  • 点击次数: 1
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 29
  • Watchers: 2
  • Forks: 16
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2013-10-18