noitran / opendox
Lumen 5.5+ 和 Laravel 5.5+ 的 OpenApi(Swagger) 3.0 包,包含 REDOC UI 和 SwaggerUI 3
v1.0.0
2021-05-21 17:26 UTC
Requires
- php: >=7.3
- ext-json: *
- illuminate/routing: ^5|^6|^7|^8
- symfony/yaml: ^5.0
Requires (Dev)
- illuminate/console: ^6.0|^7.0|^8.0
- illuminate/http: ^6.0|^7.0|^8.0
- illuminate/support: ^6.0|^7.0|^8.0
- laravel/lumen-framework: ~8.0
- orchestra/testbench: ^4.0|^5.0|^6.0
- phpunit/phpunit: ~7.0
This package is auto-updated.
Last update: 2024-09-22 00:43:49 UTC
README
关于
此包将为 Lumen/Laravel 添加控制台命令,用于解析 yml 文件,将其转换为 json 并保存到 public 路径。Redoc UI 和 Swagger UI 已连接,可以通过指定的路由访问生成的文档。此外,包还添加了用于获取原始 json 文档输出的路由,因此此包可用于微服务架构,其中所有微服务都公开了可用的路由列表。
特性
- 添加控制台命令
php artisan opendox:transform
,将 OpenApi 3.0 规范 yaml 文件转换为 json,以便外部服务可以访问 - 添加
/api/documentation
路由,您可以通过该路由访问文档的 Redoc UI 接口 - 添加
/api/console
路由,您可以通过该路由访问 Swagger UI 接口进行 API 文档和交互 - 添加
/docs
路由,可以访问原始 json
安装
- 作为 composer 包安装
$ composer require noitran/opendox
Laravel
- Laravel 使用提供者自动发现。可以使用命令发布配置文件
$ php artisan vendor:publish --provider="Noitran\Opendox\ServiceProvider"
Lumen
- 打开您的 bootstrap/app.php 文件,将其注册为服务提供者
$app->register(Noitran\Opendox\ServiceProvider::class);
- 配置文件应在 bootstrap/app.php 中手动加载
$app->configure('opendox');
用法
- 在您的应用程序项目
/src
文件夹中创建api-docs.yml
文件。使用 OpenAPI 标准编写文档
示例
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
format: int32
responses:
'200':
description: A paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
schemas:
Pet:
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
items:
$ref: "#/components/schemas/Pet"
Error:
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
- 使用命令转换并发布您的配置文件
$ php artisan opendox:transform
- 现在,您的文档可以通过指定的路由访问
/api/documentation - Redoc UI interface
/api/console - Swagger UI with ability to send example requests
/docs - Raw JSON documentation output, that can be used for external services