Skip to content

Commit fed857f

Browse files
committed
Update Route and Directives reference docs
1 parent d599b7e commit fed857f

File tree

10 files changed

+684
-287
lines changed

10 files changed

+684
-287
lines changed

docs/reference/_meta.json

+4-9
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@
55
"label": "Language Keyword"
66
},
77
{
8-
"type": "file",
9-
"name": "route-request",
10-
"label": "Route Request"
11-
},
12-
{
13-
"type": "file",
14-
"name": "route-response",
15-
"label": "Route Response"
8+
"type": "dir",
9+
"name": "route",
10+
"label": "Route"
1611
},
1712
{
18-
"type": "file",
13+
"type": "dir",
1914
"name": "directives",
2015
"label": "Directives"
2116
},

docs/reference/directives/_meta.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["route", "validator"]

docs/reference/directives/route.md

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Route Directives
2+
3+
These directives are applied to route declarations to modify their behavior.
4+
5+
## @json
6+
7+
Specifies that the route expects and parses JSON request bodies.
8+
9+
```js
10+
post /api/users {
11+
@json
12+
body {
13+
name: str,
14+
email: str
15+
}
16+
17+
// Process body as JSON
18+
return "Created user: " + body.name;
19+
}
20+
```
21+
22+
## @form
23+
24+
Specifies that the route expects and parses form data (`application/x-www-form-urlencoded` or `multipart/form-data`).
25+
26+
```js
27+
post /api/contact {
28+
@form
29+
body {
30+
name: str,
31+
message: str
32+
}
33+
34+
// Process body as form data
35+
return "Received message from: " + body.name;
36+
}
37+
```
38+
39+
## @auth
40+
41+
Requires authentication for the route. Can specify roles or permissions.
42+
43+
```js
44+
@auth
45+
get /api/profile {
46+
// Only authenticated users can access
47+
return "Your profile data";
48+
}
49+
50+
@auth(roles=["admin"])
51+
get /api/users {
52+
// Only admins can access
53+
return "All users data";
54+
}
55+
```
56+
57+
## @basic_auth
58+
59+
Enables HTTP Basic Authentication for the route.
60+
61+
```js
62+
@basic_auth(realm="Admin Area")
63+
get /admin/dashboard {
64+
// Only users with valid basic auth credentials can access
65+
return "Admin dashboard";
66+
}
67+
```
68+
69+
## @sso
70+
71+
Enables Single Sign-On authentication for the route.
72+
73+
```js
74+
@sso(provider="google")
75+
get /dashboard {
76+
// User must be authenticated via Google SSO
77+
return "Welcome, " + user.name;
78+
}
79+
```
80+
81+
## @docs
82+
83+
Provides documentation and metadata for OpenAPI generation.
84+
85+
Parameters:
86+
87+
- **deprecated**: Marks a route as deprecated
88+
- **tag**: Assigns the route to a specific tag group in documentation
89+
- **hidden**: Excludes the route from documentation
90+
91+
```js
92+
@docs(deprecated=true)
93+
get /api/users {
94+
// This route is deprecated
95+
return "Users list";
96+
}
97+
98+
@docs(tag="Authentication")
99+
post /api/login {
100+
// This route will be grouped under "Authentication" in docs
101+
return "Login successful";
102+
}
103+
104+
@docs(hidden=true)
105+
get /internal/metrics {
106+
// This route won't appear in documentation
107+
return "Internal metrics";
108+
}
109+
```

docs/reference/directives.mdx renamed to docs/reference/directives/validator.md

+10-123
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,9 @@
1-
# Directives Reference
21

3-
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
1163

1174
These directives validate field values in route parameters, request bodies, or model definitions.
1185

119-
### @string
6+
## @string
1207

1218
Validates string values with various constraints.
1229

@@ -140,7 +27,7 @@ post /api/register {
14027
}
14128
```
14229

143-
### @number
30+
## @number
14431

14532
Validates numeric values against specified constraints.
14633

@@ -162,7 +49,7 @@ post /api/product {
16249
}
16350
```
16451

165-
### @in
52+
## @in
16653

16754
Validates that a value is one of a set of allowed values.
16855

@@ -179,7 +66,7 @@ post /api/order {
17966
}
18067
```
18168

182-
### @regex
69+
## @regex
18370

18471
Validates that a string matches a given regular expression pattern.
18572

@@ -196,7 +83,7 @@ post /api/register {
19683
}
19784
```
19885

199-
### @format
86+
## @format
20087

20188
Validates that a string conforms to a specific format.
20289

@@ -229,7 +116,7 @@ post /api/user {
229116
}
230117
```
231118

232-
### @array
119+
## @array
233120

234121
Validates arrays against specified constraints.
235122

@@ -248,7 +135,7 @@ post /api/tags {
248135
}
249136
```
250137

251-
### @date
138+
## @date
252139

253140
Validates that a string is a valid date in the specified format and range.
254141

@@ -267,7 +154,7 @@ post /api/event {
267154
}
268155
```
269156

270-
### @not
157+
## @not
271158

272159
Negates another validator, passing if the inner validator fails.
273160

@@ -281,7 +168,7 @@ post /api/product {
281168
}
282169
```
283170

284-
### @or
171+
## @or
285172

286173
Combines multiple validators with logical OR, passing if any of the inner validators pass.
287174

0 commit comments

Comments
 (0)