This document describes the Swagger/OpenAPI setup for the GoTogether travel planning API.
Once the application is running, you can access the interactive API documentation at:
- Local Development: http://localhost:3001/api
- Production: https://api.gotogether.com/api
- Auto-generated: Swagger documentation is automatically generated from code decorators
- Interactive: Test API endpoints directly from the browser
- Type-safe: Full TypeScript support with proper type definitions
The API is organized into the following modules:
GET /- Basic health check endpoint
GET /trips- Get paginated list of trips with filteringGET /trips/:id- Get detailed trip informationPOST /trips- Create a new trip
GET /activities- Search activities by location and filtersGET /activities/:id- Get detailed activity informationGET /activities/recommend/:tripId- Get AI-powered activity recommendations
- JWT Bearer Token: All protected endpoints require JWT authentication
- Persistent Authorization: Swagger UI remembers your auth token across sessions
All API responses follow a consistent structure:
{
"success": true,
"message": "Request completed successfully",
"timestamp": "2023-10-24T12:00:00.000Z",
"data": { ... }
}For paginated responses:
{
"success": true,
"message": "Data retrieved successfully",
"timestamp": "2023-10-24T12:00:00.000Z",
"meta": {
"page": 1,
"limit": 10,
"total": 150,
"totalPages": 15,
"hasNext": true,
"hasPrev": false
},
"data": [...]
}- Node.js (v18+)
- pnpm package manager
# Install dependencies
pnpm install
# Start development server
pnpm run start:devMake sure to set up your environment variables in .env:
NODE_ENV=development
PORT=3001
DATABASE_URL=postgresql://user:pass@localhost:5432/itinerary
JWT_SECRET=your-jwt-secret
JWT_EXPIRES_IN=15mimport { Controller, Get } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
@ApiTags('your-module')
@Controller('your-module')
export class YourController {
@Get()
@ApiOperation({
summary: 'Your endpoint summary',
description: 'Detailed description of what this endpoint does',
})
@ApiResponse({
status: 200,
description: 'Success response description',
})
yourEndpoint() {
// Implementation
}
}import { ApiProperty } from '@nestjs/swagger';
export class YourDto {
@ApiProperty({
description: 'Field description',
example: 'example value',
})
field: string;
}Add your module to AppModule imports:
@Module({
imports: [YourModule],
// ...
})
export class AppModule {}The Swagger UI is configured in src/main.ts with:
- Custom CSS to hide the top bar
- Persistent authorization
- Request duration display
- Collapsible sections by default
- Title: GoTogether API
- Description: Travel planning application API
- Version: 1.0
- Tags: Organized by feature modules (trips, activities, auth, etc.)
- Bearer token authentication using JWT
- Tokens should be included in the
Authorizationheader - Format:
Bearer <your-jwt-token>
- Development: All origins allowed
- Production: Restricted to gotogether.com domains
- Use Descriptive Names: Make endpoint summaries and descriptions clear
- Consistent Response Format: Follow the established response structure
- Proper HTTP Status Codes: Use appropriate status codes for different scenarios
- Input Validation: Document required fields and validation rules
- Error Handling: Provide clear error messages and codes
The Swagger documentation will be automatically available in production at:
https://your-production-domain/api
Make sure to update the server URLs in the DocumentBuilder configuration for your production environment.