openapi: 3.1.0 info: title: API Foro UNS version: '1.0.0' description: | Documentación de las APIs expuestas por el backend (Next.js App Router). La autenticación se basa en sesión de NextAuth (cookie). Muchos endpoints requieren rol **ADMIN** o que la cuenta no esté suspendida (`is_banned = true`). servers: - url: / description: Servidor actual (relative base path) components: securitySchemes: sessionCookie: type: apiKey in: cookie name: next-auth.session-token description: Sesión de NextAuth; incluir también `__Secure-next-auth.session-token` en HTTPS. schemas: ErrorResponse: type: object properties: error: type: string required: [error] SuccessResponse: type: object properties: success: type: boolean required: [success] UserSummary: type: object properties: name: type: string nullable: true role: type: string enum: [ADMIN, USER] is_banned: type: boolean required: [role] Ad: type: object properties: id: type: string image_url: type: string format: uri link_url: type: string format: uri required: [id, image_url, link_url] Tag: type: object properties: id: type: string name: type: string required: [id, name] CommentImage: type: object properties: id: type: string url: type: string format: uri required: [id, url] Comment: type: object properties: id: type: string content: type: string thread_id: type: string author_id: type: string users: $ref: '#/components/schemas/UserSummary' comment_images: type: array items: $ref: '#/components/schemas/CommentImage' created_at: type: string format: date-time required: [id, content, thread_id, author_id] Thread: type: object properties: id: type: string title: type: string is_closed: type: boolean created_at: type: string format: date-time author_id: type: string users: $ref: '#/components/schemas/UserSummary' tags: type: array items: $ref: '#/components/schemas/Tag' required: [id, title, is_closed] ThreadDetail: allOf: - $ref: '#/components/schemas/Thread' - type: object properties: comments: type: array items: $ref: '#/components/schemas/Comment' SummaryResponse: type: object properties: summary: type: string required: [summary] paths: /api/health: get: tags: [Health] summary: Verificar salud description: Retorna un estado simple con timestamp ISO. responses: '200': description: OK content: application/json: schema: type: object properties: status: type: string example: ok timestamp: type: string format: date-time /api/ads: get: tags: [Ads] summary: Listar anuncios activos description: Usuarios con suscripción (`is_subscribed = true`) reciben una lista vacía. security: [] responses: '200': description: Lista de anuncios o vacío para suscriptores content: application/json: schema: type: array items: $ref: '#/components/schemas/Ad' '500': description: Error interno content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' /api/comments: post: tags: [Comments] summary: Crear comentario security: [{ sessionCookie: [] }] requestBody: required: true content: application/json: schema: type: object properties: content: type: string thread_id: type: string image_urls: type: array items: type: string format: uri required: [content, thread_id] responses: '201': description: Comentario creado content: application/json: schema: $ref: '#/components/schemas/Comment' '400': description: Datos inválidos content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '401': description: Requiere sesión content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '403': description: Cuenta suspendida o hilo cerrado content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '404': description: Hilo o usuario inexistente content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' put: tags: [Comments] summary: Actualizar comentario (ADMIN + dueño) description: Requiere rol ADMIN **y** ser autor del comentario. security: [{ sessionCookie: [] }] requestBody: required: true content: application/json: schema: type: object properties: id: type: string description: También se acepta `comment_id` o `commentId`. content: type: string required: [id, content] responses: '200': description: Comentario actualizado content: application/json: schema: $ref: '#/components/schemas/Comment' '400': description: Datos inválidos content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '401': description: Requiere sesión content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '403': description: Sin permiso o cuenta suspendida content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '404': description: Comentario no encontrado content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' delete: tags: [Comments] summary: Eliminar comentario security: [{ sessionCookie: [] }] parameters: - in: query name: id schema: type: string description: También se acepta en body (`id`, `commentId`, `comment_id`). requestBody: required: false content: application/json: schema: type: object properties: id: type: string responses: '200': description: Comentario eliminado content: application/json: schema: $ref: '#/components/schemas/SuccessResponse' '400': description: Falta id content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '401': description: Requiere sesión content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '403': description: Sin permiso o cuenta suspendida content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '404': description: Comentario no encontrado content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' /api/search: get: tags: [Search] summary: Buscar hilos parameters: - in: query name: q schema: type: string description: Texto a buscar en título (insensible a mayúsculas). - in: query name: tags schema: type: string description: Lista separada por comas de nombres de etiqueta. responses: '200': description: Resultado de hilos content: application/json: schema: type: array items: $ref: '#/components/schemas/Thread' '500': description: Error interno content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' /api/tags: get: tags: [Tags] summary: Listar etiquetas populares parameters: - in: query name: search schema: type: string description: Filtro parcial por nombre (máx 15 resultados). responses: '200': description: Lista de tags content: application/json: schema: type: array items: $ref: '#/components/schemas/Tag' '500': description: Error interno content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' post: tags: [Tags] summary: Crear etiqueta (ADMIN) security: [{ sessionCookie: [] }] requestBody: required: true content: application/json: schema: type: object properties: name: type: string required: [name] responses: '201': description: Tag creado content: application/json: schema: $ref: '#/components/schemas/Tag' '400': description: Datos inválidos content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '401': description: Requiere sesión content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '403': description: Solo ADMIN o cuenta suspendida content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '409': description: Tag duplicado content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' delete: tags: [Tags] summary: Eliminar etiqueta (ADMIN) security: [{ sessionCookie: [] }] parameters: - in: query name: id schema: type: string description: También se acepta `tagId` en query o body. requestBody: required: false content: application/json: schema: type: object properties: id: type: string tagId: type: string responses: '200': description: Tag eliminado content: application/json: schema: $ref: '#/components/schemas/SuccessResponse' '400': description: Falta id content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '401': description: Requiere sesión content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '403': description: Solo ADMIN o cuenta suspendida content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '404': description: Tag no encontrado content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' /api/threads: get: tags: [Threads] summary: Listar hilos description: Ordenados desc por `created_at`. responses: '200': description: Lista de hilos content: application/json: schema: type: array items: $ref: '#/components/schemas/Thread' '500': description: Error interno content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' post: tags: [Threads] summary: Crear hilo security: [{ sessionCookie: [] }] requestBody: required: true content: application/json: schema: type: object properties: title: type: string required: [title] responses: '201': description: Hilo creado content: application/json: schema: $ref: '#/components/schemas/Thread' '400': description: Datos inválidos content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '401': description: Requiere sesión content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '403': description: Cuenta suspendida content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' /api/threads/{id}: get: tags: [Threads] summary: Obtener hilo por id parameters: - in: path name: id required: true schema: type: string responses: '200': description: Hilo encontrado content: application/json: schema: $ref: '#/components/schemas/ThreadDetail' '400': description: Falta id content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '404': description: No encontrado content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' patch: tags: [Threads] summary: Cerrar / abrir hilo (ADMIN) security: [{ sessionCookie: [] }] parameters: - in: path name: id required: true schema: type: string requestBody: required: false content: application/json: schema: type: object properties: is_closed: type: boolean description: Por defecto `true`. responses: '200': description: Hilo actualizado content: application/json: schema: $ref: '#/components/schemas/ThreadDetail' '400': description: Falta id o body inválido content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '401': description: Requiere sesión content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '403': description: Solo ADMIN o cuenta suspendida content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '404': description: Hilo no encontrado content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' /api/threads/{id}/summarize: post: tags: [Summaries] summary: Resumir hilo con Gemini security: [{ sessionCookie: [] }] parameters: - in: path name: id required: true schema: type: string responses: '200': description: Resumen generado content: application/json: schema: $ref: '#/components/schemas/SummaryResponse' '400': description: Falta id content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '401': description: Requiere sesión content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '404': description: Hilo no encontrado content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '500': description: Error interno (incluye falta de GEMINI_API_KEY) content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' /api/threads/{id}/tags: post: tags: [Thread Tags] summary: Agregar tag a hilo (ADMIN) security: [{ sessionCookie: [] }] parameters: - in: path name: id required: true schema: type: string requestBody: required: true content: application/json: schema: type: object properties: tagId: type: string name: type: string description: Se crea si no existe. responses: '200': description: Tag agregado content: application/json: schema: type: object properties: success: type: boolean tags: type: array items: $ref: '#/components/schemas/Tag' required: [success, tags] '400': description: Falta id o tag content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '401': description: Requiere sesión content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '403': description: Solo ADMIN o cuenta suspendida content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '404': description: Hilo no encontrado content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' delete: tags: [Thread Tags] summary: Quitar tag de hilo (ADMIN) security: [{ sessionCookie: [] }] parameters: - in: path name: id required: true schema: type: string - in: query name: tagId schema: type: string requestBody: required: false content: application/json: schema: type: object properties: tagId: type: string responses: '200': description: Tag removido content: application/json: schema: type: object properties: success: type: boolean tags: type: array items: $ref: '#/components/schemas/Tag' required: [success, tags] '400': description: Falta tagId o id content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '401': description: Requiere sesión content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '403': description: Solo ADMIN o cuenta suspendida content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' /api/users/ban: patch: tags: [Users] summary: Alternar ban de usuario (ADMIN) security: [{ sessionCookie: [] }] requestBody: required: true content: application/json: schema: type: object properties: userId: type: string description: También se acepta `id`. required: [userId] responses: '200': description: Estado de ban actualizado content: application/json: schema: type: object properties: id: type: string is_banned: type: boolean required: [id, is_banned] '400': description: Falta userId o intento de auto-ban content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '401': description: Requiere sesión content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '403': description: Solo ADMIN content: application/json: schema: $ref: '#/components/schemas/ErrorResponse' '404': description: Usuario no encontrado content: application/json: schema: $ref: '#/components/schemas/ErrorResponse'