# ============================================================================ # API Design Template # ============================================================================ # This template follows SOP-200 (API Design) standards. # Copy this file and customize for your project's API specification. # # Usage: # 1. Copy to your project: /docs/api/openapi.yaml # 2. Replace placeholder values (marked with ) # 3. Add your endpoints following the patterns below # 4. Validate using: https://editor.swagger.io/ # ============================================================================ openapi: 3.0.3 info: title: API description: | ## Overview ## Authentication This API uses Bearer token authentication. Include the token in the `Authorization` header: `Bearer ` ## Rate Limiting - **Authenticated requests:** 1000 requests/hour - **Unauthenticated requests:** 100 requests/hour ## Error Handling All errors follow the standard error response format defined in SOP-203. version: 1.0.0 contact: name: API Support email: servers: - url: http://localhost:3000/api/v1 description: Local development - url: https://staging./api/v1 description: Staging environment - url: https://api./v1 description: Production # ============================================================================ # SECURITY SCHEMES (SOP-201) # ============================================================================ components: securitySchemes: bearerAuth: type: http scheme: bearer bearerFormat: JWT description: JWT token obtained from /auth/login # ========================================================================== # STANDARD RESPONSE SCHEMAS (SOP-203) # ========================================================================== schemas: # Standard Error Response ErrorResponse: type: object required: - success - error properties: success: type: boolean example: false error: type: object required: - code - message properties: code: type: string description: Machine-readable error code example: VALIDATION_ERROR message: type: string description: Human-readable error message example: Invalid input data details: type: array description: Additional error details (optional) items: type: object properties: field: type: string example: email message: type: string example: Must be a valid email address # Standard Success Response Wrapper SuccessResponse: type: object required: - success - data properties: success: type: boolean example: true data: type: object description: Response payload meta: type: object description: Metadata (pagination, etc.) properties: page: type: integer example: 1 limit: type: integer example: 20 total: type: integer example: 100 totalPages: type: integer example: 5 # Pagination Query Parameters PaginationParams: type: object properties: page: type: integer minimum: 1 default: 1 description: Page number limit: type: integer minimum: 1 maximum: 100 default: 20 description: Items per page # -------------------------------------------------------------------------- # RESOURCE SCHEMAS - Add your domain models below # -------------------------------------------------------------------------- # Example: User Resource User: type: object required: - id - email - createdAt properties: id: type: string format: uuid example: 550e8400-e29b-41d4-a716-446655440000 email: type: string format: email example: user@example.com name: type: string example: John Doe role: type: string enum: [user, admin, moderator] example: user createdAt: type: string format: date-time example: "2026-01-28T10:30:00Z" updatedAt: type: string format: date-time example: "2026-01-28T10:30:00Z" # Example: Create User Request CreateUserRequest: type: object required: - email - password - name properties: email: type: string format: email example: newuser@example.com password: type: string format: password minLength: 8 example: SecurePass123! name: type: string minLength: 1 maxLength: 100 example: Jane Doe # Example: Update User Request UpdateUserRequest: type: object properties: name: type: string minLength: 1 maxLength: 100 example: Jane Smith email: type: string format: email example: jane.smith@example.com # ========================================================================== # REUSABLE PARAMETERS # ========================================================================== parameters: PathId: name: id in: path required: true description: Resource UUID schema: type: string format: uuid QueryPage: name: page in: query description: Page number for pagination schema: type: integer minimum: 1 default: 1 QueryLimit: name: limit in: query description: Number of items per page schema: type: integer minimum: 1 maximum: 100 default: 20 QuerySort: name: sort in: query description: "Sort field and direction (e.g., createdAt:desc)" schema: type: string example: createdAt:desc # ========================================================================== # REUSABLE RESPONSES # ========================================================================== responses: BadRequest: description: Invalid request data content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" example: success: false error: code: VALIDATION_ERROR message: Invalid input data details: - field: email message: Must be a valid email address Unauthorized: description: Authentication required content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" example: success: false error: code: UNAUTHORIZED message: Authentication required Forbidden: description: Insufficient permissions content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" example: success: false error: code: FORBIDDEN message: You do not have permission to perform this action NotFound: description: Resource not found content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" example: success: false error: code: NOT_FOUND message: Resource not found InternalError: description: Internal server error content: application/json: schema: $ref: "#/components/schemas/ErrorResponse" example: success: false error: code: INTERNAL_ERROR message: An unexpected error occurred # ============================================================================ # API ENDPOINTS # ============================================================================ paths: # -------------------------------------------------------------------------- # Health Check (Required for SOP-604) # -------------------------------------------------------------------------- /health: get: summary: Health check endpoint description: Returns the health status of the API operationId: getHealth tags: - System responses: "200": description: Service is healthy content: application/json: schema: type: object properties: status: type: string example: healthy timestamp: type: string format: date-time version: type: string example: 1.0.0 # -------------------------------------------------------------------------- # Authentication Endpoints (SOP-201) # -------------------------------------------------------------------------- /auth/register: post: summary: Register a new user operationId: registerUser tags: - Authentication requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/CreateUserRequest" responses: "201": description: User created successfully content: application/json: schema: allOf: - $ref: "#/components/schemas/SuccessResponse" - type: object properties: data: $ref: "#/components/schemas/User" "400": $ref: "#/components/responses/BadRequest" /auth/login: post: summary: Authenticate user and get token operationId: loginUser tags: - Authentication requestBody: required: true content: application/json: schema: type: object required: - email - password properties: email: type: string format: email password: type: string format: password responses: "200": description: Login successful content: application/json: schema: type: object properties: success: type: boolean example: true data: type: object properties: token: type: string example: eyJhbGciOiJIUzI1NiIs... expiresIn: type: integer example: 3600 user: $ref: "#/components/schemas/User" "401": $ref: "#/components/responses/Unauthorized" # -------------------------------------------------------------------------- # Example CRUD Endpoints - Users (Adapt for your resources) # -------------------------------------------------------------------------- /users: get: summary: List all users operationId: listUsers tags: - Users security: - bearerAuth: [] parameters: - $ref: "#/components/parameters/QueryPage" - $ref: "#/components/parameters/QueryLimit" - $ref: "#/components/parameters/QuerySort" - name: search in: query description: Search by name or email schema: type: string responses: "200": description: List of users content: application/json: schema: allOf: - $ref: "#/components/schemas/SuccessResponse" - type: object properties: data: type: array items: $ref: "#/components/schemas/User" "401": $ref: "#/components/responses/Unauthorized" /users/{id}: get: summary: Get user by ID operationId: getUserById tags: - Users security: - bearerAuth: [] parameters: - $ref: "#/components/parameters/PathId" responses: "200": description: User details content: application/json: schema: allOf: - $ref: "#/components/schemas/SuccessResponse" - type: object properties: data: $ref: "#/components/schemas/User" "401": $ref: "#/components/responses/Unauthorized" "404": $ref: "#/components/responses/NotFound" patch: summary: Update user operationId: updateUser tags: - Users security: - bearerAuth: [] parameters: - $ref: "#/components/parameters/PathId" requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/UpdateUserRequest" responses: "200": description: User updated content: application/json: schema: allOf: - $ref: "#/components/schemas/SuccessResponse" - type: object properties: data: $ref: "#/components/schemas/User" "400": $ref: "#/components/responses/BadRequest" "401": $ref: "#/components/responses/Unauthorized" "404": $ref: "#/components/responses/NotFound" delete: summary: Delete user operationId: deleteUser tags: - Users security: - bearerAuth: [] parameters: - $ref: "#/components/parameters/PathId" responses: "204": description: User deleted successfully "401": $ref: "#/components/responses/Unauthorized" "403": $ref: "#/components/responses/Forbidden" "404": $ref: "#/components/responses/NotFound" # ============================================================================ # TAGS - Organize your endpoints # ============================================================================ tags: - name: System description: System and health endpoints - name: Authentication description: User authentication operations - name: Users description: User management operations # Add more tags for your domain resources: # - name: Products # description: Product catalog operations # - name: Orders # description: Order management operations