apiboard/php-openapi 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

apiboard/php-openapi

最新稳定版本:2.1.3

Composer 安装命令:

composer require apiboard/php-openapi

包简介

OpenAPI Specification library for PHP 8. Supports both OAS 3.0 and 3.1.

README 文档

README

OpenAPI Specification parser for PHP 8. Supports both OAS 3.0 and 3.1.

Latest Version on Packagist PHP from Packagist CI

Features

  • Parse OpenAPI files into a PHP object to interact with in code
  • Validate OpenAPI files against the official JSON-schema descriptions
  • Resolve external and internal references

Installation

composer require apiboard/php-openapi

Usage

You can interact with this library through the OpenAPI::class directly.

$openAPI = new OpenAPI();

This class optionally accepts an implementation of Apiboard\OpenAPI\Contents\Retriever::class which will be used to retrieve the file contents. By default the local filesystem will be used to retrieve file contents.

Parse

You can parse the contents of a file by passing its path to parse(). This will attempt to retrieve the file's contents and resolve any external references.

It returns a PHP object that represents the OAS document structure that can be used in code.

$document = $openAPI->parse('/path/to/my-oas.json');

$document->openapi(); // 3.1.0

Validate

You can directly validate the contents of a file against the official OpenAPI JSON-schema descriptions. It returns an array of possible errors that occured during the validation.

$errors = $openAPI->validate('/path/to/my-oas.yaml');

⚠️ Validation for OAS 3.1 does not check any JSON Schemas in your OpenAPI document because it allows you to use any JSON Schema dialect you choose!

Resolve

You can resolve external and internal references. It returns a PHP object with the resolved contents.

$contents = $openAPI->resolve('/path/to/my-oas.json');

$document = new Apiboard\OpenAPI\Structure\Document($contents);

When resolving references the contents will be retrieved from the local fileystem by default. You can override the way file contents is retrieved by passing a custom class that implements the Apiboard\OpenAPI\Contents\Retriever interface.

$customRetriever = new MyCustomRetriever();
$openAPI = new OpenAPI($customRetriever);

$openAPI->resolve('/path/to/my-oas.json');

Circular references are resolved as an internal reference after recursing twice, this is to prevent infinite recursion.

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 420
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-31

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固