{
  "openapi": "3.1.0",
  "info": {
    "title": "soffice",
    "version": "2.1.1",
    "description": "Microservicio de conversión de documentos DOCX a PDF con LibreOffice. Documentación legible en /."
  },
  "servers": [
    {
      "url": "https://soffice.apps360.es"
    }
  ],
  "security": [
    {
      "bearer": []
    },
    {
      "cabecera": []
    },
    {
      "parametro": []
    }
  ],
  "paths": {
    "/index.php": {
      "post": {
        "summary": "Convertir un DOCX a PDF",
        "description": "También disponible en / y /convertir. Las conversiones se atienden por orden de llegada; la respuesta llega cuando el PDF está listo.",
        "operationId": "convertir",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "documento"
                ],
                "properties": {
                  "documento": {
                    "type": "string",
                    "format": "binary",
                    "description": "Fichero DOCX. Máximo 20 MB."
                  },
                  "vars": {
                    "type": "string",
                    "description": "JSON {\"clave\": \"valor\"}. Cada clave se sustituye literalmente por su valor en word/document.xml antes de convertir. Los valores se insertan sin escapar: escapar &, < y > en el cliente.",
                    "examples": [
                      "{\"[NOMBRE]\": \"Ana García\", \"[FECHA]\": \"28/10/2026\"}"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "PDF generado.",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "500": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          },
          "504": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/salud": {
      "get": {
        "summary": "Estado del servicio",
        "operationId": "salud",
        "security": [],
        "responses": {
          "200": {
            "description": "El servicio está en marcha.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "estado": {
                      "type": "string",
                      "const": "ok"
                    },
                    "enCurso": {
                      "type": "integer",
                      "description": "Conversiones en curso"
                    },
                    "enEspera": {
                      "type": "integer",
                      "description": "Conversiones esperando turno"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer"
      },
      "cabecera": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Soffice-Token"
      },
      "parametro": {
        "type": "apiKey",
        "in": "query",
        "name": "token"
      }
    },
    "responses": {
      "Error": {
        "description": "Error. El campo error indica la causa.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "required": [
                "error",
                "mensaje"
              ],
              "properties": {
                "error": {
                  "type": "string",
                  "enum": [
                    "SIN_DOCUMENTO",
                    "VARS_INCORRECTAS",
                    "PETICION_INCORRECTA",
                    "NO_AUTORIZADO",
                    "DOCUMENTO_DEMASIADO_GRANDE",
                    "NO_ES_DOCX",
                    "CONVERSION_FALLIDA",
                    "COLA_LLENA",
                    "PLAZO_AGOTADO",
                    "NO_ENCONTRADO",
                    "ERROR_INTERNO"
                  ]
                },
                "mensaje": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  }
}
