parent
90296720d9
commit
c4a30b8e27
|
|
@ -301,7 +301,7 @@ use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
// Swagger Documentation - редирект на Swagger UI
|
// Swagger Documentation - редирект на Swagger UI
|
||||||
Route::get('/docs', function () {
|
Route::get('/docs', function () {
|
||||||
return redirect()->to('/docs/index.html');
|
return redirect()->to('/spectrum/openapi.html');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Public routes (без авторизации)
|
// Public routes (без авторизации)
|
||||||
|
|
@ -401,65 +401,31 @@ curl -X POST http://la.test/api/logout \
|
||||||
|
|
||||||
### 6.2 Генерация документации
|
### 6.2 Генерация документации
|
||||||
|
|
||||||
Сначала сгенерируйте OpenAPI спецификацию:
|
Laravel Spectrum генерирует готовый HTML с Swagger UI:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
php artisan spectrum:generate
|
php artisan spectrum:generate --format=html
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Это создаёт файл `public/spectrum/openapi.html`.
|
||||||
|
|
||||||
### 6.3 Настройка доступа
|
### 6.3 Настройка доступа
|
||||||
|
|
||||||
Для работы Swagger UI необходимо:
|
При генерации с флагом `--format=html` symlink создаётся автоматически.
|
||||||
|
|
||||||
**1. Создать символическую ссылку:**
|
Если symlink отсутствует, создайте его вручную:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
ln -sf /home/user/www/lara/storage/app/spectrum /home/user/www/lara/public/spectrum
|
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 Файлы документации
|
### 6.4 Файлы документации
|
||||||
|
|
||||||
```
|
```
|
||||||
public/
|
public/
|
||||||
└── docs/
|
└── spectrum/
|
||||||
└── index.html # Swagger UI
|
├── openapi.html # Swagger UI (генерируется с --format=html)
|
||||||
|
└── openapi.json # OpenAPI спецификация
|
||||||
storage/
|
|
||||||
└── app/
|
|
||||||
└── spectrum/
|
|
||||||
└── openapi.json # OpenAPI спецификация
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### 6.5 Маршрут для документации
|
### 6.5 Маршрут для документации
|
||||||
|
|
@ -469,7 +435,7 @@ storage/
|
||||||
|
|
||||||
// Swagger Documentation
|
// Swagger Documentation
|
||||||
Route::get('/docs', function () {
|
Route::get('/docs', function () {
|
||||||
return redirect()->to('/docs/index.html');
|
return redirect()->to('/spectrum/openapi.html');
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -491,8 +457,8 @@ Laravel Spectrum поставляется с готовыми командами
|
||||||
### 7.2 Генерация документации
|
### 7.2 Генерация документации
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Генерация документации
|
# Генерация документации в формате HTML
|
||||||
php artisan spectrum:generate
|
php artisan spectrum:generate --format=html
|
||||||
```
|
```
|
||||||
|
|
||||||
**Вывод:**
|
**Вывод:**
|
||||||
|
|
@ -501,7 +467,7 @@ php artisan spectrum:generate
|
||||||
🔍 Analyzing routes...
|
🔍 Analyzing routes...
|
||||||
Found 9 API routes
|
Found 9 API routes
|
||||||
📝 Generating OpenAPI specification...
|
📝 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
|
⏱️ Generation completed in 0.17 seconds
|
||||||
💾 Cache: 5 files, 7.04 KB
|
💾 Cache: 5 files, 7.04 KB
|
||||||
✅ Documentation generated successfully!
|
✅ 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
|
// Swagger Documentation
|
||||||
Route::get('/docs', function () {
|
Route::get('/docs', function () {
|
||||||
return redirect()->to('/docs/index.html');
|
return redirect()->to('/spectrum/openapi.html');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Public routes
|
// Public routes
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue