parent
90296720d9
commit
c4a30b8e27
|
|
@ -301,7 +301,7 @@ use Illuminate\Support\Facades\Route;
|
|||
|
||||
// Swagger Documentation - редирект на Swagger UI
|
||||
Route::get('/docs', function () {
|
||||
return redirect()->to('/docs/index.html');
|
||||
return redirect()->to('/spectrum/openapi.html');
|
||||
});
|
||||
|
||||
// Public routes (без авторизации)
|
||||
|
|
@ -401,64 +401,30 @@ curl -X POST http://la.test/api/logout \
|
|||
|
||||
### 6.2 Генерация документации
|
||||
|
||||
Сначала сгенерируйте OpenAPI спецификацию:
|
||||
Laravel Spectrum генерирует готовый HTML с Swagger UI:
|
||||
|
||||
```bash
|
||||
php artisan spectrum:generate
|
||||
php artisan spectrum:generate --format=html
|
||||
```
|
||||
|
||||
Это создаёт файл `public/spectrum/openapi.html`.
|
||||
|
||||
### 6.3 Настройка доступа
|
||||
|
||||
Для работы Swagger UI необходимо:
|
||||
При генерации с флагом `--format=html` symlink создаётся автоматически.
|
||||
|
||||
**1. Создать символическую ссылку:**
|
||||
Если symlink отсутствует, создайте его вручную:
|
||||
|
||||
```bash
|
||||
ln -sf /home/user/www/lara/storage/app/spectrum /home/user/www/lara/public/spectrum
|
||||
```
|
||||
|
||||
**2. Создать HTML файл Swagger UI:**
|
||||
|
||||
```html
|
||||
<!-- public/docs/index.html -->
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>API Documentation - Swagger UI</title>
|
||||
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@5.9.0/swagger-ui.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="swagger-ui"></div>
|
||||
<script src="https://unpkg.com/swagger-ui-dist@5.9.0/swagger-ui-bundle.js"></script>
|
||||
<script>
|
||||
window.onload = function() {
|
||||
SwaggerUIBundle({
|
||||
url: "/spectrum/openapi.json",
|
||||
dom_id: '#swagger-ui',
|
||||
presets: [
|
||||
SwaggerUIBundle.presets.apis
|
||||
],
|
||||
docExpansion: "list",
|
||||
persistAuthorization: true
|
||||
});
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
### 6.4 Файлы документации
|
||||
|
||||
```
|
||||
public/
|
||||
└── docs/
|
||||
└── index.html # Swagger UI
|
||||
|
||||
storage/
|
||||
└── app/
|
||||
└── spectrum/
|
||||
├── openapi.html # Swagger UI (генерируется с --format=html)
|
||||
└── openapi.json # OpenAPI спецификация
|
||||
```
|
||||
|
||||
|
|
@ -469,7 +435,7 @@ storage/
|
|||
|
||||
// Swagger Documentation
|
||||
Route::get('/docs', function () {
|
||||
return redirect()->to('/docs/index.html');
|
||||
return redirect()->to('/spectrum/openapi.html');
|
||||
});
|
||||
```
|
||||
|
||||
|
|
@ -491,8 +457,8 @@ Laravel Spectrum поставляется с готовыми командами
|
|||
### 7.2 Генерация документации
|
||||
|
||||
```bash
|
||||
# Генерация документации
|
||||
php artisan spectrum:generate
|
||||
# Генерация документации в формате HTML
|
||||
php artisan spectrum:generate --format=html
|
||||
```
|
||||
|
||||
**Вывод:**
|
||||
|
|
@ -501,7 +467,7 @@ php artisan spectrum:generate
|
|||
🔍 Analyzing routes...
|
||||
Found 9 API routes
|
||||
📝 Generating OpenAPI specification...
|
||||
✅ Documentation generated: /home/user/www/lara/storage/app/spectrum/openapi.json
|
||||
✅ Documentation generated: /home/user/www/lara/public/spectrum/openapi.html
|
||||
⏱️ Generation completed in 0.17 seconds
|
||||
💾 Cache: 5 files, 7.04 KB
|
||||
✅ Documentation generated successfully!
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>API Documentation - Swagger UI</title>
|
||||
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@5.9.0/swagger-ui.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="swagger-ui"></div>
|
||||
<script src="https://unpkg.com/swagger-ui-dist@5.9.0/swagger-ui-bundle.js"></script>
|
||||
<script>
|
||||
window.onload = function() {
|
||||
SwaggerUIBundle({
|
||||
url: "/spectrum/openapi.json",
|
||||
dom_id: '#swagger-ui',
|
||||
presets: [
|
||||
SwaggerUIBundle.presets.apis
|
||||
],
|
||||
docExpansion: "list",
|
||||
persistAuthorization: true
|
||||
});
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>API Documentation - Swagger UI</title>
|
||||
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@5.9.0/swagger-ui.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="swagger-ui"></div>
|
||||
<script src="https://unpkg.com/swagger-ui-dist@5.9.0/swagger-ui-bundle.js"></script>
|
||||
<script>
|
||||
window.onload = function() {
|
||||
SwaggerUIBundle({
|
||||
url: "/spectrum/openapi.json",
|
||||
dom_id: '#swagger-ui',
|
||||
presets: [
|
||||
SwaggerUIBundle.presets.apis
|
||||
],
|
||||
docExpansion: "list",
|
||||
persistAuthorization: true
|
||||
});
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ use Illuminate\Support\Facades\Route;
|
|||
|
||||
// Swagger Documentation
|
||||
Route::get('/docs', function () {
|
||||
return redirect()->to('/docs/index.html');
|
||||
return redirect()->to('/spectrum/openapi.html');
|
||||
});
|
||||
|
||||
// Public routes
|
||||
|
|
|
|||
Loading…
Reference in New Issue