This guide explains how we document our APIs using Swagger/OpenAPI specifications in the FlowFocus project. Following these standards ensures consistency across all API endpoints and makes the API documentation maintainable and user-friendly.
We use Swagger UI to provide interactive API documentation. The configuration is located in server/config/swagger.js. The documentation is automatically generated from JSDoc comments in our route files.
We have defined reusable components for common patterns:
PageParam: Page number for paginationLimitParam: Number of items per pageSortParam: Sorting criteria
SuccessResponse: Standard success response wrapperPaginatedResponse: Wrapper for paginated dataValidationError: Validation error responseUnauthorizedError: Authentication error response
Here's an example of how to document an API endpoint using our standardized approach:
/**
* @swagger
* /api/examples:
* get:
* summary: Get all examples with pagination
* tags: [Examples]
* security:
* - bearerAuth: []
* parameters:
* - $ref: '#/components/parameters/PageParam'
* - $ref: '#/components/parameters/LimitParam'
* - $ref: '#/components/parameters/SortParam'
* responses:
* 200:
* description: Successfully retrieved examples
* content:
* application/json:
* schema:
* allOf:
* - $ref: '#/components/schemas/SuccessResponse'
* - properties:
* data:
* $ref: '#/components/schemas/PaginatedResponse'
* 401:
* $ref: '#/components/responses/UnauthorizedError'
*/- Always include a clear summary for each endpoint
- Use appropriate tags to group related endpoints
- Document security requirements when authentication is needed
- Reference common components instead of duplicating schemas
- Include all possible response scenarios
- Provide clear parameter descriptions
All protected routes should include the security section with bearerAuth. This indicates that a JWT token is required in the Authorization header.
For endpoints that return lists, always include:
- Page parameter
- Limit parameter
- Sort parameter
- Use the
PaginatedResponseschema for the response
Consistently use the predefined error response schemas:
400: ValidationError401: UnauthorizedError404: NotFoundError500: ServerError
After adding new endpoint documentation:
- Start the server
- Visit the Swagger UI endpoint (usually
/api-docs) - Verify that the new endpoint appears and is correctly documented
- Test the endpoint through the Swagger UI interface