We've updated the Swagger documentation for the IX Coach API to include all endpoints that were previously undocumented. This guide explains what was done and how to maintain the documentation moving forward.
-
Schema Definitions: Created comprehensive schema definitions for all API request and response objects in the
swagger-componentsdirectory:- Authentication: User-related schemas
- Settings: User settings schemas
- Projects: Project management schemas
- Conversations: Conversation and messaging schemas
- Notifications: Notification schemas
- Referrals: Referral program schemas
- Custom AI: AI-related schemas
- AB Testing: A/B testing schemas
- Subscriptions: Subscription and payment schemas
- Feedback: User feedback schemas
- Error Logging: Error logging schemas
- Analytics: User analytics schemas
-
Route Documentation: Added Swagger JSDoc comments to all route handlers, documenting:
- URL path and method
- Summary and detailed description
- Request parameters and body schemas
- Response schemas and status codes
- Authentication requirements
- Example requests and responses
-
New Route Files: Created new route files for endpoints that were missing implementation:
/routes/settings.js/routes/sync.js/routes/engagement.js/routes/log-error.js/routes/slack.js/routes/track-visit.js/routes/user-session.js
-
Updated Existing Routes: Added documentation to existing route files:
/routes/auth.js/routes/abTest.js/routes/subscription.js/routes/conversations.js/routes/notifications.js/routes/feedback.js
-
Configuration: Updated the Swagger configuration to include all new components and routes.
-
Documentation: Created comprehensive documentation on how to use and maintain the Swagger API documentation.
When running the API server, the Swagger documentation is available at:
http://localhost:3000/api-docs
When adding new endpoints, follow these steps:
-
Add Schema Definitions: Create or update schema definitions in the appropriate file in the
swagger-componentsdirectory. -
Document Route Handler: Add JSDoc comments above your route handler with the Swagger specification. Example:
/**
* @swagger
* /api/your-endpoint:
* post:
* summary: Short summary
* description: Detailed description
* tags: [Your Tag]
* security:
* - bearerAuth: []
* requestBody:
* required: true
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/YourRequestSchema'
* responses:
* 200:
* description: Success response
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/YourResponseSchema'
* 400:
* description: Bad request
* 401:
* description: Unauthorized
* 500:
* description: Server error
*/
router.post('/your-endpoint', auth, yourController.yourHandler);- Add Examples: Include example requests and responses where helpful:
* examples:
* Example Name:
* summary: Short summary of example
* value:
* property1: "value1"
* property2: "value2"-
Register the Route: Ensure your route is properly registered in the Express app.
-
Restart the Server: Restart the API server to see your new documentation.
To update existing documentation:
- Locate the route handler in the appropriate route file.
- Update the JSDoc comment with the new information.
- Restart the server to see the changes.
- Be Descriptive: Provide clear, concise descriptions for endpoints and parameters.
- Include Examples: Add examples for complex request bodies.
- Document All Responses: Document all possible response statuses and bodies.
- Keep Schemas Updated: When changing models, update the corresponding schema definitions.
- Organize by Tags: Use appropriate tags to organize endpoints by feature.
- Maintain Security Requirements: Always specify security requirements for protected endpoints.
Always test your documentation changes by:
- Starting the API server
- Navigating to the Swagger UI (
/api-docs) - Verifying that your endpoint is properly displayed
- Testing the endpoint using the "Try it out" feature
After examining the actual implementation code, I found and corrected the following misalignments:
-
Text-to-Speech Endpoint:
- Documentation listed it as
/api/speak-the-text - Actual implementation uses
/api/audios/text-to-speech - Fixed by creating proper documentation for the correct endpoint
- Documentation listed it as
-
User Language Detection:
- Documentation suggested there was an API endpoint for this
- Actual implementation makes direct calls to external services (
https://api.ipify.organdhttps://ipapi.co/) - Fixed by updating documentation to reflect this client-side implementation
The following items may still need attention:
- Comprehensive Validation: Implement a formal validation process to ensure documentation stays in sync with code
- More Detailed Examples: Add more detailed examples for complex endpoints
- Response Examples: Add examples of actual responses where helpful
- Environment-Specific URLs: Document environment-specific URLs for staging and production
- Automated Testing: Consider adding automated tests to verify API implementation matches documentation
With this comprehensive API documentation, developers can now more easily understand and use the IX Coach API. The documentation serves as both a reference and a testing tool, ensuring consistent API usage across the application.
For any questions or issues with the API documentation, please create a ticket or reach out to the development team.