|
1
|
# TSDoc: API Routes |
|
2
|
|
|
3
|
API route files live under `packages/medusa/src/api/admin/` and `packages/medusa/src/api/store/`. They export named HTTP handler functions (`GET`, `POST`, `DELETE`, `PATCH`). |
|
4
|
|
|
5
|
## Rules |
|
6
|
|
|
7
|
- Only add TSDocs to the exported handler functions (`GET`, `POST`, etc.) |
|
8
|
- Keep it **minimal**: only `@featureFlag` and/or `@since` — no full method documentation |
|
9
|
- If a handler has neither a feature flag nor is demonstrably new, add **no TSDoc** |
|
10
|
- Do NOT add `@param`, `@returns`, `@example`, or descriptions to route handlers |
|
11
|
|
|
12
|
## Detecting Feature Flags |
|
13
|
|
|
14
|
Look inside the handler body for `FeatureFlag.isFeatureEnabled(...)`: |
|
15
|
|
|
16
|
```typescript |
|
17
|
// This route is behind the "index_engine" feature flag |
|
18
|
export const GET = async (req, res) => { |
|
19
|
if (FeatureFlag.isFeatureEnabled(IndexEngineFeatureFlag.key)) { |
|
20
|
// ... |
|
21
|
} |
|
22
|
} |
|
23
|
``` |
|
24
|
|
|
25
|
The `@featureFlag` value is the flag's key string (e.g. `IndexEngineFeatureFlag.key` → `"index_engine"`). |
|
26
|
|
|
27
|
Also check if the route file is conditionally registered based on a flag in the route registration config or middleware. |
|
28
|
|
|
29
|
## When to Add Each Tag |
|
30
|
|
|
31
|
| Condition | Add | |
|
32
|
|-----------|-----| |
|
33
|
| Handler uses `FeatureFlag.isFeatureEnabled(XFlag.key)` | `@featureFlag <flag_key>` | |
|
34
|
| Handler is new in this commit's diff | `@since <version>` | |
|
35
|
| Handler is existing AND has no feature flag | Nothing | |
|
36
|
|
|
37
|
## Examples |
|
38
|
|
|
39
|
**Feature flag only:** |
|
40
|
```typescript |
|
41
|
/** |
|
42
|
* @featureFlag index_engine |
|
43
|
*/ |
|
44
|
export const GET = async ( |
|
45
|
req: AuthenticatedMedusaRequest<HttpTypes.AdminProductListParams>, |
|
46
|
res: MedusaResponse<HttpTypes.AdminProductListResponse> |
|
47
|
) => { |
|
48
|
// ... |
|
49
|
} |
|
50
|
``` |
|
51
|
|
|
52
|
**New route with feature flag:** |
|
53
|
```typescript |
|
54
|
/** |
|
55
|
* @since 2.14.0 |
|
56
|
* @featureFlag view_configurations |
|
57
|
*/ |
|
58
|
export const GET = async ( |
|
59
|
req: AuthenticatedMedusaRequest, |
|
60
|
res: MedusaResponse<HttpTypes.AdminViewConfigurationListResponse> |
|
61
|
) => { |
|
62
|
// ... |
|
63
|
} |
|
64
|
``` |
|
65
|
|
|
66
|
**New route without feature flag:** |
|
67
|
```typescript |
|
68
|
/** |
|
69
|
* @since 2.14.0 |
|
70
|
*/ |
|
71
|
export const POST = async ( |
|
72
|
req: AuthenticatedMedusaRequest<AdminCreateRegionType>, |
|
73
|
res: MedusaResponse<HttpTypes.AdminRegionResponse> |
|
74
|
) => { |
|
75
|
// ... |
|
76
|
} |
|
77
|
``` |
|
78
|
|
|
79
|
**Existing route, no feature flag — no TSDoc needed:** |
|
80
|
```typescript |
|
81
|
// No TSDoc added — route is existing and has no feature flag |
|
82
|
export const GET = async ( |
|
83
|
req: AuthenticatedMedusaRequest<HttpTypes.AdminOrderListParams>, |
|
84
|
res: MedusaResponse<HttpTypes.AdminOrderListResponse> |
|
85
|
) => { |
|
86
|
// ... |
|
87
|
} |
|
88
|
``` |
|
89
|
|
|
90
|
## Non-Handler Exports |
|
91
|
|
|
92
|
Route files sometimes export validators or helpers. These are typically not exported from the module's public surface and do not need TSDocs. |