First, install the required dependencies:
npm install swagger-jsdoc swagger-ui-express
npm install --save-dev @types/swagger-jsdoc @types/swagger-ui-expressOnce the server is running, you can access the Swagger documentation at:
- Swagger UI:
http://localhost:3000/api/docs - Swagger JSON:
http://localhost:3000/api/docs.json
For production:
- Swagger UI:
https://live.linkedtrust.us/api/docs - Swagger JSON:
https://live.linkedtrust.us/api/docs.json
- Browse all endpoints organized by tags
- See request/response schemas
- View example payloads
- Understand authentication requirements
- Test endpoints directly from the browser
- Authenticate with JWT tokens
- Send real requests to the API
- See actual responses
The documentation is organized into the following sections:
- Authentication: Login, signup, and token refresh
- Claims (Legacy v3): Backward-compatible claim endpoints
- Claims (v4): Modern claim management
- Credentials: Credential submission and retrieval
- Graph: Trust graph queries
- Feed: Activity feeds
- Reports: Reporting and validation
To test protected endpoints:
- First, use the
/auth/loginendpoint to get tokens - Click the "Authorize" button in Swagger UI
- Enter your access token in the format:
Bearer YOUR_ACCESS_TOKEN - Click "Authorize" to save
- Now you can test protected endpoints
To document new endpoints, add JSDoc comments in the route files:
/**
* @swagger
* /api/v4/new-endpoint:
* get:
* summary: Description of your endpoint
* tags: [Category]
* parameters:
* - in: query
* name: param
* schema:
* type: string
* description: Parameter description
* responses:
* 200:
* description: Success response
* content:
* application/json:
* schema:
* type: object
*/Common schemas are defined in src/lib/swagger.ts:
Error: Standard error responseAuthTokens: JWT token pairUser: User informationClaimV3Input/Response: Legacy claim formatsClaimV4Input: Modern claim formatCredential: Verifiable credential formatHowKnown: Enumeration of knowledge sources
You can export the API documentation:
- OpenAPI JSON: Visit
/api/docs.json - Postman Collection: Import the OpenAPI JSON into Postman
- Client Generation: Use the OpenAPI spec with code generators
- All v4 endpoints require JWT authentication (except GET operations)
- Legacy endpoints maintain original authentication requirements
- Tokens expire after 1 hour (access) and 7 days (refresh)
- Use HTTPS in production for secure token transmission
To customize the Swagger UI appearance, edit the options in src/index.ts:
app.use('/api/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec, {
customCss: '.swagger-ui .topbar { display: none }',
customSiteTitle: 'LinkedTrust API Documentation',
customfavIcon: '/favicon.ico',
swaggerOptions: {
persistAuthorization: true, // Remember auth between reloads
},
}));- Run the server in development mode to see documentation updates instantly
- Use the "Try it out" feature to test your implementations
- Export schemas to generate TypeScript types for the frontend
- Keep descriptions clear and examples realistic
- Document all possible error responses
If Swagger documentation doesn't appear:
- Check that all dependencies are installed
- Ensure
src/api/swagger-docs.tsis imported inindex.ts - Verify the paths in swagger configuration match your file structure
- Check console for any parsing errors in JSDoc comments
- Make sure the server is running on the correct port