openapi: 3.0.0 info: title: API de Gestión de Tareas description: API RESTful para crear, leer, actualizar y eliminar tareas con autenticación JWT version: 1.0.0 contact: name: Soporte API email: support@tareas.local servers: - url: http://localhost:3000/api description: Servidor de desarrollo - url: https://api.tareas.local/api description: Servidor de producción tags: - name: Autenticación description: Endpoints de autenticación y gestión de tokens - name: Tareas description: Operaciones CRUD sobre tareas components: securitySchemes: bearerAuth: type: http scheme: bearer bearerFormat: JWT description: JWT token obtenido del endpoint de login schemas: User: type: object required: - username - email - password properties: _id: type: string description: ID único del usuario (MongoDB ObjectId) example: 507f1f77bcf86cd799439011 username: type: string minLength: 3 maxLength: 20 pattern: '^[a-zA-Z0-9_-]+$' description: Nombre de usuario único example: john_doe email: type: string format: email description: Email único del usuario example: john@example.com password: type: string minLength: 6 description: Contraseña (solo en solicitudes, nunca en respuestas) example: securepassword123 createdAt: type: string format: date-time description: Fecha de creación updatedAt: type: string format: date-time description: Fecha de última actualización Task: type: object required: - title - description - status - userId properties: _id: type: string description: ID único de la tarea example: 507f1f77bcf86cd799439012 title: type: string minLength: 3 maxLength: 100 description: Título de la tarea example: Completar documentación description: type: string maxLength: 500 description: Descripción detallada example: Escribir la documentación técnica del proyecto status: type: string enum: [pending, in_progress, completed, cancelled] default: pending description: Estado actual de la tarea priority: type: string enum: [low, medium, high] default: medium description: Prioridad de la tarea dueDate: type: string format: date description: Fecha de vencimiento (YYYY-MM-DD) example: "2026-12-31" tags: type: array items: type: string maxItems: 10 description: Etiquetas asociadas example: [backend, documentation] userId: type: string description: ID del usuario propietario example: 507f1f77bcf86cd799439011 createdAt: type: string format: date-time description: Fecha de creación updatedAt: type: string format: date-time description: Fecha de última actualización LoginRequest: type: object required: - username - password properties: username: type: string example: john_doe password: type: string example: securepassword123 LoginResponse: type: object properties: token: type: string description: JWT token para autenticación example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... user: $ref: '#/components/schemas/User' RegisterRequest: type: object required: - username - email - password properties: username: type: string minLength: 3 example: john_doe email: type: string format: email example: john@example.com password: type: string minLength: 6 example: securepassword123 PaginatedTasksResponse: type: object properties: data: type: array items: $ref: '#/components/schemas/Task' pagination: type: object properties: total: type: integer example: 150 page: type: integer example: 1 limit: type: integer example: 10 pages: type: integer example: 15 ErrorResponse: type: object properties: error: type: string description: Descripción del error example: Tarea no encontrada statusCode: type: integer example: 404 timestamp: type: string format: date-time responses: Unauthorized: description: Token no válido o ausente content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' example: error: Unauthorized statusCode: 401 Forbidden: description: Acceso denegado content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' example: error: Forbidden statusCode: 403 NotFound: description: Recurso no encontrado content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' example: error: Not Found statusCode: 404 RateLimitExceeded: description: Límite de velocidad excedido content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' example: error: Rate limit exceeded statusCode: 429 headers: X-RateLimit-Limit: schema: type: integer description: Número máximo de solicitudes permitidas X-RateLimit-Remaining: schema: type: integer description: Número de solicitudes restantes X-RateLimit-Reset: schema: type: integer description: Timestamp cuando se reinicia el límite paths: /auth/register: post: summary: Registrar nuevo usuario tags: - Autenticación requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/RegisterRequest' responses: '201': description: Usuario registrado exitosamente content: application/json: schema: $ref: '#/components/schemas/LoginResponse' '400': description: Datos inválidos o usuario ya existe content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '429': $ref: '#/components/responses/RateLimitExceeded' /auth/login: post: summary: Iniciar sesión y obtener token tags: - Autenticación requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/LoginRequest' responses: '200': description: Login exitoso content: application/json: schema: $ref: '#/components/schemas/LoginResponse' '401': description: Credenciales inválidas content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '429': $ref: '#/components/responses/RateLimitExceeded' /tasks: get: summary: Obtener todas las tareas del usuario tags: - Tareas security: - bearerAuth: [] parameters: - name: page in: query schema: type: integer default: 1 minimum: 1 description: Número de página - name: limit in: query schema: type: integer default: 10 minimum: 1 maximum: 100 description: Tareas por página - name: status in: query schema: type: string enum: [pending, in_progress, completed, cancelled] description: Filtrar por estado - name: priority in: query schema: type: string enum: [low, medium, high] description: Filtrar por prioridad - name: sort in: query schema: type: string default: -createdAt description: Campo para ordenar (prefijo - para descendente) responses: '200': description: Lista de tareas content: application/json: schema: $ref: '#/components/schemas/PaginatedTasksResponse' '401': $ref: '#/components/responses/Unauthorized' '429': $ref: '#/components/responses/RateLimitExceeded' post: summary: Crear nueva tarea tags: - Tareas security: - bearerAuth: [] requestBody: required: true content: application/json: schema: type: object required: - title - description properties: title: type: string minLength: 3 maxLength: 100 description: type: string maxLength: 500 status: type: string enum: [pending, in_progress, completed, cancelled] default: pending priority: type: string enum: [low, medium, high] default: medium dueDate: type: string format: date tags: type: array items: type: string responses: '201': description: Tarea creada exitosamente content: application/json: schema: $ref: '#/components/schemas/Task' '400': description: Datos inválidos content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '401': $ref: '#/components/responses/Unauthorized' '429': $ref: '#/components/responses/RateLimitExceeded' /tasks/{id}: parameters: - name: id in: path required: true schema: type: string description: ID de la tarea (MongoDB ObjectId) get: summary: Obtener detalles de una tarea tags: - Tareas security: - bearerAuth: [] responses: '200': description: Detalles de la tarea content: application/json: schema: $ref: '#/components/schemas/Task' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' '429': $ref: '#/components/responses/RateLimitExceeded' put: summary: Actualizar una tarea completamente tags: - Tareas security: - bearerAuth: [] requestBody: required: true content: application/json: schema: type: object required: - title - description - status properties: title: type: string minLength: 3 maxLength: 100 description: type: string maxLength: 500 status: type: string enum: [pending, in_progress, completed, cancelled] priority: type: string enum: [low, medium, high] dueDate: type: string format: date tags: type: array items: type: string responses: '200': description: Tarea actualizada content: application/json: schema: $ref: '#/components/schemas/Task' '400': description: Datos inválidos content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' '429': $ref: '#/components/responses/RateLimitExceeded' patch: summary: Actualizar parcialmente una tarea tags: - Tareas security: - bearerAuth: [] requestBody: required: true content: application/json: schema: type: object properties: title: type: string minLength: 3 maxLength: 100 description: type: string maxLength: 500 status: type: string enum: [pending, in_progress, completed, cancelled] priority: type: string enum: [low, medium, high] dueDate: type: string format: date tags: type: array items: type: string responses: '200': description: Tarea actualizada content: application/json: schema: $ref: '#/components/schemas/Task' '400': description: Datos inválidos content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' '429': $ref: '#/components/responses/RateLimitExceeded' delete: summary: Eliminar una tarea tags: - Tareas security: - bearerAuth: [] responses: '204': description: Tarea eliminada exitosamente '401': $ref: '#/components/responses/Unauthorized' '403': $ref: '#/components/responses/Forbidden' '404': $ref: '#/components/responses/NotFound' '429': $ref: '#/components/responses/RateLimitExceeded' security: - bearerAuth: []