Skip to content

Commit 8240991

Browse files
committed
add rapidoc html
1 parent d3c0721 commit 8240991

File tree

6 files changed

+24
-14
lines changed

6 files changed

+24
-14
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ php bin/hyperf.php start
208208
* 访问`/swagger`可以看到swagger页面
209209
* 已安装[knife4j-ui](https://github.com/tw2066/knife4j-ui),访问`/swagger/doc`可以看到knife4j页面
210210
* 访问`/swagger/redoc`,可以看到[redoc](https://github.com/Redocly/redoc)页面
211+
* 访问`/swagger/rapidoc`,可以看到[rapidoc](https://github.com/rapi-doc/RapiDoc)页面
211212

212213
## 注解
213214

example/Controller/DemoController.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,6 @@ public function fromData(#[RequestFormData] DemoFormData $formData): array
112112
#[ApiOperation('4:查询单条记录')]
113113
#[GetMapping(path: 'find/{id}/and/{in}')]
114114
#[ApiHeader('test2')]
115-
#[ApiResponse()]
116-
#[ApiResponse(PhpType::BOOL, 11)]
117-
#[ApiResponse(PhpType::INT, 12)]
118-
#[ApiResponse(PhpType::FLOAT, 13)]
119-
#[ApiResponse(PhpType::ARRAY, 14)]
120-
#[ApiResponse(PhpType::OBJECT, 15)]
121-
#[ApiResponse(PhpType::STRING, 16)]
122-
#[ApiResponse([PhpType::BOOL], 101)]
123-
#[ApiResponse([PhpType::INT], 102)]
124-
#[ApiResponse([PhpType::FLOAT], 103)]
125-
#[ApiResponse([PhpType::ARRAY], 104)]
126-
#[ApiResponse([PhpType::OBJECT], 105)]
127-
#[ApiResponse([PhpType::STRING], 106)]
128115
#[ApiResponse([PhpType::BOOL])]
129116
#[ApiResponse(Address::class, 201)]
130117
#[ApiResponse(Address_1::class, 202)]

src/Listener/BootAppRouteListener.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public function process(object $event): void
7474
$httpServerRouter->addGroup($prefix, function ($route) {
7575
$route->get('', [SwaggerUiController::class, 'swagger']);
7676
$route->get('/redoc', [SwaggerUiController::class, 'redoc']);
77+
$route->get('/rapidoc', [SwaggerUiController::class, 'rapidoc']);
7778
$route->get('/doc', [SwaggerUiController::class, 'knife4j']);
7879
$route->get('/swagger-resources', [SwaggerUiController::class, 'swaggerResources']);
7980
$route->get('/webjars/{file:.*}', [SwaggerUiController::class, 'knife4jFile']);

src/Swagger/SwaggerConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class SwaggerConfig
1717

1818
private string $prefix_url = '';
1919

20-
private string $prefix_swagger_resources = 'https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.5.0';
20+
private string $prefix_swagger_resources = 'https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.27.1';
2121

2222
private bool $validation_custom_attributes = false;
2323

src/Swagger/SwaggerUiController.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ public function redoc(): PsrResponseInterface
3939
return $this->response->withAddedHeader('content-type', 'text/html')->withBody(new SwooleStream($contents));
4040
}
4141

42+
public function rapidoc(): PsrResponseInterface
43+
{
44+
// https://rapidocweb.com/examples.html
45+
$filePath = $this->docsWebPath . '/rapidoc.html';
46+
$contents = file_get_contents($filePath);
47+
$contents = str_replace('{{$url}}', BootAppRouteListener::$httpServerName . '.' . $this->swaggerConfig->getFormat(), $contents);
48+
return $this->response->withAddedHeader('content-type', 'text/html')->withBody(new SwooleStream($contents));
49+
}
50+
4251
public function knife4j()
4352
{
4453
$filePath = $this->swaggerUiPath . '/doc.html';

src/web/rapidoc.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html> <!-- Important: must specify -->
2+
<html>
3+
<head>
4+
<meta charset="utf-8"> <!-- Important: rapi-doc uses utf8 characters -->
5+
<script type="module" src="https://unpkg.com/rapidoc/dist/rapidoc-min.js"></script>
6+
</head>
7+
<body>
8+
<rapi-doc
9+
spec-url = "{{$url}}"
10+
> </rapi-doc>
11+
</body>
12+
</html>

0 commit comments

Comments
 (0)