You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Directives in AIScript are special annotations that provide additional metadata, validation, or behavior for different language elements. This reference documents all available directives and their usage.
4
-
5
-
## Route Directives
6
-
7
-
These directives are applied to route declarations to modify their behavior.
8
-
9
-
### @json
10
-
11
-
Specifies that the route expects and parses JSON request bodies.
12
-
13
-
```js
14
-
post /api/users {
15
-
@json
16
-
body {
17
-
name: str,
18
-
email: str
19
-
}
20
-
21
-
// Process body as JSON
22
-
return"Created user: "+body.name;
23
-
}
24
-
```
25
-
26
-
### @form
27
-
28
-
Specifies that the route expects and parses form data (`application/x-www-form-urlencoded` or `multipart/form-data`).
29
-
30
-
```js
31
-
post /api/contact {
32
-
@form
33
-
body {
34
-
name: str,
35
-
message: str
36
-
}
37
-
38
-
// Process body as form data
39
-
return"Received message from: "+body.name;
40
-
}
41
-
```
42
-
43
-
### @auth
44
-
45
-
Requires authentication for the route. Can specify roles or permissions.
46
-
47
-
```js
48
-
@auth
49
-
get /api/profile {
50
-
// Only authenticated users can access
51
-
return"Your profile data";
52
-
}
53
-
54
-
@auth(roles=["admin"])
55
-
get /api/users {
56
-
// Only admins can access
57
-
return"All users data";
58
-
}
59
-
```
60
-
61
-
### @basic_auth
62
-
63
-
Enables HTTP Basic Authentication for the route.
64
-
65
-
```js
66
-
@basic_auth(realm="Admin Area")
67
-
get /admin/dashboard {
68
-
// Only users with valid basic auth credentials can access
69
-
return"Admin dashboard";
70
-
}
71
-
```
72
-
73
-
### @sso
74
-
75
-
Enables Single Sign-On authentication for the route.
76
-
77
-
```js
78
-
@sso(provider="google")
79
-
get /dashboard {
80
-
// User must be authenticated via Google SSO
81
-
return"Welcome, "+user.name;
82
-
}
83
-
```
84
-
85
-
### @docs
86
-
87
-
Provides documentation and metadata for OpenAPI generation.
88
-
89
-
Parameters:
90
-
91
-
-**deprecated**: Marks a route as deprecated
92
-
-**tag**: Assigns the route to a specific tag group in documentation
93
-
-**hidden**: Excludes the route from documentation
94
-
95
-
```js
96
-
@docs(deprecated=true)
97
-
get /api/users {
98
-
// This route is deprecated
99
-
return"Users list";
100
-
}
101
-
102
-
@docs(tag="Authentication")
103
-
post /api/login {
104
-
// This route will be grouped under "Authentication" in docs
105
-
return"Login successful";
106
-
}
107
-
108
-
@docs(hidden=true)
109
-
get /internal/metrics {
110
-
// This route won't appear in documentation
111
-
return"Internal metrics";
112
-
}
113
-
```
114
-
115
-
## Validator Directives
2
+
# Validator Directives
116
3
117
4
These directives validate field values in route parameters, request bodies, or model definitions.
118
5
119
-
###@string
6
+
## @string
120
7
121
8
Validates string values with various constraints.
122
9
@@ -140,7 +27,7 @@ post /api/register {
140
27
}
141
28
```
142
29
143
-
###@number
30
+
## @number
144
31
145
32
Validates numeric values against specified constraints.
146
33
@@ -162,7 +49,7 @@ post /api/product {
162
49
}
163
50
```
164
51
165
-
###@in
52
+
## @in
166
53
167
54
Validates that a value is one of a set of allowed values.
168
55
@@ -179,7 +66,7 @@ post /api/order {
179
66
}
180
67
```
181
68
182
-
###@regex
69
+
## @regex
183
70
184
71
Validates that a string matches a given regular expression pattern.
185
72
@@ -196,7 +83,7 @@ post /api/register {
196
83
}
197
84
```
198
85
199
-
###@format
86
+
## @format
200
87
201
88
Validates that a string conforms to a specific format.
202
89
@@ -229,7 +116,7 @@ post /api/user {
229
116
}
230
117
```
231
118
232
-
###@array
119
+
## @array
233
120
234
121
Validates arrays against specified constraints.
235
122
@@ -248,7 +135,7 @@ post /api/tags {
248
135
}
249
136
```
250
137
251
-
###@date
138
+
## @date
252
139
253
140
Validates that a string is a valid date in the specified format and range.
254
141
@@ -267,7 +154,7 @@ post /api/event {
267
154
}
268
155
```
269
156
270
-
###@not
157
+
## @not
271
158
272
159
Negates another validator, passing if the inner validator fails.
273
160
@@ -281,7 +168,7 @@ post /api/product {
281
168
}
282
169
```
283
170
284
-
###@or
171
+
## @or
285
172
286
173
Combines multiple validators with logical OR, passing if any of the inner validators pass.
0 commit comments