Webman Auto Route 是一个基于 PHP8 注解开发的一个 Webman 扩展组件。
项目及文档地址
Webman Auto Route 可以做什么
- 为 Webman 项目的控制器提供注解路由功能
- 保留 Webman 路由中间件能力
- 根据注解信息实时生成 OpenAPI 3.0 文档
- 自带 Swagger UI 提供接口自测、对接
- 根据注解信息自动验证过滤输入信息 ( 1.0.0开始提供 )
快速开始
composer require qnnp/webman-auto-route
<?php #config/route.php
use Webman\Route;
use WebmanPress\AutoRoute\Module\AutoRoute;
// 直接使用
AutoRoute::load();
// 加载自定义组件
AutoRoute::load(
// 注解路由默认会扫描 /app 下的所有PHP文件
// 如果需要扫描其他文件夹或者组件的路由可以这样设置
[
[
'WebmanPress\Controller', // 命名空间根路径
WP_LIB_PATH . '/Controller' // 对应文件夹路径
],
],
true // false 禁用 OpenAPI 文档
// 注意:组件扫描文件时会自动跳过 . 开头的文件文件夹和 model view 文件夹
);
/**
* 因注解路由可注解加载中间件
* 防止需要中间件的被直接加载
* 安全起见关闭默认路由
* 需要自定义路由组或者其他自
* 定义路由可按照 Webman 文
* 档正常自行配置
*/
Route::disableDefaultRoute();
{
"components": {
"securitySchemes": []
},
"externalDocs": [],
"info": {
"title": "项目名称",
"description": "项目描述",
"version": "0.0.0",
"termsOfService": "http://localhost/service.html",
"contact": {
"name": "联系人",
"url": "http://localhost/contact.html",
"email": "example@example.com"
},
"license": {
"name": "API许可",
"url": "http://localhost/license.html"
}
},
"openapi": "3.0.3",
"security": [],
"servers": [],
"tags": [],
"paths": {
"/api/example/test": {
"get": {
"tags": [],
"summary": "",
"description": "",
"operationId": null,
"responses": {
"default": {
"description": ""
}
},
"deprecated": false
},
"post": {
"tags": [],
"summary": "",
"description": "",
"operationId": null,
"responses": {
"default": {
"description": ""
}
},
"deprecated": false
},
"put": {
"tags": [],
"summary": "",
"description": "",
"operationId": null,
"responses": {
"default": {
"description": ""
}
},
"deprecated": false
},
"patch": {
"tags": [],
"summary": "",
"description": "",
"operationId": null,
"responses": {
"default": {
"description": ""
}
},
"deprecated": false
},
"delete": {
"tags": [],
"summary": "",
"description": "",
"operationId": null,
"responses": {
"default": {
"description": ""
}
},
"deprecated": false
},
"head": {
"tags": [],
"summary": "",
"description": "",
"operationId": null,
"responses": {
"default": {
"description": ""
}
},
"deprecated": false
},
"options": {
"tags": [],
"summary": "",
"description": "",
"operationId": null,
"responses": {
"default": {
"description": ""
}
},
"deprecated": false
}
},
"/test1": {
"get": {
"tags": [],
"summary": "",
"description": "",
"operationId": null,
"responses": {
"default": {
"description": ""
}
},
"deprecated": false,
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"required": [
"field2"
],
"type": "object",
"properties": {
"file": {
"type": "file"
},
"field1": {
"type": "integer"
},
"field2": {
"type": "boolean"
}
}
}
},
"application/json": {
"schema": {
"required": [],
"type": "object",
"properties": {
"field1": {
"type": "string"
},
"field2": {
"type": "string"
}
}
}
}
},
"required": false
}
}
},
"/api/wp/v1/options": {
"get": {
"tags": [
"系统"
],
"summary": "获取系统选项列表",
"description": "",
"operationId": null,
"responses": {
"default": {
"description": ""
}
},
"deprecated": false
}
},
"/api/wp/v1/users": {
"get": {
"tags": [
"用户"
],
"summary": "",
"description": "",
"operationId": null,
"responses": {
"default": {
"description": ""
}
},
"deprecated": false,
"parameters": [
{
"in": "query",
"schema": {
"type": "string",
"enum": [
"status",
"last_active_time",
"created_at"
]
},
"name": "orderBy"
},
{
"in": "query",
"schema": {
"type": "string",
"enum": [
"asc",
"desc"
]
},
"default": "desc",
"name": "order"
},
{
"in": "query",
"schema": {
"type": "integer"
},
"default": 1,
"name": "page"
},
{
"in": "query",
"schema": {
"type": "string"
},
"default": 10,
"name": "limit"
}
]
}
},
"/api/wp/v1/users/me": {
"get": {
"tags": [
"用户"
],
"summary": "获取当前用户信息",
"description": "",
"operationId": null,
"responses": {
"default": {
"description": ""
}
},
"deprecated": false
},
"patch": {
"tags": [
"用户"
],
"summary": "修改当前用户信息",
"description": "详细说明",
"operationId": null,
"responses": {
"default": {
"description": ""
}
},
"deprecated": false,
"requestBody": {
"content": {
"application/x-www-form-urlencoded": {
"schema": {
"required": [],
"type": "object",
"properties": {
"username": {
"type": "string"
},
"email": {
"type": "string"
},
"email_code": {
"type": "string"
},
"phone": {
"type": "string"
},
"phone_code": {
"type": "string"
},
"password": {
"type": "string"
},
"password_confirmation": {
"type": "string"
},
"salt": {
"type": "string"
}
}
}
}
},
"required": false
}
}
},
"/api/wp/v1/users/token": {
"post": {
"tags": [
"用户"
],
"summary": "创建用户认证 Token",
"description": "",
"operationId": null,
"responses": {
"default": {
"description": ""
}
},
"deprecated": false,
"requestBody": {
"content": {
"application/x-www-form-urlencoded": {
"schema": {
"required": [
"identity",
"password"
],
"type": "object",
"properties": {
"identity": {
"type": "string"
},
"password": {
"type": "string"
},
"ttl": {
"type": "integer"
}
}
}
}
},
"required": false
}
},
"get": {
"tags": [
"用户"
],
"summary": "验证用户 Token 有效",
"description": "",
"operationId": null,
"responses": {
"default": {
"description": ""
}
},
"deprecated": false
}
},
"/api/wp/v1/users/{user_ID}": {
"get": {
"tags": [],
"summary": "",
"description": "",
"operationId": null,
"responses": {
"default": {
"description": ""
}
},
"deprecated": false,
"parameters": [
{
"name": "user_ID",
"in": "path",
"required": true,
"description": "用户ID",
"schema": {
"type": "string",
"pattern": "^\\w+$"
}
}
]
}
}
}
}
留言