|
| 1 | +# JSDoc/Swagger Documentation Standards for Paperless-AI API |
| 2 | + |
| 3 | +The following detailed standard is what all API route documentation should adhere to: |
| 4 | + |
| 5 | +## 1. Basic Structure and Format |
| 6 | + |
| 7 | +Every route in the API must be documented with a JSDoc comment block using the `@swagger` tag following the OpenAPI 3.0.0 specification. The documentation should be placed immediately before the route handler function. |
| 8 | + |
| 9 | +```javascript |
| 10 | +/** |
| 11 | + * @swagger |
| 12 | + * /path/to/endpoint: |
| 13 | + * method: |
| 14 | + * // Documentation content |
| 15 | + */ |
| 16 | +router.method('/path/to/endpoint', async (req, res) => { |
| 17 | +``` |
| 18 | +
|
| 19 | +## 2. Core Documentation Elements |
| 20 | +
|
| 21 | +### 2.1 Route Path Definition |
| 22 | +
|
| 23 | +- The route path must match exactly the path defined in the Express route handler |
| 24 | +- Path parameters should be defined using curly braces: `/path/{paramName}` |
| 25 | +- Trailing slashes should be avoided for consistency |
| 26 | +
|
| 27 | +### 2.2 HTTP Method |
| 28 | +
|
| 29 | +- The HTTP method (get, post, put, delete) should be indented under the path |
| 30 | +- Only one method should be defined per documentation block |
| 31 | +- Multiple methods for the same path should be documented separately |
| 32 | +
|
| 33 | +### 2.3 Summary and Description |
| 34 | +
|
| 35 | +- Every endpoint must have a clear, concise `summary` field (single line) |
| 36 | +- A more detailed `description` field using the pipe symbol (`|`) for multi-line content |
| 37 | +- The description should: |
| 38 | + - Explain the purpose of the endpoint in 2-3 sentences |
| 39 | + - Describe key functionality and behaviors |
| 40 | + - Note any important side effects or dependencies |
| 41 | + - Use proper grammar and complete sentences |
| 42 | + - For complex endpoints, include usage examples or explanations of how the endpoint works in the larger application context |
| 43 | +
|
| 44 | +Example: |
| 45 | +```javascript |
| 46 | +/** |
| 47 | + * @swagger |
| 48 | + * /api/example: |
| 49 | + * get: |
| 50 | + * summary: Brief description of what this endpoint does |
| 51 | + * description: | |
| 52 | + * Detailed explanation of the endpoint functionality. |
| 53 | + * This should cover what the endpoint does, how it works, |
| 54 | + * and any important behaviors users should know about. |
| 55 | + * |
| 56 | + * Use multiple paragraphs for complex explanations. |
| 57 | + */ |
| 58 | +``` |
| 59 | +
|
| 60 | +## 3. Tags and Categorization |
| 61 | +
|
| 62 | +### 3.1 Tag Requirements |
| 63 | +
|
| 64 | +- Each endpoint must be assigned to at least one tag, often multiple tags |
| 65 | +- Tags must come from the predefined list of application tags defined in the `tags` section |
| 66 | +- Multiple tags should be used when an endpoint serves multiple purposes |
| 67 | +- Common tag combinations include: |
| 68 | + - `[Navigation, X]` for UI page routes |
| 69 | + - `[API, X]` for data API endpoints |
| 70 | + - `[System, Authentication]` for security-related endpoints |
| 71 | +
|
| 72 | +### 3.2 Defined Tags |
| 73 | +
|
| 74 | +The application uses the following tags for categorization: |
| 75 | +- Authentication - User authentication and authorization endpoints |
| 76 | +- Documents - Document management and processing endpoints |
| 77 | +- History - Document processing history and tracking |
| 78 | +- Navigation - General navigation endpoints for the web interface |
| 79 | +- System - Configuration, health checks, and administrative functions |
| 80 | +- Chat - Document chat functionality |
| 81 | +- Setup - Application setup and configuration |
| 82 | +- Metadata - Endpoints for managing document metadata |
| 83 | +- API - General API endpoints (usually combined with other tags) |
| 84 | +
|
| 85 | +## 4. Security Requirements |
| 86 | +
|
| 87 | +### 4.1 Security Definitions |
| 88 | +
|
| 89 | +- Each protected endpoint must include appropriate security requirements |
| 90 | +- The application supports two authentication methods: |
| 91 | + - `BearerAuth` - JWT-based authentication for web app users |
| 92 | + - `ApiKeyAuth` - API key authentication for programmatic access |
| 93 | +
|
| 94 | +### 4.2 Security Requirement Format |
| 95 | +
|
| 96 | +Security requirements should be specified in the standard format: |
| 97 | +```javascript |
| 98 | + * security: |
| 99 | + * - BearerAuth: [] |
| 100 | + * - ApiKeyAuth: [] |
| 101 | +``` |
| 102 | +
|
| 103 | +### 4.3 Security Notices |
| 104 | +
|
| 105 | +- For endpoints that modify security settings (like key regeneration), include explicit security notices |
| 106 | +- Format these as bold text in the description using Markdown: `**Security Notice**: Important information.` |
| 107 | +
|
| 108 | +## 5. Parameters Documentation |
| 109 | +
|
| 110 | +### 5.1 Path Parameters |
| 111 | +
|
| 112 | +Path parameters should be documented with: |
| 113 | +- Parameter name matching the path definition |
| 114 | +- Schema type (integer, string, etc.) |
| 115 | +- Required flag (almost always true for path parameters) |
| 116 | +- Description of the parameter purpose |
| 117 | +- Example value |
| 118 | +
|
| 119 | +```javascript |
| 120 | + * parameters: |
| 121 | + * - in: path |
| 122 | + * name: id |
| 123 | + * required: true |
| 124 | + * schema: |
| 125 | + * type: integer |
| 126 | + * description: The resource ID |
| 127 | + * example: 123 |
| 128 | +``` |
| 129 | +
|
| 130 | +### 5.2 Query Parameters |
| 131 | +
|
| 132 | +Query parameters follow a similar format but include: |
| 133 | +- Default values where applicable |
| 134 | +- Enumerated values if the parameter has a restricted set of options |
| 135 | +
|
| 136 | +```javascript |
| 137 | + * parameters: |
| 138 | + * - in: query |
| 139 | + * name: limit |
| 140 | + * schema: |
| 141 | + * type: integer |
| 142 | + * default: 10 |
| 143 | + * description: Maximum number of records to return |
| 144 | +``` |
| 145 | +
|
| 146 | +### 5.3 Request Body |
| 147 | +
|
| 148 | +For POST/PUT endpoints, document the request body with: |
| 149 | +- Required flag |
| 150 | +- Content type (usually application/json) |
| 151 | +- Schema definition including: |
| 152 | + - Required properties list |
| 153 | + - Property definitions with types |
| 154 | + - Property descriptions |
| 155 | + - Example values |
| 156 | +
|
| 157 | +```javascript |
| 158 | + * requestBody: |
| 159 | + * required: true |
| 160 | + * content: |
| 161 | + * application/json: |
| 162 | + * schema: |
| 163 | + * type: object |
| 164 | + * required: |
| 165 | + * - propertyName |
| 166 | + * properties: |
| 167 | + * propertyName: |
| 168 | + * type: string |
| 169 | + * description: Description of the property |
| 170 | + * example: "Example value" |
| 171 | +``` |
| 172 | +
|
| 173 | +## 6. Response Documentation |
| 174 | +
|
| 175 | +### 6.1 Response Status Codes |
| 176 | +
|
| 177 | +Each endpoint must document all possible response status codes: |
| 178 | +- 200/201 for successful operations |
| 179 | +- 400 for invalid requests |
| 180 | +- 401 for authentication failures |
| 181 | +- 403 for authorization failures |
| 182 | +- 404 for resource not found |
| 183 | +- 500 for server errors |
| 184 | +- Any other status code the endpoint might return |
| 185 | +
|
| 186 | +### 6.2 Response Content |
| 187 | +
|
| 188 | +For each status code, document: |
| 189 | +- Description of what the status code means in this specific context |
| 190 | +- Content type of the response |
| 191 | +- Schema definition of the response body |
| 192 | +- For complex responses, use schema references to components |
| 193 | +
|
| 194 | +```javascript |
| 195 | + * responses: |
| 196 | + * 200: |
| 197 | + * description: Detailed description of successful response |
| 198 | + * content: |
| 199 | + * application/json: |
| 200 | + * schema: |
| 201 | + * $ref: '#/components/schemas/ResponseSchema' |
| 202 | +``` |
| 203 | +
|
| 204 | +### 6.3 Streaming Responses |
| 205 | +
|
| 206 | +For streaming endpoints (like chat), document: |
| 207 | +- The streaming nature of the response |
| 208 | +- The format of each chunk |
| 209 | +- Examples of the stream events |
| 210 | +
|
| 211 | +```javascript |
| 212 | + * 200: |
| 213 | + * description: | |
| 214 | + * Response streaming started. Each event contains a message chunk. |
| 215 | + * content: |
| 216 | + * text/event-stream: |
| 217 | + * schema: |
| 218 | + * type: string |
| 219 | + * example: | |
| 220 | + * data: {"chunk":"Example response chunk"} |
| 221 | + * |
| 222 | + * data: {"done":true} |
| 223 | +``` |
| 224 | +
|
| 225 | +## 7. Schema Definitions and References |
| 226 | +
|
| 227 | +### 7.1 Schema Components |
| 228 | +
|
| 229 | +- Complex object schemas should be defined as components in a central schema file |
| 230 | +- These components should be referenced using `$ref` syntax |
| 231 | +- Common schemas like Error responses should always use references |
| 232 | +
|
| 233 | +```javascript |
| 234 | + * schema: |
| 235 | + * $ref: '#/components/schemas/Error' |
| 236 | +``` |
| 237 | +
|
| 238 | +### 7.2 Inline Schemas |
| 239 | +
|
| 240 | +- Simple response schemas can be defined inline |
| 241 | +- Include: |
| 242 | + - Object type |
| 243 | + - Properties with types and descriptions |
| 244 | + - Example values for each property |
| 245 | +
|
| 246 | +```javascript |
| 247 | + * schema: |
| 248 | + * type: object |
| 249 | + * properties: |
| 250 | + * success: |
| 251 | + * type: boolean |
| 252 | + * description: Whether the operation succeeded |
| 253 | + * example: true |
| 254 | +``` |
| 255 | +
|
| 256 | +### 7.3 Array Schemas |
| 257 | +
|
| 258 | +Arrays should specify the item type, either as a reference or inline schema: |
| 259 | +
|
| 260 | +```javascript |
| 261 | + * schema: |
| 262 | + * type: array |
| 263 | + * items: |
| 264 | + * $ref: '#/components/schemas/Item' |
| 265 | +``` |
| 266 | +
|
| 267 | +## 8. Documentation Style and Formatting |
| 268 | +
|
| 269 | +### 8.1 Indentation and Formatting |
| 270 | +
|
| 271 | +- Consistent indentation using 2 spaces |
| 272 | +- Proper nesting of OpenAPI elements |
| 273 | +- Clear separation between different documentation sections |
| 274 | +
|
| 275 | +### 8.2 Naming Conventions |
| 276 | +
|
| 277 | +- Use camelCase for property names in schemas |
| 278 | +- Use snake_case for query parameter names |
| 279 | +- Use descriptive names for all elements |
| 280 | +
|
| 281 | +### 8.3 Example Values |
| 282 | +
|
| 283 | +- Every property should include a realistic example value |
| 284 | +- Examples should demonstrate typical usage |
| 285 | +- For enums, example should be one of the allowed values |
| 286 | +
|
| 287 | +## 9. Special Documentation Types |
| 288 | +
|
| 289 | +### 9.1 Page Routes (Navigation) |
| 290 | +
|
| 291 | +For routes that render HTML pages: |
| 292 | +- Tag with [Navigation] and relevant feature tag |
| 293 | +- Document the purpose of the page |
| 294 | +- Note any data dependencies |
| 295 | +
|
| 296 | +### 9.2 API Data Endpoints |
| 297 | +
|
| 298 | +For pure data API endpoints: |
| 299 | +- Tag with [API] and relevant feature tag |
| 300 | +- Document the data structure comprehensively |
| 301 | +- Include pagination details if applicable |
| 302 | +
|
| 303 | +### 9.3 Authentication Endpoints |
| 304 | +
|
| 305 | +For authentication-related endpoints: |
| 306 | +- Tag with [Authentication] |
| 307 | +- Include detailed security considerations |
| 308 | +- Document token/session behaviors |
| 309 | +
|
| 310 | +## 10. Documentation Quality Standards |
| 311 | +
|
| 312 | +### 10.1 Completeness |
| 313 | +
|
| 314 | +- No undocumented parameters or responses |
| 315 | +- All possible response codes covered |
| 316 | +- All security requirements specified |
| 317 | +
|
| 318 | +### 10.2 Accuracy |
| 319 | +
|
| 320 | +- Documentation must match actual implementation |
| 321 | +- Examples must be valid for the described schema |
| 322 | +- Security requirements must reflect actual restrictions |
| 323 | +
|
| 324 | +### 10.3 Consistency |
| 325 | +
|
| 326 | +- Similar endpoints should follow similar documentation patterns |
| 327 | +- Standard responses (like errors) should be documented identically |
| 328 | +- Terminology should be consistent across all endpoints |
| 329 | +
|
| 330 | +This comprehensive standard ensures that all API documentation in the Paperless-AI application is thorough, consistent, and user-friendly, providing developers with all the information they need to use the API effectively. |
| 331 | +
|
0 commit comments