-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi-documentation.mdc
More file actions
202 lines (178 loc) · 4.66 KB
/
api-documentation.mdc
File metadata and controls
202 lines (178 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
---
description:
globs:
alwaysApply: true
---
# @attach: auto
# @glob: public/swagger.yaml,public/v*/openapi.yaml,docs/api/**/*,app/controllers/api/**/*
# @description: API documentation standards for OpenAPI/Swagger specifications.
# API Documentation Standards
## Related Rules
- @backend-rules.mdc for backend implementation
- @frontend-rules.mdc for frontend integration
- @workflow-rules.mdc for development workflow
## Module References
- @backend/api-design.mdc for API implementation details
- @workflow/documentation.mdc for general documentation practices
## When to Check These Rules
- When creating new API endpoints
- When modifying existing endpoints
- Before API version updates
- During code review of API changes
- When generating client SDKs
- When updating API documentation
## OpenAPI/Swagger Documentation Standards
### File Organization
- Keep OpenAPI specification in `public/swagger.yaml`
- Version specifications in `public/v{version}/openapi.yaml`
- Generate client SDKs in `docs/api/sdks/`
- Store examples in `docs/api/examples/`
### Specification Structure
```yaml
openapi: 3.0.3
info:
title: API Title
version: 1.0.0
description: |
Comprehensive API documentation
with detailed examples
contact:
name: API Team
email: api@example.com
license:
name: MIT
url: https://opensource.org/licenses/MIT
servers:
- url: https://api.example.com/v1
description: Production server
- url: https://staging-api.example.com/v1
description: Staging server
```
### Required Sections
1. **Info**
- Title
- Version
- Description
- Contact information
- License
2. **Servers**
- Production URL
- Staging URL
- Development URL (optional)
3. **Security**
- Authentication schemes
- Authorization requirements
- API keys
- OAuth flows
4. **Paths**
- Resource endpoints
- HTTP methods
- Parameters
- Request bodies
- Responses
- Error codes
5. **Components**
- Schemas
- Security schemes
- Parameters
- Request bodies
- Responses
- Headers
- Examples
### Documentation Requirements
#### Endpoint Documentation
```yaml
paths:
/users:
get:
summary: List all users
description: |
Returns a paginated list of users.
Supports filtering and sorting.
operationId: listUsers
tags:
- Users
parameters:
- $ref: '#/components/parameters/page'
- $ref: '#/components/parameters/per_page'
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/UserList'
'400':
$ref: '#/components/responses/BadRequest'
```
#### Schema Documentation
```yaml
components:
schemas:
User:
type: object
description: User object
required:
- id
- email
properties:
id:
type: string
format: uuid
description: Unique identifier
email:
type: string
format: email
description: User's email address
```
### Best Practices
1. **Versioning**
- Use semantic versioning
- Document breaking changes
- Maintain backward compatibility
- Include deprecation notices
2. **Examples**
- Provide request/response examples
- Include error scenarios
- Show authentication flows
- Demonstrate pagination
3. **Validation**
- Use JSON Schema validation
- Define required fields
- Specify data types
- Include format constraints
4. **Security**
- Document authentication methods
- Define authorization scopes
- Include security schemes
- Specify rate limits
### Documentation Checklist
- [ ] OpenAPI specification is valid
- [ ] All endpoints are documented
- [ ] Request/response schemas are defined
- [ ] Examples are provided
- [ ] Error responses are documented
- [ ] Authentication is described
- [ ] Versioning is clear
- [ ] Breaking changes are noted
- [ ] Client SDKs are generated
- [ ] Documentation is up to date
### Tools and Automation
- Use Swagger UI for interactive documentation
- Implement automated validation
- Generate client SDKs automatically
- Include documentation in CI/CD pipeline
- Monitor API changes
- Track documentation coverage
### Maintenance
- Review documentation monthly
- Update with new features
- Remove deprecated endpoints
- Validate examples
- Check links and references
- Update client SDKs
### Related Resources
- [OpenAPI Specification](mdc:https:/spec.openapis.org/oas/latest.html)
- [Swagger Documentation](mdc:https:/swagger.io/docs)
- [API Design Guide](mdc:https:/google.aip.dev)
- [REST API Best Practices](mdc:https:/restfulapi.net)