phrity/slim-openapi 问题修复 & 功能扩展

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

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

phrity/slim-openapi

最新稳定版本:1.2.2

Composer 安装命令:

composer require phrity/slim-openapi

包简介

OpenApi implementation for Slim 4.

README 文档

README

Build Status Coverage Status

OpenApi for Slim v4

Adapter that reads OpenApi schema and add included routes to Slim. By defining operationId in OpenApi schema, the adapter will automatically instanciate and call referenced controller class.

Some features

  • Automatic mapping of routes to controllers
  • OpenApi specification in JSON or YAML source
  • Optional validation of requests and responses

Installation

Install with Composer;

composer require phrity/slim-openapi

How to use

use Phrity\Slim\OpenApi;
use Slim\Factory\AppFactory;

// Create Slim App as you normally would
$slim = AppFactory::create();

// Create OpenApi adapter with OpenApi source
$openapi = new OpenApi('openapi.json');

// Push all routes from OpenApi to Slim
$openapi->route($slim);

// Run Slim
$slim->run();

How to define controllers

In order for automatic mapping to work, the operationId must be set on all defined routes in OpenApi source. If no method is specified, class method __invoke() will be called on class.

With invoke With method
 Classname Classname:method
 Namespace/Classname Namespace/Classname:method
 Namespace\\Classname Namespace\\Classname:method

Example

{
    "openapi": "3.0.0",
    "paths": {
        "/test": {
            "get": {
                "operationId": "Test/MyController",
                "description": "Will invoke on class Test\\MyController"
            },
            "put": {
                "operationId": "Test\\MyController:put",
                "description": "Will call method put() on class Test\\MyController"
            }
        }
    }
}

Documentation

Versions

Version PHP
1.2 ^7.4|^8.0 Request/Response validation, YAML support
1.1 ^7.4|^8.0 Settings & helpers
1.0 ^7.4|^8.0 Route registry

统计信息

  • 总下载量: 1.28k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-21