{
  "openapi": "3.1.0",
  "info": {
    "title": "Catálogo de audiolibros y libros — API para LLMs",
    "version": "1.0.0",
    "description": "API pública de solo lectura del catálogo de libros.ingenieria.dev: más de 28 mil audiolibros y libros electrónicos en español, inglés y otros idiomas, con autores, narradores, género, duración, valoración, reacciones y reseñas.\n\nPensada para que cualquier LLM o agente la use sin clave: JSON, CORS abierto, sin autenticación, 120 solicitudes por minuto por IP.\n\nCómo usarla: 1) busca con GET /api/books (q + filtros); 2) pide el detalle con GET /api/books/{id}; 3) reseñas con GET /api/books/{id}/reviews. Los valores válidos de género, idioma, autor y narrador salen de /api/genres, /api/languages, /api/authors y /api/narrators. Usa `fields` para respuestas cortas y `facets=true` para saber cómo refinar.\n\nCada libro trae `url`, la ficha pública en el sitio, para enlazarla en la respuesta al usuario."
  },
  "servers": [
    {
      "url": "https://libros.ingenieria.dev"
    }
  ],
  "tags": [
    {
      "name": "libros"
    },
    {
      "name": "catálogo"
    }
  ],
  "paths": {
    "/api/books": {
      "get": {
        "operationId": "searchBooks",
        "tags": [
          "libros"
        ],
        "summary": "Buscar y filtrar libros y audiolibros",
        "description": "Búsqueda de texto completo con filtros combinables (AND entre filtros, OR dentro de una lista separada por comas), orden y paginación. Ej.: audiolibros de terror en español de más de 4.3 estrellas con al menos 50 valoraciones → `?format=audiobook&language=es&genre=Terror y Suspenso&minRating=4.3&minRatings=50&sort=rating`.",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "description": "Búsqueda de texto completo (título, autores, narradores, género, palabras clave y sinopsis). Sin acentos ni mayúsculas. Admite frases entre comillas, OR, NOT y prefijo con * (ej. `dragon*`).",
            "schema": {
              "type": "string"
            },
            "example": "cien años de soledad"
          },
          {
            "name": "title",
            "in": "query",
            "description": "Filtra por palabras del título (subcadena, sin distinguir mayúsculas).",
            "schema": {
              "type": "string"
            },
            "example": "principito"
          },
          {
            "name": "author",
            "in": "query",
            "description": "Autor: coincidencia exacta del nombre (sin distinguir mayúsculas); si no hay exacta, subcadena. Lista de nombres en GET /api/authors.",
            "schema": {
              "type": "string"
            },
            "example": "Gabriel García Márquez"
          },
          {
            "name": "narrator",
            "in": "query",
            "description": "Narrador (mismo criterio que author). Lista en GET /api/narrators.",
            "schema": {
              "type": "string"
            },
            "example": "Carlos Ponce"
          },
          {
            "name": "publisher",
            "in": "query",
            "description": "Editorial (subcadena).",
            "schema": {
              "type": "string"
            },
            "example": "Penguin"
          },
          {
            "name": "genre",
            "in": "query",
            "description": "Género exacto. Varios separados por coma = cualquiera de ellos. Valores en GET /api/genres.",
            "schema": {
              "type": "string"
            },
            "example": "Novelas,Clásicos"
          },
          {
            "name": "language",
            "in": "query",
            "description": "Código de idioma ISO 639-1. Varios separados por coma. Valores en GET /api/languages.",
            "schema": {
              "type": "string"
            },
            "example": "es"
          },
          {
            "name": "format",
            "in": "query",
            "description": "Formato: `audiobook` (audiolibro) o `ebook` (libro electrónico).",
            "schema": {
              "type": "string",
              "enum": [
                "audiobook",
                "ebook"
              ]
            },
            "example": "audiobook"
          },
          {
            "name": "isbn",
            "in": "query",
            "description": "ISBN-10 o ISBN-13 exacto (con o sin guiones).",
            "schema": {
              "type": "string"
            },
            "example": "9788497592208"
          },
          {
            "name": "minRating",
            "in": "query",
            "description": "Valoración media mínima (0 a 5).",
            "schema": {
              "type": "number",
              "minimum": 0,
              "maximum": 5
            },
            "example": 4.2
          },
          {
            "name": "maxRating",
            "in": "query",
            "description": "Valoración media máxima (0 a 5).",
            "schema": {
              "type": "number",
              "minimum": 0,
              "maximum": 5
            }
          },
          {
            "name": "minRatings",
            "in": "query",
            "description": "Número mínimo de valoraciones (popularidad).",
            "schema": {
              "type": "integer",
              "minimum": 0
            },
            "example": 100
          },
          {
            "name": "minReviews",
            "in": "query",
            "description": "Número mínimo de reseñas escritas.",
            "schema": {
              "type": "integer",
              "minimum": 0
            },
            "example": 1
          },
          {
            "name": "hasDescription",
            "in": "query",
            "description": "true = solo libros con sinopsis.",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "durationMin",
            "in": "query",
            "description": "Duración mínima en minutos (solo audiolibros).",
            "schema": {
              "type": "integer",
              "minimum": 0
            },
            "example": 60
          },
          {
            "name": "durationMax",
            "in": "query",
            "description": "Duración máxima en minutos (solo audiolibros).",
            "schema": {
              "type": "integer",
              "minimum": 0
            },
            "example": 300
          },
          {
            "name": "yearFrom",
            "in": "query",
            "description": "Año de publicación desde (inclusive).",
            "schema": {
              "type": "integer"
            },
            "example": 2015
          },
          {
            "name": "yearTo",
            "in": "query",
            "description": "Año de publicación hasta (inclusive).",
            "schema": {
              "type": "integer"
            },
            "example": 2025
          },
          {
            "name": "sort",
            "in": "query",
            "description": "Orden. `relevance` (por defecto con q), `ratings` (más valorados; por defecto sin q), `rating`, `reviews`, `title`, `duration`, `published`/`recent` (más nuevos). Prefijo `-` invierte el sentido (ej. `-duration` = más cortos primero, `title` es A→Z).",
            "schema": {
              "type": "string",
              "enum": [
                "relevance",
                "rating",
                "ratings",
                "reviews",
                "title",
                "duration",
                "published",
                "recent",
                "-relevance",
                "-rating",
                "-ratings",
                "-reviews",
                "-title",
                "-duration",
                "-published",
                "-recent"
              ]
            },
            "example": "rating"
          },
          {
            "name": "page",
            "in": "query",
            "description": "Página (desde 1).",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            },
            "example": 1
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Resultados por página (1 a 100).",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            },
            "example": 20
          },
          {
            "name": "fields",
            "in": "query",
            "description": "Campos a devolver, separados por coma (respuesta más ligera para un LLM). Disponibles: id, title, slug, url, authors, narrators, publisher, genre, keywords, language, isbn, format, durationMinutes, published, year, rating, ratingCount, reviewCount, cover, description, reactions. Por defecto todos salvo description y reactions.",
            "schema": {
              "type": "string"
            },
            "example": "id,title,authors,rating,url"
          },
          {
            "name": "facets",
            "in": "query",
            "description": "true = incluye conteos por género, idioma y formato del resultado filtrado (para refinar la búsqueda).",
            "schema": {
              "type": "boolean"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BookList"
                }
              }
            }
          },
          "400": {
            "description": "Parámetro inválido",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No existe",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Demasiadas solicitudes (120 por minuto por IP)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/books/{id}": {
      "get": {
        "operationId": "getBook",
        "tags": [
          "libros"
        ],
        "summary": "Ficha completa de un libro (sinopsis, reacciones y últimas reseñas)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "id del libro (de /api/books).",
            "schema": {
              "type": "integer"
            },
            "example": 192362
          },
          {
            "name": "reviews",
            "in": "query",
            "description": "Cuántas reseñas recientes incluir (0 a 50, por defecto 5).",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 50,
              "default": 5
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BookDetail"
                }
              }
            }
          },
          "400": {
            "description": "Parámetro inválido",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No existe",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Demasiadas solicitudes (120 por minuto por IP)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/books/{id}/reviews": {
      "get": {
        "operationId": "listReviews",
        "tags": [
          "libros"
        ],
        "summary": "Reseñas de un libro, paginadas",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "minRating",
            "in": "query",
            "description": "Solo reseñas con al menos esta valoración (1 a 5).",
            "schema": {
              "type": "number"
            },
            "example": 4
          },
          {
            "name": "maxRating",
            "in": "query",
            "description": "Solo reseñas con como máximo esta valoración (1 a 5); útil para críticas negativas.",
            "schema": {
              "type": "number"
            },
            "example": 2
          },
          {
            "name": "sort",
            "in": "query",
            "description": "`recent` (por defecto), `rating` (mejores primero) o `-rating` (peores primero).",
            "schema": {
              "type": "string",
              "enum": [
                "recent",
                "rating",
                "-rating"
              ]
            },
            "example": "recent"
          },
          {
            "name": "page",
            "in": "query",
            "description": "Página (desde 1).",
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "example": 1
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Resultados por página (1 a 100, por defecto 20).",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            },
            "example": 20
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "bookId": {
                      "type": "integer"
                    },
                    "total": {
                      "type": "integer"
                    },
                    "page": {
                      "type": "integer"
                    },
                    "limit": {
                      "type": "integer"
                    },
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Review"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Parámetro inválido",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No existe",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Demasiadas solicitudes (120 por minuto por IP)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/genres": {
      "get": {
        "operationId": "listGenres",
        "tags": [
          "catálogo"
        ],
        "summary": "Géneros con número de libros",
        "parameters": [
          {
            "name": "language",
            "in": "query",
            "description": "Cuenta solo libros de este idioma.",
            "schema": {
              "type": "string"
            },
            "example": "es"
          },
          {
            "name": "format",
            "in": "query",
            "description": "Cuenta solo este formato.",
            "schema": {
              "type": "string",
              "enum": [
                "audiobook",
                "ebook"
              ]
            },
            "example": "audiobook"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "total": {
                      "type": "integer"
                    },
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string"
                          },
                          "count": {
                            "type": "integer"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/languages": {
      "get": {
        "operationId": "listLanguages",
        "tags": [
          "catálogo"
        ],
        "summary": "Idiomas (código ISO 639-1 y nombre en español) con número de libros",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "total": {
                      "type": "integer"
                    },
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "code": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          },
                          "count": {
                            "type": "integer"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/authors": {
      "get": {
        "operationId": "listAuthors",
        "tags": [
          "catálogo"
        ],
        "summary": "Autores con número de libros (más prolíficos primero)",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "description": "Filtra por subcadena del nombre.",
            "schema": {
              "type": "string"
            },
            "example": "king"
          },
          {
            "name": "limit",
            "in": "query",
            "description": "1 a 500, por defecto 50.",
            "schema": {
              "type": "integer"
            },
            "example": 50
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "total": {
                      "type": "integer"
                    },
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string"
                          },
                          "count": {
                            "type": "integer"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/narrators": {
      "get": {
        "operationId": "listNarrators",
        "tags": [
          "catálogo"
        ],
        "summary": "Narradores con número de audiolibros",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "description": "Filtra por subcadena del nombre.",
            "schema": {
              "type": "string"
            },
            "example": "ponce"
          },
          {
            "name": "limit",
            "in": "query",
            "description": "1 a 500, por defecto 50.",
            "schema": {
              "type": "integer"
            },
            "example": 50
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "total": {
                      "type": "integer"
                    },
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string"
                          },
                          "count": {
                            "type": "integer"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/stats": {
      "get": {
        "operationId": "getStats",
        "tags": [
          "catálogo"
        ],
        "summary": "Totales del catálogo y fecha de actualización",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Stats"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Book": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "title": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri",
            "description": "Ficha pública del libro en el sitio."
          },
          "authors": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "narrators": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "publisher": {
            "type": [
              "string",
              "null"
            ]
          },
          "genre": {
            "type": [
              "string",
              "null"
            ]
          },
          "keywords": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "language": {
            "type": [
              "string",
              "null"
            ],
            "description": "ISO 639-1"
          },
          "isbn": {
            "type": [
              "string",
              "null"
            ]
          },
          "format": {
            "type": "string",
            "enum": [
              "audiobook",
              "ebook"
            ]
          },
          "durationMinutes": {
            "type": [
              "integer",
              "null"
            ]
          },
          "published": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          },
          "year": {
            "type": [
              "integer",
              "null"
            ]
          },
          "rating": {
            "type": [
              "number",
              "null"
            ],
            "description": "Media de 0 a 5"
          },
          "ratingCount": {
            "type": "integer"
          },
          "reviewCount": {
            "type": "integer"
          },
          "cover": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "reactions": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "pct": {
                  "type": "integer"
                }
              }
            },
            "description": "Cómo describen el libro sus lectores y qué porcentaje lo eligió."
          }
        }
      },
      "BookList": {
        "type": "object",
        "properties": {
          "total": {
            "type": "integer"
          },
          "page": {
            "type": "integer"
          },
          "limit": {
            "type": "integer"
          },
          "pages": {
            "type": "integer"
          },
          "next": {
            "type": [
              "string",
              "null"
            ],
            "description": "URL de la siguiente página, o null."
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Book"
            }
          },
          "facets": {
            "type": "object",
            "properties": {
              "genre": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "type": "string"
                    },
                    "count": {
                      "type": "integer"
                    }
                  }
                }
              },
              "language": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "type": "string"
                    },
                    "count": {
                      "type": "integer"
                    }
                  }
                }
              },
              "format": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "type": "string"
                    },
                    "count": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "BookDetail": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Book"
          },
          {
            "type": "object",
            "properties": {
              "reviews": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/Review"
                }
              }
            }
          }
        ]
      },
      "Review": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "rating": {
            "type": [
              "number",
              "null"
            ]
          },
          "date": {
            "type": "string",
            "format": "date"
          },
          "author": {
            "type": "string"
          },
          "comment": {
            "type": "string"
          }
        }
      },
      "Stats": {
        "type": "object",
        "properties": {
          "books": {
            "type": "integer"
          },
          "audiobooks": {
            "type": "integer"
          },
          "ebooks": {
            "type": "integer"
          },
          "reviews": {
            "type": "integer"
          },
          "authors": {
            "type": "integer"
          },
          "narrators": {
            "type": "integer"
          },
          "genres": {
            "type": "integer"
          },
          "languages": {
            "type": "integer"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}