@famgia/omnify-laravel 0.0.108 → 0.0.109

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@famgia/omnify-laravel",
3
- "version": "0.0.108",
3
+ "version": "0.0.109",
4
4
  "description": "Laravel migration and TypeScript type generator for omnify-schema",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -25,9 +25,9 @@
25
25
  "README.md"
26
26
  ],
27
27
  "dependencies": {
28
- "@famgia/omnify-types": "0.0.97",
29
- "@famgia/omnify-core": "0.0.99",
30
- "@famgia/omnify-atlas": "0.0.93"
28
+ "@famgia/omnify-types": "0.0.98",
29
+ "@famgia/omnify-core": "0.0.100",
30
+ "@famgia/omnify-atlas": "0.0.94"
31
31
  },
32
32
  "scripts": {
33
33
  "build": "tsup",
@@ -6,18 +6,34 @@ alwaysApply: false
6
6
 
7
7
  # Controller Rules
8
8
 
9
- ## ⚠️ CRITICAL: OpenAPI Route Prefix
9
+ ## ⚠️ CRITICAL: Check Route Prefix BEFORE Writing OpenAPI
10
10
 
11
- **NEVER include `/api` in OpenAPI paths!** Laravel's `api.php` already has this prefix.
11
+ **MUST check route file prefix first!** Don't assume - VERIFY.
12
+
13
+ ### Before Writing OpenAPI Path:
14
+
15
+ 1. **Check route file** → Which file has your route? (`api.php`, `web.php`, custom?)
16
+ 2. **Check prefix** → Look in `RouteServiceProvider` or `bootstrap/app.php`
17
+ 3. **Write path WITHOUT prefix** → OpenAPI path = Route definition path
12
18
 
13
19
  ```php
14
- // CRITICAL BUG - Results in /api/api/users !!
20
+ // Route trong api.php (prefix: /api)
21
+ Route::get('/users', [UserController::class, 'index']);
22
+
23
+ // ❌ SAI - Duplicate prefix → /api/api/users !!
15
24
  #[OA\Get(path: '/api/users')]
16
25
 
17
- // ✅ CORRECT - api.php already adds /api prefix
18
- #[OA\Get(path: '/users')]
26
+ // ✅ ĐÚNG - Path không prefix
27
+ #[OA\Get(path: '/users')] // → /api/users
19
28
  ```
20
29
 
30
+ | Route File | Prefix | Route Definition | OpenAPI Path |
31
+ |------------|--------|------------------|--------------|
32
+ | `api.php` | `/api` | `/users` | `/users` |
33
+ | `web.php` | (none) | `/dashboard` | `/dashboard` |
34
+
35
+ **Full guide:** `.claude/guides/laravel/openapi.md`
36
+
21
37
  ---
22
38
 
23
39
  ## Golden Rule: Thin Controller
@@ -2,27 +2,70 @@
2
2
 
3
3
  > **Related:** [README](./README.md) | [Controller Guide](./controller-guide.md) | [Checklist](./checklist.md)
4
4
 
5
- ## ⚠️ CRITICAL: Route Prefix Warning
5
+ ## ⚠️ CRITICAL: Check Route Prefix BEFORE Writing OpenAPI Path
6
6
 
7
- **DO NOT duplicate the `/api` prefix in OpenAPI paths!**
7
+ ### Step 1: Check Which Route File the Controller Uses
8
8
 
9
- Laravel's `routes/api.php` already has `/api` prefix applied automatically. If you write `/api/users` in OpenAPI, it becomes `/api/api/users` - a serious bug!
9
+ ```bash
10
+ # Find where your route is registered
11
+ grep -r "UserController" routes/
12
+ ```
13
+
14
+ ### Step 2: Check the Route Prefix in That File
15
+
16
+ ```php
17
+ // bootstrap/app.php hoặc app/Providers/RouteServiceProvider.php
18
+ // Tìm xem route file có prefix gì
19
+
20
+ // Ví dụ Laravel 11+: bootstrap/app.php
21
+ ->withRouting(
22
+ api: __DIR__.'/../routes/api.php', // ← /api prefix tự động!
23
+ web: __DIR__.'/../routes/web.php',
24
+ apiPrefix: 'api', // ← Đây là prefix!
25
+ )
26
+
27
+ // Ví dụ Laravel 10: app/Providers/RouteServiceProvider.php
28
+ Route::middleware('api')
29
+ ->prefix('api') // ← Đây là prefix!
30
+ ->group(base_path('routes/api.php'));
31
+ ```
32
+
33
+ ### Step 3: Write OpenAPI Path = Actual Route Path (KHÔNG có prefix)
34
+
35
+ | Route File | Route Definition | Prefix | OpenAPI Path | Final URL |
36
+ |------------|------------------|--------|--------------|-----------|
37
+ | `api.php` | `Route::get('/users', ...)` | `/api` | `path: '/users'` | `/api/users` |
38
+ | `api.php` | `Route::get('/users/{id}', ...)` | `/api` | `path: '/users/{id}'` | `/api/users/1` |
39
+ | `web.php` | `Route::get('/dashboard', ...)` | (none) | `path: '/dashboard'` | `/dashboard` |
40
+ | `admin.php` | `Route::get('/stats', ...)` | `/admin/api` | `path: '/stats'` | `/admin/api/stats` |
41
+
42
+ ### ❌ CRITICAL BUG - Duplicate Prefix
10
43
 
11
44
  ```php
12
- // CRITICAL BUG - NEVER DO THIS!
13
- #[OA\Get(path: '/api/users')] // Results in: /api/api/users !!
45
+ // Route trong api.php (đã prefix /api)
46
+ Route::get('/users', [UserController::class, 'index']);
14
47
 
15
- // CORRECT - Routes file already has /api prefix
16
- #[OA\Get(path: '/users')] // Results in: /api/users
48
+ // SAI - Viết thêm /api vào path
49
+ #[OA\Get(path: '/api/users')] // /api/api/users !!
50
+
51
+ // ✅ ĐÚNG - Chỉ viết path sau prefix
52
+ #[OA\Get(path: '/users')] // → /api/users ✓
17
53
  ```
18
54
 
19
- **Remember:** The `api.php` file is loaded under the `/api` prefix by Laravel's RouteServiceProvider. You only need to write the path AFTER `/api`.
55
+ ### Quick Reference: Common Prefixes
56
+
57
+ | Route File | Default Prefix | OpenAPI Server URL |
58
+ |------------|----------------|-------------------|
59
+ | `api.php` | `/api` | `#[OA\Server(url: '/api')]` |
60
+ | `web.php` | (none) | `#[OA\Server(url: '/')]` |
61
+ | Custom | Check RouteServiceProvider | Match the prefix |
62
+
63
+ ### Checklist Before Writing OpenAPI
20
64
 
21
- | Routes File | OpenAPI Path | Actual URL |
22
- |--------------|---------------|----------------|
23
- | `api.php` | `/users` | `/api/users` |
24
- | `api.php` | `/users/{id}` | `/api/users/1` |
25
- | `web.php` | `/dashboard` | `/dashboard` |
65
+ - [ ] Check route file (`api.php` / `web.php` / custom)
66
+ - [ ] Check prefix in `RouteServiceProvider` or `bootstrap/app.php`
67
+ - [ ] OpenAPI path = Route path (WITHOUT prefix)
68
+ - [ ] `#[OA\Server(url: ...)]` matches the prefix
26
69
 
27
70
  ---
28
71