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
Copy file name to clipboardExpand all lines: docs/guide/web/openapi-docs.md
+61-6Lines changed: 61 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,11 +23,31 @@ post /api/chat {
23
23
}
24
24
```
25
25
26
+
## Using @docs Directive
27
+
28
+
The `@docs` directive gives you fine-grained control over how your API is documented:
29
+
30
+
```py
31
+
@docs(tag="Authentication", deprecated=true)
32
+
post /api/login {
33
+
"""Login endpoint - use the new OAuth endpoint instead"""
34
+
35
+
// Route implementation
36
+
}
37
+
```
38
+
39
+
The `@docs` directive supports the following parameters:
40
+
41
+
-`tag`: String value that groups related endpoints in the documentation UI
42
+
-`deprecated`: Boolean that marks an endpoint as deprecated
43
+
-`hidden`: Boolean that excludes an endpoint from the documentation
44
+
26
45
## Documenting Routes
27
46
28
-
Each route can have a detailed description:
47
+
Each route can have a detailed description using docstrings and can be enhanced with the `@docs` directive:
29
48
30
49
```py
50
+
@docs(tag="Users")
31
51
get /api/users {
32
52
"""
33
53
List all users
@@ -145,6 +165,8 @@ AIScript automatically generates OpenAPI documentation based on your route defin
145
165
4. Data types for all parameters and responses
146
166
5. Docstrings as descriptions
147
167
6. Documentation specific to each parameter
168
+
7. Tags and groupings defined by `@docs` directives
169
+
8. Deprecated endpoints marked accordingly
148
170
149
171
## Accessing Documentation
150
172
@@ -163,28 +185,43 @@ AIScript's documentation UI support **Swagger UI** and **Redoc**.
163
185
164
186
## Tags and Grouping
165
187
166
-
You can use tags to group related endpoints in the documentation:
188
+
You can use the `tag` parameter in the `@docs` directive to group related endpoints in the documentation:
167
189
168
190
```py
169
-
@docs(tag="Users")
191
+
@docs(tag="Users")
170
192
get /api/users {
171
193
"""List all users"""
172
194
}
173
195
174
-
@docs(tag="Users")
196
+
@docs(tag="Users")
175
197
get /api/users/<id:int> {
176
198
"""Get user by ID"""
177
199
}
178
200
179
-
@docs(tag="Users")
201
+
@docs(tag="Products")
180
202
get /api/products {
181
203
"""List all products"""
182
204
}
183
205
```
184
206
207
+
In the generated documentation UI, endpoints will be grouped by their tags, making it easier to navigate complex APIs.
208
+
209
+
## Marking Deprecated Endpoints
210
+
211
+
Use the `deprecated` parameter to mark endpoints that should no longer be used:
212
+
213
+
```py
214
+
@docs(deprecated=true)
215
+
get /api/v1/users {
216
+
"""This endpoint is deprecated. Use /api/v2/users instead."""
217
+
}
218
+
```
219
+
220
+
Deprecated endpoints will be clearly marked in the documentation UI, but will still be included so that users who need to migrate can understand the old API.
221
+
185
222
## Hiding Endpoints
186
223
187
-
You can exclude specific endpoints from documentation:
224
+
You can exclude specific endpoints from documentation with the `hidden` parameter:
188
225
189
226
```py
190
227
@docs(hidden=true)
@@ -193,6 +230,22 @@ get /internal/metrics {
193
230
}
194
231
```
195
232
233
+
This is useful for internal endpoints that aren't meant for public consumption.
234
+
235
+
## Combining Multiple Directives
236
+
237
+
You can combine the `@docs` directive with other directives to create comprehensive documentation:
238
+
239
+
```py
240
+
@auth(jwt=true)
241
+
@docs(tag="Users")
242
+
get /api/users/me {
243
+
"""Get the currently authenticated user's profile"""
244
+
245
+
// Route implementation
246
+
}
247
+
```
248
+
196
249
## Benefits
197
250
198
251
Automatic OpenAPI documentation in AIScript offers several benefits:
@@ -203,5 +256,7 @@ Automatic OpenAPI documentation in AIScript offers several benefits:
203
256
4.**Validation rules included**: All validators are documented
204
257
5.**Interactive testing**: Test endpoints directly from the documentation UI
205
258
6.**Client generation**: Use the OpenAPI spec to generate client libraries in various languages
259
+
7.**Organized documentation**: Group endpoints logically with tags
260
+
8.**Deprecation notices**: Clearly mark endpoints that are being phased out
206
261
207
262
AIScript's built-in documentation system ensures your API is well-documented with minimal effort, making it easier for both you and your API consumers to understand and use your services.
0 commit comments