openapi: 3.0.3 info: title: API de Maxocracia Cero description: | API para el sistema de economía colaborativa Maxocracia Cero. Permite la gestión de usuarios, autenticación, intercambios, VHV/TVI, formularios y contratos (MaxoContracts). version: 1.0.0 contact: name: Soporte Maxocracia Cero email: soporte@maxocracia.com servers: - url: http://localhost:5001 description: Servidor local (run.py) - url: https://api.maxocracia.com/v1 description: Servidor de producción (placeholder) components: securitySchemes: bearerAuth: type: http scheme: bearer bearerFormat: JWT schemas: User: type: object properties: id: type: integer format: int64 email: type: string format: email name: type: string alias: type: string nullable: true created_at: type: string format: date-time Token: type: object properties: access_token: type: string refresh_token: type: string expires_in: type: integer description: Tiempo de expiración en segundos Interchange: type: object required: - interchange_id - giver_id - receiver_id - description properties: interchange_id: type: string description: Identificador único del intercambio giver_id: type: integer description: ID del usuario que realiza el intercambio receiver_id: type: integer description: ID del usuario que recibe el intercambio description: type: string description: Descripción del intercambio uth_hours: type: number format: float default: 0 description: Horas de trabajo en Unidades de Tiempo Hombre (UTH) impact_resolution_score: type: integer default: 0 description: Puntuación de impacto/resolución VHV: type: object description: > Vector de Huella Vital. En la creación de contratos, `h` se acepta como alias de `r` para no romper el borrador del oráculo. properties: t: type: number description: Tiempo (Tiempo Vital Indexado) v: type: number description: Vida (Impacto en vida/sufrimiento) r: type: number description: Recursos (Uso de recursos finitos) MaxoContract: type: object properties: contract_id: type: string state: type: string enum: [draft, pending, active, executed, partial, retracted] civil_description: type: string participants: type: array items: type: string terms_count: type: integer total_vhv: $ref: '#/components/schemas/VHV' Error: type: object properties: error: type: string description: Descripción del error code: type: string description: Código estable cuando aplica (CONTRACT_CONFLICT, UNASSIGNED_OBLIGATION…) errors: type: array description: Todos los problemas del borrador, con su ruta items: $ref: '#/components/schemas/FieldError' FieldError: type: object properties: path: type: string example: terms[t1].vhv message: type: string code: type: string ValidationError: type: object properties: message: type: string errors: type: object additionalProperties: type: array items: type: string paths: /auth/register: post: tags: [Autenticación] summary: Registrar un nuevo usuario requestBody: required: true content: application/json: schema: type: object required: - email - password - name properties: email: type: string format: email example: usuario@ejemplo.com password: type: string format: password minLength: 8 example: Password1 name: type: string minLength: 2 example: Juan Pérez alias: type: string nullable: true example: juanp responses: '201': description: Usuario creado exitosamente content: application/json: schema: $ref: '#/components/schemas/Token' '400': description: Error en la solicitud content: application/json: schema: $ref: '#/components/schemas/ValidationError' /auth/login: post: tags: [Autenticación] summary: Iniciar sesión requestBody: required: true content: application/json: schema: type: object required: - email - password properties: email: type: string format: email example: usuario@ejemplo.com password: type: string format: password example: Password1 responses: '200': description: Inicio de sesión exitoso content: application/json: schema: $ref: '#/components/schemas/Token' '401': description: Credenciales inválidas /auth/refresh: post: tags: [Autenticación] summary: Refrescar token de acceso description: | En local/dev, el refresh token se envía como `Authorization: Bearer ` (ver docs/api/API.md). En modo browser, puede usarse cookie HttpOnly `mc_refresh`. responses: '200': description: Token refrescado exitosamente content: application/json: schema: $ref: '#/components/schemas/Token' '401': description: Token de refresco inválido o expirado /auth/me: get: tags: [Usuarios] summary: Obtener información del usuario actual security: - bearerAuth: [] responses: '200': description: Información del usuario content: application/json: schema: $ref: '#/components/schemas/User' '401': description: No autorizado /interchanges: get: tags: [Intercambios] summary: Listar intercambios recientes security: - bearerAuth: [] parameters: - name: limit in: query description: Número máximo de intercambios a devolver schema: type: integer default: 20 maximum: 200 responses: '200': description: Lista de intercambios content: application/json: schema: type: array items: $ref: '#/components/schemas/Interchange' post: tags: [Intercambios] summary: Crear un nuevo intercambio security: - bearerAuth: [] requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/Interchange' responses: '201': description: Intercambio creado exitosamente content: application/json: schema: type: object properties: message: type: string credit: type: number description: Créditos otorgados '400': description: Error en la solicitud content: application/json: schema: $ref: '#/components/schemas/Error' /maxo/balance: get: tags: [Créditos] summary: (Legacy) Obtener saldo actual security: - bearerAuth: [] responses: '200': description: Saldo actual content: application/json: schema: type: object properties: balance: type: number description: Saldo actual en Maxos /maxo/{user_id}/balance: get: tags: [Créditos] summary: Obtener saldo de un usuario security: - bearerAuth: [] parameters: - name: user_id in: path required: true schema: type: integer responses: '200': description: Saldo actual content: application/json: schema: type: object properties: user_id: type: integer balance: type: number '401': description: No autorizado '403': description: Prohibido /reputation: get: tags: [Reputación] summary: Obtener reputación del usuario actual security: - bearerAuth: [] responses: '200': description: Puntuación de reputación content: application/json: schema: type: object properties: score: type: number description: Puntuación de reputación /contracts: get: tags: [MaxoContracts] summary: Listar todos los contratos security: - bearerAuth: [] responses: '200': description: Lista de contratos content: application/json: schema: type: object properties: contracts: type: array items: $ref: '#/components/schemas/MaxoContract' total: type: integer post: tags: [MaxoContracts] summary: Crear un nuevo contrato description: | Acepta el borrador canónico completo: los mismos campos que devuelve `GET /contracts/{contract_id}` y que produce `POST /contracts/negotiate`. Los identificadores son opcionales; si faltan, los genera el servidor. Un término ilegible devuelve 400 con su posición: nada se descarta en silencio. security: - bearerAuth: [] requestBody: required: true content: application/json: schema: type: object properties: contract_id: type: string description: Opcional. Si falta, el servidor genera `maxo-ctr-XXXXXXXX`. civil_description: type: string signature_deadline: type: string format: date-time min_reflection_hours: type: number parent_contract_id: type: string dry_run: type: boolean description: > Valida y devuelve el borrador canónico sin escribir nada. También se acepta como `?dry_run=1`. participants: type: array items: type: object additionalProperties: true description: > Formas aceptadas: `{"user_id": 5}`, `{"participant_id": "synthetic-qwen-1", "realm": "synthetic"}` o `{"party_id": "coop-7", "party_type": "cooperative"}`. terms: type: array items: type: object properties: term_id: type: string description: Opcional; si falta, se genera `t1`, `t2`… civil_text: type: string vhv: $ref: '#/components/schemas/VHV' assigned_participant_id: type: string assigned_participant: type: string description: Alias de `assigned_participant_id` (borrador del oráculo). penalty_gamma: type: number minimum: 0 maximum: 0.5 required: [civil_text] responses: '200': description: Ensayo (`dry_run`) — valida y devuelve el borrador sin escribir content: application/json: schema: type: object properties: dry_run: type: boolean valid: type: boolean errors: type: array items: $ref: '#/components/schemas/FieldError' draft: $ref: '#/components/schemas/MaxoContract' '201': description: Contrato creado content: application/json: schema: type: object properties: success: type: boolean contract_id: type: string state: type: string '400': description: Término ilegible, penalización fuera de rango o descripción no cívica content: application/json: schema: $ref: '#/components/schemas/Error' '409': description: El contract_id ya existe y no es un borrador editable del mismo creador content: application/json: schema: $ref: '#/components/schemas/Error' /contracts/{contract_id}: get: tags: [MaxoContracts] summary: Obtener detalles de un contrato security: - bearerAuth: [] parameters: - name: contract_id in: path required: true schema: type: string responses: '200': description: Detalles del contrato content: application/json: schema: $ref: '#/components/schemas/MaxoContract' '404': description: No encontrado /contracts/{contract_id}/terms: post: tags: [MaxoContracts] summary: Añadir un término al contrato security: - bearerAuth: [] parameters: - name: contract_id in: path required: true schema: type: string requestBody: required: true content: application/json: schema: type: object required: [term_id, civil_text] properties: term_id: type: string civil_text: type: string vhv: $ref: '#/components/schemas/VHV' responses: '200': description: Término añadido '400': description: Error en la solicitud /contracts/{contract_id}/participants: post: tags: [MaxoContracts] summary: Añadir un participante al contrato security: - bearerAuth: [] parameters: - name: contract_id in: path required: true schema: type: string requestBody: required: true content: application/json: schema: type: object required: [user_id] properties: user_id: type: integer gamma: type: number description: Nivel inicial de bienestar (Wellness Index) responses: '200': description: Participante añadido /contracts/{contract_id}/validate: get: tags: [MaxoContracts] summary: Validar axiomas del contrato security: - bearerAuth: [] parameters: - name: contract_id in: path required: true schema: type: string responses: '200': description: Resultados de la validación /contracts/{contract_id}/accept: post: tags: [MaxoContracts] summary: Aceptar un término del contrato security: - bearerAuth: [] parameters: - name: contract_id in: path required: true schema: type: string requestBody: required: true content: application/json: schema: type: object required: [term_id, user_id] properties: term_id: type: string user_id: type: integer responses: '200': description: Término aceptado /contracts/{contract_id}/activate: post: tags: [MaxoContracts] summary: Activar el contrato security: - bearerAuth: [] parameters: - name: contract_id in: path required: true schema: type: string responses: '200': description: Contrato activado /contracts/{contract_id}/retract: post: tags: [MaxoContracts] summary: Solicitar retractación ética security: - bearerAuth: [] parameters: - name: contract_id in: path required: true schema: type: string requestBody: required: true content: application/json: schema: type: object required: [user_id, reason] properties: user_id: type: integer reason: type: string cause: type: string responses: '200': description: Retractación procesada /contracts/{contract_id}/civil: get: tags: [MaxoContracts] summary: Obtener resumen del contrato en lenguaje civil security: - bearerAuth: [] parameters: - name: contract_id in: path required: true schema: type: string responses: '200': description: Resumen civil security: - bearerAuth: []