Skip to content

Commit 232356d

Browse files
committed
Update OpenAPI docs with @docs directive
1 parent 9a5ee0c commit 232356d

File tree

1 file changed

+61
-6
lines changed

1 file changed

+61
-6
lines changed

docs/guide/web/openapi-docs.md

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,31 @@ post /api/chat {
2323
}
2424
```
2525

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+
2645
## Documenting Routes
2746

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:
2948

3049
```py
50+
@docs(tag="Users")
3151
get /api/users {
3252
"""
3353
List all users
@@ -145,6 +165,8 @@ AIScript automatically generates OpenAPI documentation based on your route defin
145165
4. Data types for all parameters and responses
146166
5. Docstrings as descriptions
147167
6. Documentation specific to each parameter
168+
7. Tags and groupings defined by `@docs` directives
169+
8. Deprecated endpoints marked accordingly
148170

149171
## Accessing Documentation
150172

@@ -163,28 +185,43 @@ AIScript's documentation UI support **Swagger UI** and **Redoc**.
163185

164186
## Tags and Grouping
165187

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:
167189

168190
```py
169-
@docs(tag = "Users")
191+
@docs(tag="Users")
170192
get /api/users {
171193
"""List all users"""
172194
}
173195

174-
@docs(tag = "Users")
196+
@docs(tag="Users")
175197
get /api/users/<id:int> {
176198
"""Get user by ID"""
177199
}
178200

179-
@docs(tag = "Users")
201+
@docs(tag="Products")
180202
get /api/products {
181203
"""List all products"""
182204
}
183205
```
184206

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+
185222
## Hiding Endpoints
186223

187-
You can exclude specific endpoints from documentation:
224+
You can exclude specific endpoints from documentation with the `hidden` parameter:
188225

189226
```py
190227
@docs(hidden=true)
@@ -193,6 +230,22 @@ get /internal/metrics {
193230
}
194231
```
195232

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+
196249
## Benefits
197250

198251
Automatic OpenAPI documentation in AIScript offers several benefits:
@@ -203,5 +256,7 @@ Automatic OpenAPI documentation in AIScript offers several benefits:
203256
4. **Validation rules included**: All validators are documented
204257
5. **Interactive testing**: Test endpoints directly from the documentation UI
205258
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
206261

207262
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

Comments
 (0)