@famgia/omnify-laravel 0.0.106 → 0.0.108
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/dist/{chunk-XR2DTIIS.js → chunk-GDFAEEEG.js} +225 -3
- package/dist/chunk-GDFAEEEG.js.map +1 -0
- package/dist/index.cjs +229 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +72 -1
- package/dist/index.d.ts +72 -1
- package/dist/index.js +11 -1
- package/dist/plugin.cjs +92 -2
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.js +1 -1
- package/package.json +4 -4
- package/stubs/ai-guides/cursor/laravel-controller.mdc.stub +14 -0
- package/stubs/ai-guides/cursor/laravel.mdc.stub +15 -1
- package/stubs/ai-guides/cursor/omnify-migrations.mdc.stub +109 -0
- package/stubs/ai-guides/laravel/openapi.md.stub +42 -5
- package/dist/chunk-XR2DTIIS.js.map +0 -1
package/dist/plugin.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@famgia/omnify-laravel",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.108",
|
|
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.
|
|
29
|
-
"@famgia/omnify-core": "0.0.
|
|
30
|
-
"@famgia/omnify-atlas": "0.0.
|
|
28
|
+
"@famgia/omnify-types": "0.0.97",
|
|
29
|
+
"@famgia/omnify-core": "0.0.99",
|
|
30
|
+
"@famgia/omnify-atlas": "0.0.93"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "tsup",
|
|
@@ -6,6 +6,20 @@ alwaysApply: false
|
|
|
6
6
|
|
|
7
7
|
# Controller Rules
|
|
8
8
|
|
|
9
|
+
## ⚠️ CRITICAL: OpenAPI Route Prefix
|
|
10
|
+
|
|
11
|
+
**NEVER include `/api` in OpenAPI paths!** Laravel's `api.php` already has this prefix.
|
|
12
|
+
|
|
13
|
+
```php
|
|
14
|
+
// ❌ CRITICAL BUG - Results in /api/api/users !!
|
|
15
|
+
#[OA\Get(path: '/api/users')]
|
|
16
|
+
|
|
17
|
+
// ✅ CORRECT - api.php already adds /api prefix
|
|
18
|
+
#[OA\Get(path: '/users')]
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
9
23
|
## Golden Rule: Thin Controller
|
|
10
24
|
|
|
11
25
|
```php
|
|
@@ -7,7 +7,20 @@ alwaysApply: false
|
|
|
7
7
|
# Laravel Rules
|
|
8
8
|
|
|
9
9
|
> **Documentation:** `.claude/guides/laravel/`
|
|
10
|
-
> **Specific Rules:** See also `laravel-controller.mdc`, `laravel-resource.mdc`, `laravel-request.mdc`, `laravel-testing.mdc`
|
|
10
|
+
> **Specific Rules:** See also `laravel-controller.mdc`, `laravel-resource.mdc`, `laravel-request.mdc`, `laravel-testing.mdc`, `omnify-migrations.mdc`
|
|
11
|
+
|
|
12
|
+
## ⛔ CRITICAL: DO NOT EDIT
|
|
13
|
+
|
|
14
|
+
| Path | Reason |
|
|
15
|
+
|------|--------|
|
|
16
|
+
| `database/migrations/omnify/**` | Auto-generated by Omnify - will be overwritten! |
|
|
17
|
+
| `app/Models/OmnifyBase/**` | Auto-generated base models |
|
|
18
|
+
| `app/Http/Requests/OmnifyBase/**` | Auto-generated request bases |
|
|
19
|
+
| `app/Http/Resources/OmnifyBase/**` | Auto-generated resource bases |
|
|
20
|
+
|
|
21
|
+
**To modify schema:** Edit YAML in `schemas/` → run `npx omnify generate`
|
|
22
|
+
|
|
23
|
+
---
|
|
11
24
|
|
|
12
25
|
## Critical Rules
|
|
13
26
|
|
|
@@ -18,6 +31,7 @@ alwaysApply: false
|
|
|
18
31
|
5. **Dates** - Store UTC, return `->toISOString()`
|
|
19
32
|
6. **Testing** - Write 正常系 + 異常系 tests (see `laravel-testing.mdc`)
|
|
20
33
|
7. **Imports** - Always `use` and short class names, never FQCN inline
|
|
34
|
+
8. **OpenAPI Paths** - NO `/api` prefix! `api.php` already has it (see `laravel-controller.mdc`)
|
|
21
35
|
|
|
22
36
|
## File-Specific Rules
|
|
23
37
|
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "CRITICAL: Auto-generated Omnify migrations - DO NOT EDIT"
|
|
3
|
+
globs: ["{{LARAVEL_BASE}}/migrations/omnify/**"]
|
|
4
|
+
alwaysApply: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# ⛔ CRITICAL: DO NOT EDIT OMNIFY MIGRATIONS
|
|
8
|
+
|
|
9
|
+
## These files are AUTO-GENERATED
|
|
10
|
+
|
|
11
|
+
All files in `database/migrations/omnify/` are automatically generated by Omnify.
|
|
12
|
+
|
|
13
|
+
**ANY MANUAL CHANGES WILL BE OVERWRITTEN** when running `npx omnify generate`.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## ❌ ABSOLUTELY FORBIDDEN
|
|
18
|
+
|
|
19
|
+
```php
|
|
20
|
+
// NEVER modify files in database/migrations/omnify/
|
|
21
|
+
// Even "simple fixes" will be lost!
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
| Action | Result |
|
|
25
|
+
|--------|--------|
|
|
26
|
+
| Add column manually | ❌ Overwritten on next generate |
|
|
27
|
+
| Modify column type | ❌ Overwritten on next generate |
|
|
28
|
+
| Add index manually | ❌ Overwritten on next generate |
|
|
29
|
+
| Fix "typo" | ❌ Overwritten on next generate |
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## ✅ CORRECT APPROACH
|
|
34
|
+
|
|
35
|
+
### 1. Edit the YAML Schema
|
|
36
|
+
|
|
37
|
+
```yaml
|
|
38
|
+
# schemas/auth/User.yaml
|
|
39
|
+
properties:
|
|
40
|
+
# Add or modify properties HERE
|
|
41
|
+
new_field:
|
|
42
|
+
type: String
|
|
43
|
+
length: 100
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 2. Regenerate Migrations
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npx omnify generate
|
|
50
|
+
php artisan migrate
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Need Custom Migration?
|
|
56
|
+
|
|
57
|
+
For changes NOT supported by Omnify schemas:
|
|
58
|
+
|
|
59
|
+
1. Create migration **OUTSIDE** the `omnify/` folder:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
php artisan make:migration add_custom_field_to_users_table
|
|
63
|
+
# Creates: database/migrations/2026_01_12_000000_add_custom_field_to_users_table.php
|
|
64
|
+
# This is SAFE - Omnify won't touch it
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
2. Keep the omnify/ folder untouched
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Folder Structure
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
database/migrations/
|
|
75
|
+
├── omnify/ ← ⛔ AUTO-GENERATED - DO NOT EDIT
|
|
76
|
+
│ ├── 2026_01_01_000000_create_users_table.php
|
|
77
|
+
│ ├── 2026_01_01_000001_create_posts_table.php
|
|
78
|
+
│ └── ...
|
|
79
|
+
├── 2026_01_12_120000_add_custom_field.php ← ✅ Safe to edit
|
|
80
|
+
└── 2026_01_12_130000_custom_migration.php ← ✅ Safe to edit
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Quick Reference
|
|
86
|
+
|
|
87
|
+
| Want to... | Do this |
|
|
88
|
+
|------------|---------|
|
|
89
|
+
| Add column | Edit schema YAML → `npx omnify generate` |
|
|
90
|
+
| Modify column | Edit schema YAML → `npx omnify generate` |
|
|
91
|
+
| Add index | Edit schema YAML → `npx omnify generate` |
|
|
92
|
+
| Custom migration | `php artisan make:migration` (outside omnify/) |
|
|
93
|
+
| Fix generation bug | Report issue or edit Omnify plugin |
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## If You See This Warning
|
|
98
|
+
|
|
99
|
+
If a file has this header:
|
|
100
|
+
|
|
101
|
+
```php
|
|
102
|
+
/**
|
|
103
|
+
* DO NOT EDIT - This file is auto-generated by Omnify.
|
|
104
|
+
* Any changes will be overwritten on next generation.
|
|
105
|
+
* ...
|
|
106
|
+
*/
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**STOP!** Do not edit this file. Edit the schema YAML instead.
|
|
@@ -2,6 +2,43 @@
|
|
|
2
2
|
|
|
3
3
|
> **Related:** [README](./README.md) | [Controller Guide](./controller-guide.md) | [Checklist](./checklist.md)
|
|
4
4
|
|
|
5
|
+
## ⚠️ CRITICAL: Route Prefix Warning
|
|
6
|
+
|
|
7
|
+
**DO NOT duplicate the `/api` prefix in OpenAPI paths!**
|
|
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!
|
|
10
|
+
|
|
11
|
+
```php
|
|
12
|
+
// ❌ CRITICAL BUG - NEVER DO THIS!
|
|
13
|
+
#[OA\Get(path: '/api/users')] // Results in: /api/api/users !!
|
|
14
|
+
|
|
15
|
+
// ✅ CORRECT - Routes file already has /api prefix
|
|
16
|
+
#[OA\Get(path: '/users')] // Results in: /api/users
|
|
17
|
+
```
|
|
18
|
+
|
|
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`.
|
|
20
|
+
|
|
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` |
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## ⚠️ CRITICAL: L5-Swagger Configuration
|
|
30
|
+
|
|
31
|
+
**MUST set `use_absolute_path` to `false`** in `config/l5-swagger.php`:
|
|
32
|
+
|
|
33
|
+
```php
|
|
34
|
+
// config/l5-swagger.php
|
|
35
|
+
'use_absolute_path' => env('L5_SWAGGER_USE_ABSOLUTE_PATH', false),
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Without this, Swagger UI will fail to load the API documentation correctly.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
5
42
|
## Overview
|
|
6
43
|
|
|
7
44
|
This project uses [L5-Swagger](https://github.com/DarkaOnLine/L5-Swagger) with PHP 8 Attributes.
|
|
@@ -131,7 +168,7 @@ class Schemas
|
|
|
131
168
|
|
|
132
169
|
```php
|
|
133
170
|
#[OA\Get(
|
|
134
|
-
path: '/
|
|
171
|
+
path: '/users', // ⚠️ NO /api prefix! api.php already has it
|
|
135
172
|
summary: 'List users',
|
|
136
173
|
description: 'Paginated list with search and sorting',
|
|
137
174
|
tags: ['Users'],
|
|
@@ -153,7 +190,7 @@ public function index(Request $request): AnonymousResourceCollection
|
|
|
153
190
|
|
|
154
191
|
```php
|
|
155
192
|
#[OA\Post(
|
|
156
|
-
path: '/
|
|
193
|
+
path: '/users', // ⚠️ NO /api prefix!
|
|
157
194
|
summary: 'Create user',
|
|
158
195
|
description: 'Create a new user account',
|
|
159
196
|
tags: ['Users'],
|
|
@@ -181,7 +218,7 @@ public function store(UserStoreRequest $request): UserResource
|
|
|
181
218
|
|
|
182
219
|
```php
|
|
183
220
|
#[OA\Get(
|
|
184
|
-
path: '/
|
|
221
|
+
path: '/users/{id}', // ⚠️ NO /api prefix!
|
|
185
222
|
summary: 'Get user',
|
|
186
223
|
description: 'Get user by ID',
|
|
187
224
|
tags: ['Users'],
|
|
@@ -200,7 +237,7 @@ public function show(User $user): UserResource
|
|
|
200
237
|
|
|
201
238
|
```php
|
|
202
239
|
#[OA\Put(
|
|
203
|
-
path: '/
|
|
240
|
+
path: '/users/{id}', // ⚠️ NO /api prefix!
|
|
204
241
|
summary: 'Update user',
|
|
205
242
|
description: 'Update user (partial update supported)',
|
|
206
243
|
tags: ['Users'],
|
|
@@ -230,7 +267,7 @@ public function update(UserUpdateRequest $request, User $user): UserResource
|
|
|
230
267
|
|
|
231
268
|
```php
|
|
232
269
|
#[OA\Delete(
|
|
233
|
-
path: '/
|
|
270
|
+
path: '/users/{id}', // ⚠️ NO /api prefix!
|
|
234
271
|
summary: 'Delete user',
|
|
235
272
|
description: 'Permanently delete user',
|
|
236
273
|
tags: ['Users'],
|