This document describes the API documentation setup for the Stellar MarketPay backend.
The Stellar MarketPay API uses OpenAPI 3.0 specification with Swagger UI for interactive documentation. All API endpoints are documented with JSDoc annotations that are automatically processed to generate the OpenAPI specification.
- Interactive Swagger UI: Available at
/api/docsin development and production - Auto-generated OpenAPI spec: Generated from JSDoc annotations in route files
- Build-time validation: CI/CD checks ensure all routes are documented
- Live documentation: Always in sync with the actual API implementation
- Swagger UI: http://localhost:4000/api/docs
- OpenAPI JSON: http://localhost:4000/api/docs/json
- Swagger UI: https://api.stellarmarketpay.com/api/docs
- OpenAPI JSON: https://api.stellarmarketpay.com/api/docs/json
When adding new API endpoints, follow these steps:
/**
* @swagger
* /api/your-endpoint:
* get:
* summary: Brief description of the endpoint
* description: Detailed description of what the endpoint does
* tags: [YourTag]
* parameters:
* - in: query
* name: paramName
* required: true
* schema:
* type: string
* description: Parameter description
* responses:
* 200:
* description: Success response description
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* data:
* $ref: '#/components/schemas/YourSchema'
*/
router.get("/your-endpoint", (req, res) => {
// Your implementation
});Add new schemas to the components/schemas section in src/config/swagger.js:
YourSchema: {
type: 'object',
properties: {
id: {
type: 'string',
description: 'Resource ID'
},
name: {
type: 'string',
description: 'Resource name'
}
}
}Run the build command to generate the OpenAPI specification:
npm run buildOr generate just the documentation:
npm run generate-openapisummary: Brief, one-line descriptiondescription: Detailed explanation of the endpointtags: Group endpoints logically (e.g., [Authentication], [Jobs], [Applications])responses: Document at least the success response and common error responses
Always document:
200: Success response400: Bad request401: Unauthorized (if authentication required)404: Resource not found500: Server error
- Path parameters: Mark as
required: true - Query parameters: Include type, format, and description
- Request body: Include schema validation
The following tags are used for organizing endpoints:
- Authentication: Auth-related endpoints (
/api/auth) - Health: Health check and status endpoints (
/health) - Jobs: Job management endpoints (
/api/jobs) - Applications: Application management (
/api/applications) - Profiles: User profile management (
/api/profiles) - Escrow: Escrow and payment management (
/api/escrow) - Ratings: Rating and review system (
/api/ratings) - Messages: Messaging system (
/api/messages)
- Bearer Token: JWT token in Authorization header
- Cookie Auth: JWT token in HTTP cookie
Add security requirements to protected endpoints:
security:
- bearerAuth: []
- cookieAuth: []The GitHub Actions workflow .github/workflows/check-openapi-docs.yml:
- Validates that all routes have OpenAPI annotations
- Generates the OpenAPI specification
- Validates JSON syntax
- Posts documentation status to pull requests
- Uploads the specification as an artifact
The build process includes:
- OpenAPI specification generation
- Linting and validation
- Documentation completeness checks
-
Missing @swagger annotations
- Error: "Found X undocumented routes"
- Solution: Add JSDoc annotations to undocumented routes
-
Invalid JSON in openapi.json
- Error: "Invalid JSON"
- Solution: Check for syntax errors in JSDoc annotations
-
Missing schemas
- Error: Schema not found
- Solution: Define missing schemas in swagger configuration
Enable debug logging by setting environment variable:
DEBUG=swagger-jsdoc* npm run generate-openapidocs/openapi.json: Complete OpenAPI 3.0 specification/api/docs: Interactive Swagger UI endpoint/api/docs/json: Raw OpenAPI JSON endpoint
- Review documentation for accuracy after API changes
- Update schemas when data models change
- Add new tags when introducing new endpoint categories
- Validate documentation completeness before releases
- Update API version in
src/config/swagger.js - Maintain backward compatibility when possible
- Document breaking changes in release notes
/**
* @swagger
* /api/jobs/{id}:
* get:
* summary: Get a specific job
* description: Retrieves detailed information about a specific job posting
* tags: [Jobs]
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* format: uuid
* description: Job ID
* - in: query
* name: viewerAddress
* schema:
* type: string
* description: Viewer's Stellar address for permission checks
* responses:
* 200:
* description: Job retrieved successfully
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: boolean
* example: true
* data:
* $ref: '#/components/schemas/Job'
* 404:
* description: Job not found
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* 403:
* description: Access denied - private job
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
*/
router.get("/:id", (req, res) => {
// Implementation
});This comprehensive documentation system ensures that the Stellar MarketPay API remains well-documented, easy to understand, and always in sync with the implementation.