承接 wedo/openapi-generator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

wedo/openapi-generator

最新稳定版本:v2.0.0

Composer 安装命令:

composer require wedo/openapi-generator

包简介

Open api json generator from typed classes

README 文档

README

Framework agnostic Open api generator from phpdoc and php type hints

Latest Stable Version build codecov PHPStan License

Installation

$ composer require wedo/openapi-generator

Configuration

see src/Config.php

Usage

Check tests folder, there's full working minimal API there: https://github.com/WEDOehf/openapi-generator/tree/master/tests

this is minimal config required to run, to check all options see src/Config.php

//minimal config
$config = new Config();
$config->baseRequest = BaseRequest::class;
$config->serverUrl = 'https://www.mydomain.com/api/v1';
$config->baseEnum = BaseEnum::class; // use with @see annotation if U want to provide user enum options
$config->requiredAnnotation = '@required'; //what annotation should be used on requests to confirm that parameter is required
$config->namespace = 'App\Api\Controllers\\';
$config->path = __DIR__ . 'Api/Controllers';

$generator = new Generator($config);

//add standard error response to ref list
$this->generator->onBeforeGenerate[] = function () {
    $this->generator->getRefProcessor()->generateRef(ClassType::from(ErrorResponse::class));
};

$this->generator->getClassProcessor()->getMethodProcessor()->onProcess[] = function() {
        // set some standard error responses for each endpoint
        $methodProcessor = $this->generator->getClassProcessor()->getMethodProcessor();
        $path->responses[400] = $methodProcessor->createResponse('Bad request error response', 'ErrorResponse');
        
        $annotations = $method->getAnnotations();
        if (!empty($annotations['throws'])) {
            // add your own error responses classes for some specific exceptions
        }
}

//set some title
$this->generator->getJson()->info->title = 'My api';

//add your security schemes if needed
$this->generator->getJson()->components->securitySchemes = [
    'APIKeyHeader' => [
            'type' => 'apiKey',
            'in' => 'header',
            'name' => 'api-key',
        ]
];

$json = $this->generator->generate();
file_put_contents('open-api.json', $json);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-10-11