承接 mako/open-api 相关项目开发

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

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

mako/open-api

Composer 安装命令:

composer require mako/open-api

包简介

Generate routes based on OpenAPI specifications and OpenAPI specifications from code

README 文档

README

Static analysis

The mako/open-api package allows you to generate an OpenApi specification by documenting your code using PHP attributes, and to generate routes from an OpenAPI specification.

In addition, the package can render interactive API documentation for your OpenAPI specification using one of the following user interface providers:

  • Elements
  • Redoc
  • Scalar
  • Swagger (default)

Requirements

Mako 12.0 or greater.

Installation

First you'll need to install the package as a dependency to your project.

composer require mako/open-api

Next you'll need to add the package to the cli section of the packages configuration array in the application.php config file.

'cli' => [
	mako\openapi\OpenApiPackage::class,
]

And finally replace the contents of your routes.php file with the following:

<?php

use mako\openapi\http\routing\Registrar;

Registrar::register(
	$routes,
	cachedRoutes: __DIR__ . '/openapi.php',
	openApiSpec: __DIR__ . '/openapi.yaml',
);

Usage

You can build an OpenAPI specification using a tool such as Apicurito or by documenting your code using PHP attributes. For details on the available syntax, see the zircote/swagger-php documentation.

Here is a basic example of documenting API routes using attributes::

<?php

namespace app\http\controllers;

use OpenApi\Attributes as OA;

#[OA\Info(
	title: 'Example API',
	version: '1.0.0'
)]
class OpenApiExample
{
	#[OA\Get(
        path: '/',
        responses: [
            new OA\Response(response: 200, description: 'Displays a greeting to the user.'),
        ]
    )]
	public function __invoke(): string
	{
		return 'Welcome to the OpenApi example!';
	}
}

If you want to generate a specification file from your documentation, you can do so by running the open-api:generate-spec command.

Below is an example of the generated specification:

openapi: 3.0.0
info:
  title: 'Example API'
  version: 1.0.0
paths:
  /:
    get:
      operationId: app\http\controllers\OpenApiExample
      responses:
        '200':
          description: 'Displays a greeting to the user.'

Note: If you manually write your OpenAPI specification, you must set the operationId parameter to the fully qualified method name (for example, app\controllers\Index::welcome) of the controller action in order for the route generator to work.

When running in production, it is strongly recommended to generate a cached route file for maximum performance. To do so, run the open-api:generate-routes command.

mako/open-api 适用场景与选型建议

mako/open-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 37.13k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 10 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「framework」 「mako」 「open-api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mako/open-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mako/open-api 我们能提供哪些服务?
定制开发 / 二次开发

基于 mako/open-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2021-10-12