This commit is contained in:
zhang zhuo 2025-10-24 18:06:39 +08:00
parent 6b01b51450
commit 02b054ac2c
2 changed files with 34 additions and 49 deletions

View File

@ -34,12 +34,32 @@ use Hyperf\HttpServer\Annotation\DeleteMapping;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\HttpServer\Annotation\PutMapping;
use Hyperf\Swagger\Annotation as SA;
#[Controller(prefix: "admin")]
#[SA\HyperfServer('user')]
class System extends Base
{
#[GetMapping(path: "menu/list")]
#[Auth(needAuth: false, auth: "menu:list")]
#[SA\Post(path: '/menu/list', summary: '菜单接口', tags: ['菜单接口'])]
#[SA\RequestBody(
description: '请求参数',
content: [
new SA\MediaType(
mediaType: 'application/json',
schema: new SA\Schema(
required: ['username', 'age'],
properties: [
new SA\Property(property: 'username', description: '用户名字段描述', type: 'string'),
new SA\Property(property: 'age', description: '年龄字段描述', type: 'string'),
new SA\Property(property: 'city', description: '城市字段描述', type: 'string'),
]
),
),
],
)]
#[SA\Response(response: 200, description: '返回值的描述')]
public function menuList()
{
return $this->success("菜单列表", mModel::getMenus(1));

View File

@ -8,62 +8,14 @@ return [
'enable' => true,
'port' => (int)env("SWAGGER_PORT", 9500),
'json_dir' => BASE_PATH . '/static/swagger',
'html' => <<<'HTML'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta
name="description"
content="SwaggerUI"
/>
<title>SwaggerUI</title>
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@4.5.0/swagger-ui.css" />
</head>
<body>
<div id="swagger-ui"></div>
<script src="https://unpkg.com/swagger-ui-dist@4.5.0/swagger-ui-bundle.js" crossorigin></script>
<script src="https://unpkg.com/swagger-ui-dist@4.5.0/swagger-ui-standalone-preset.js" crossorigin></script>
<script>
window.onload = () => {
window.ui = SwaggerUIBundle({
url: GetQueryString("search"),
dom_id: '#swagger-ui',
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
layout: "StandaloneLayout",
});
};
function GetQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg); //获取url中"?"符后的字符串并正则匹配
var context = "";
if (r != null)
context = decodeURIComponent(r[2]);
reg = null;
r = null;
return context == null || context == "" || context == "undefined" ? "/http.json" : context;
}
</script>
</body>
</html>
HTML,
'url' => '/swagger',
'path' =>'/swagger',
'auto_generate' => true,
'scan' => [
'paths' => [
BASE_PATH . '/app/Controller/Admin'
],
],
'processors' => [
// users can append their own processors here
],
'server' => [
'http' => [
'admin' => [
'servers' => [
[
'url' => env('DOMAIN') . '/admin',
@ -76,5 +28,18 @@ HTML,
'version' => '1.0.0',
],
],
'user' => [
'servers' => [
[
'url' => env('DOMAIN') . '/user',
'description' => '用户接口',
],
],
'info' => [
'title' => '里派基础接口',
'description' => '用户端接口',
'version' => '1.0.0',
],
],
],
];