{
  "openapi": "3.0.3",
  "info": {
    "title": "Zapford Catalog API",
    "version": "1.0.0",
    "description": "Карточки магазина zapford.ru (магазин 0, русский язык). Только чтение. Все карточки, включая отключенные, доступны по умолчанию. Цены базовые, остатки текущие. Снимок между страницами не фиксируется. HTML описания требует безопасного отображения на стороне клиента."
  },
  "servers": [
    {
      "url": "https://api.zapford.ru"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/products": {
      "get": {
        "summary": "Список карточек",
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Product"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "page": {
                          "type": "integer"
                        },
                        "per_page": {
                          "type": "integer"
                        },
                        "total": {
                          "type": "integer"
                        },
                        "total_pages": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Неверный или отсутствующий ключ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Не найдено",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Некорректный параметр",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышена частота запросов",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Каталог недоступен",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "description": "Страница, начиная с 1",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1,
              "maximum": 100000
            }
          },
          {
            "name": "per_page",
            "in": "query",
            "description": "Размер страницы: 1–100",
            "schema": {
              "type": "integer",
              "default": 25,
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "q",
            "in": "query",
            "description": "Поиск фрагмента названия, артикула, SKU или производителя",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "model",
            "in": "query",
            "description": "Точное совпадение артикула без учета регистра",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "manufacturer",
            "in": "query",
            "description": "Точное название без учета регистра; Ford, Ford USA и FORD EUROPE равнозначны",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "manufacturer_id",
            "in": "query",
            "description": "ID производителя",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "category_id",
            "in": "query",
            "description": "ID группы; без вложенных групп",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          },
          {
            "name": "status",
            "in": "query",
            "description": "Активность: 0 или 1; по умолчанию обе",
            "schema": {
              "type": "integer",
              "enum": [
                0,
                1
              ]
            }
          },
          {
            "name": "in_stock",
            "in": "query",
            "description": "1 — количество > 0, 0 — количество <= 0",
            "schema": {
              "type": "integer",
              "enum": [
                0,
                1
              ]
            }
          },
          {
            "name": "price_min",
            "in": "query",
            "description": "Минимальная базовая цена включительно",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "price_max",
            "in": "query",
            "description": "Максимальная базовая цена включительно",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "sort",
            "in": "query",
            "description": "id, name, model, price, quantity, date_modified",
            "schema": {
              "type": "string",
              "default": "id",
              "enum": [
                "id",
                "name",
                "model",
                "price",
                "quantity",
                "date_modified"
              ]
            }
          },
          {
            "name": "order",
            "in": "query",
            "description": "asc или desc",
            "schema": {
              "type": "string",
              "default": "asc",
              "enum": [
                "asc",
                "desc"
              ]
            }
          }
        ]
      }
    },
    "/v1/products/{id}": {
      "get": {
        "summary": "Полная карточка",
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ProductDetail"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Неверный или отсутствующий ключ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Не найдено",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Некорректный параметр",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышена частота запросов",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Каталог недоступен",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 2147483647
            }
          }
        ]
      }
    },
    "/v1/categories": {
      "get": {
        "summary": "Группы магазина",
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "allOf": [
                          {
                            "$ref": "#/components/schemas/ProductCategory"
                          }
                        ],
                        "properties": {
                          "sort_order": {
                            "type": "integer"
                          },
                          "product_count": {
                            "type": "integer"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Неверный или отсутствующий ключ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Не найдено",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Некорректный параметр",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышена частота запросов",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Каталог недоступен",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/manufacturers": {
      "get": {
        "summary": "Производители магазина",
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "integer"
                          },
                          "name": {
                            "type": "string"
                          },
                          "product_count": {
                            "type": "integer"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Неверный или отсутствующий ключ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Не найдено",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Некорректный параметр",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышена частота запросов",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Каталог недоступен",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/products/{id}/images/{image_id}": {
      "get": {
        "summary": "Файл фото",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 2147483647
            }
          },
          {
            "name": "image_id",
            "in": "path",
            "required": true,
            "description": "main для основного фото; числовой ID из images для дополнительного",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "If-None-Match",
            "in": "header",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Изображение",
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "image/jpeg": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/png": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "304": {
            "description": "Файл не изменился"
          },
          "401": {
            "description": "Требуется ключ"
          },
          "404": {
            "description": "Фото отсутствует"
          }
        }
      }
    },
    "/health": {
      "get": {
        "summary": "Проверка работы приложения (без проверки базы)",
        "security": [],
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string"
                    },
                    "service": {
                      "type": "string"
                    },
                    "api_version": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Секретный API-ключ; передавайте только через HTTPS в Authorization."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "request_id"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "request_id": {
                "type": "string"
              },
              "details": {
                "type": "object"
              }
            }
          }
        }
      },
      "Image": {
        "type": "object",
        "properties": {
          "id": {
            "oneOf": [
              {
                "type": "integer"
              },
              {
                "type": "string",
                "enum": [
                  "main"
                ]
              }
            ]
          },
          "path": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri",
            "description": "Для загрузки требуется тот же Bearer-ключ"
          },
          "position": {
            "type": "integer"
          },
          "available": {
            "type": "boolean"
          }
        }
      },
      "ProductCategory": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string",
            "nullable": true
          },
          "parent_id": {
            "type": "integer"
          },
          "active": {
            "type": "boolean"
          },
          "main": {
            "type": "boolean"
          }
        }
      },
      "Product": {
        "type": "object",
        "required": [
          "id",
          "model",
          "price",
          "quantity",
          "active"
        ],
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string",
            "nullable": true
          },
          "model": {
            "type": "string"
          },
          "sku": {
            "type": "string"
          },
          "manufacturer": {
            "type": "object",
            "nullable": true,
            "properties": {
              "id": {
                "type": "integer"
              },
              "name": {
                "type": "string",
                "nullable": true
              }
            }
          },
          "price": {
            "type": "string",
            "description": "Базовая цена OpenCart, десятичная строка; без расчета акций и скидок"
          },
          "currency": {
            "type": "string",
            "example": "RUB"
          },
          "quantity": {
            "type": "integer"
          },
          "active": {
            "type": "boolean"
          },
          "main_image": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Image"
              }
            ],
            "nullable": true
          },
          "categories": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ProductCategory"
            }
          },
          "date_added": {
            "type": "string",
            "description": "Дата из базы YYYY-MM-DD HH:MM:SS без преобразования часового пояса"
          },
          "date_modified": {
            "type": "string"
          }
        }
      },
      "ProductDetail": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Product"
          },
          {
            "type": "object",
            "properties": {
              "description": {
                "type": "object",
                "nullable": true,
                "properties": {
                  "header": {
                    "type": "string"
                  },
                  "short_html": {
                    "type": "string"
                  },
                  "html": {
                    "type": "string"
                  },
                  "tags": {
                    "type": "string"
                  },
                  "meta_title": {
                    "type": "string"
                  },
                  "meta_description": {
                    "type": "string"
                  },
                  "meta_keyword": {
                    "type": "string"
                  }
                }
              },
              "identifiers": {
                "type": "object",
                "properties": {
                  "upc": {
                    "type": "string"
                  },
                  "ean": {
                    "type": "string"
                  },
                  "jan": {
                    "type": "string"
                  },
                  "isbn": {
                    "type": "string"
                  },
                  "mpn": {
                    "type": "string"
                  }
                }
              },
              "location": {
                "type": "string"
              },
              "minimum_quantity": {
                "type": "integer"
              },
              "subtract_stock": {
                "type": "boolean"
              },
              "shipping": {
                "type": "boolean"
              },
              "stock_status_id": {
                "type": "integer"
              },
              "stock_status": {
                "type": "string",
                "nullable": true
              },
              "tax_class_id": {
                "type": "integer"
              },
              "date_available": {
                "type": "string"
              },
              "sort_order": {
                "type": "integer"
              },
              "viewed": {
                "type": "integer"
              },
              "weight": {
                "type": "object",
                "properties": {
                  "value": {
                    "type": "string"
                  },
                  "class_id": {
                    "type": "integer"
                  }
                }
              },
              "dimensions": {
                "type": "object",
                "properties": {
                  "length": {
                    "type": "string"
                  },
                  "width": {
                    "type": "string"
                  },
                  "height": {
                    "type": "string"
                  },
                  "class_id": {
                    "type": "integer"
                  }
                }
              },
              "images": {
                "type": "array",
                "description": "Дополнительные фото; основное находится в main_image",
                "items": {
                  "$ref": "#/components/schemas/Image"
                }
              },
              "attributes": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "integer"
                    },
                    "name": {
                      "type": "string",
                      "nullable": true
                    },
                    "value": {
                      "type": "string"
                    },
                    "group": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "integer"
                        },
                        "name": {
                          "type": "string",
                          "nullable": true
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        ]
      }
    }
  }
}