{
  "openapi": "3.0.1",
  "info": {
    "title": "Документация по SelSup API",
    "description": "API SelSup — программный интерфейс для работы с сервисом SelSup. Даёт возможность работать со всеми функциями SelSup из вашей системы. Для использования API добавьте новый токен на странице:https://selsup.ru/application/integration/api. Добавленный токен необходимо передавать во всех запросах к API SelSup, в заголовке Authorization.",
    "contact": {
      "name": "Support Team",
      "email": "admin@selsup.ru"
    },
    "license": {
      "name": "Apache 2.0",
      "url": "https://selsup.ru/dogovor-offerta/"
    },
    "version": "1.0"
  },
  "servers": [
    {
      "url": "https://api.selsup.ru/",
      "description": "Production server"
    }
  ],
  "tags": [
    {
      "name": "Метки товаров",
      "description": "Методы для создания/получения/добавления/удаления тегов товарамподдерживается пагинация и сортировка"
    }
  ],
  "paths": {
    "/api/tag/{tagId}": {
      "put": {
        "tags": [
          "Метки товаров"
        ],
        "summary": "Обновление тэга товара",
        "description": "Изменяет имя существующего тэга по его идентификатору.",
        "operationId": "updateTag",
        "parameters": [
          {
            "name": "tagId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProductTag"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/hal+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProductTag"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Метки товаров"
        ],
        "summary": "Удаление тэга товара",
        "description": "Удаляет тэг по идентификатору. Тэг отвязывается от всех товаров.",
        "operationId": "updateTag_1",
        "parameters": [
          {
            "name": "tagId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/api/tag/product/{tagId}/{productId}": {
      "put": {
        "tags": [
          "Метки товаров"
        ],
        "summary": "Привязать тэг к продукту",
        "description": "Привязывает указанный тэг к продукту по их идентификаторам.",
        "operationId": "bindTagToProduct",
        "parameters": [
          {
            "name": "tagId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          },
          {
            "name": "productId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "delete": {
        "tags": [
          "Метки товаров"
        ],
        "summary": "Отвязать тэг от продукта",
        "description": "Удаляет связь между тэгом и продуктом по их идентификаторам.",
        "operationId": "unBindTagToProduct",
        "parameters": [
          {
            "name": "tagId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          },
          {
            "name": "productId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/api/tag/model/{tagId}/{modelId}": {
      "put": {
        "tags": [
          "Метки товаров"
        ],
        "summary": "Привязать тэг ко всем товарам модели",
        "description": "Привязывает указанный тэг ко всем продуктам модели.",
        "operationId": "bindTagToModel",
        "parameters": [
          {
            "name": "tagId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          },
          {
            "name": "modelId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      },
      "delete": {
        "tags": [
          "Метки товаров"
        ],
        "summary": "Отвязать тэг от всех товаров модели",
        "description": "Удаляет связь между тэгом и всеми продуктами  модели.",
        "operationId": "unBindTagToModel",
        "parameters": [
          {
            "name": "tagId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          },
          {
            "name": "modelId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/api/tag": {
      "post": {
        "tags": [
          "Метки товаров"
        ],
        "summary": "Создание тэга товара",
        "description": "Создаёт новый тэг для товаров клиента. Имя тэга должно быть уникальным в рамках клиента.",
        "operationId": "createTag",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProductTag"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/hal+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProductTag"
                }
              }
            }
          }
        }
      }
    },
    "/api/tag/find": {
      "get": {
        "tags": [
          "Метки товаров"
        ],
        "summary": "Поиск и фильтрация тегов",
        "description": "Возвращает список тегов с поддержкой фильтрации, сортировки и пагинации.",
        "operationId": "findTags",
        "parameters": [
          {
            "name": "query",
            "in": "query",
            "description": "Запрос на поиск тега",
            "required": false,
            "schema": {
              "type": "string",
              "description": "Запрос на поиск тега"
            }
          },
          {
            "name": "productId",
            "in": "query",
            "description": "Идентификатор продукта",
            "required": false,
            "schema": {
              "type": "integer",
              "description": "Идентификатор продукта",
              "format": "int64"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Ограничение на количество записей. Максимальное значение - 500",
            "required": false,
            "schema": {
              "type": "integer",
              "description": "Ограничение на количество записей. Максимальное значение - 500",
              "format": "int32"
            }
          },
          {
            "name": "page",
            "in": "query",
            "description": "Номер страницы начиная с 1",
            "required": false,
            "schema": {
              "type": "integer",
              "description": "Номер страницы начиная с 1",
              "format": "int32"
            }
          },
          {
            "name": "count",
            "in": "query",
            "description": "Возвратить в ответе общее количество записей",
            "required": false,
            "schema": {
              "type": "boolean",
              "description": "Возвратить в ответе общее количество записей"
            }
          },
          {
            "name": "sortBy",
            "in": "query",
            "description": "Поле для сортировки",
            "required": false,
            "schema": {
              "type": "string",
              "description": "Поле для сортировки",
              "enum": [
                "ID",
                "NAME"
              ]
            }
          },
          {
            "name": "ascending",
            "in": "query",
            "description": "Порядок сортировки - по возрастанию?. Работает только при получении списка.",
            "required": false,
            "schema": {
              "type": "boolean",
              "description": "Порядок сортировки - по возрастанию?. Работает только при получении списка."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/hal+json": {
                "schema": {
                  "$ref": "#/components/schemas/FindResponseProductTag"
                }
              }
            }
          }
        }
      }
    },
    "/api/tag/find/{modelId}": {
      "get": {
        "tags": [
          "Метки товаров"
        ],
        "summary": "Получить теги товаров по id модели",
        "description": "Возвращает список объектов,в которых сопоставляются id продукта и  его теги",
        "operationId": "findModelTags",
        "parameters": [
          {
            "name": "modelId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/hal+json": {
                "schema": {
                  "$ref": "#/components/schemas/FindResponseProductTagInfo"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ProductTag": {
        "required": [
          "name"
        ],
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "description": "Идентификатор метки",
            "format": "int64",
            "readOnly": true
          },
          "name": {
            "type": "string",
            "description": "Название метки"
          },
          "clientId": {
            "type": "integer",
            "description": "Идентификатор клиента",
            "format": "int64",
            "readOnly": true
          }
        },
        "description": "Метка для товара"
      },
      "FindResponseProductTag": {
        "type": "object",
        "properties": {
          "rows": {
            "type": "array",
            "description": "Строки с результатом поиска",
            "items": {
              "$ref": "#/components/schemas/ProductTag"
            }
          },
          "total": {
            "type": "integer",
            "description": "Общее количество найденных записей. Возвращается только, когда count = true",
            "format": "int32"
          },
          "page": {
            "type": "integer",
            "description": "Номер запрошенной страницы",
            "format": "int32"
          },
          "hasNextPage": {
            "type": "boolean",
            "description": "Есть ли следующая страница"
          },
          "emptyPurchase": {
            "type": "integer",
            "description": "Показатель пустой закупочной цены",
            "format": "int64"
          }
        }
      },
      "FindResponseProductTagInfo": {
        "type": "object",
        "properties": {
          "rows": {
            "type": "array",
            "description": "Строки с результатом поиска",
            "items": {
              "$ref": "#/components/schemas/ProductTagInfo"
            }
          },
          "total": {
            "type": "integer",
            "description": "Общее количество найденных записей. Возвращается только, когда count = true",
            "format": "int32"
          },
          "page": {
            "type": "integer",
            "description": "Номер запрошенной страницы",
            "format": "int32"
          },
          "hasNextPage": {
            "type": "boolean",
            "description": "Есть ли следующая страница"
          },
          "emptyPurchase": {
            "type": "integer",
            "description": "Показатель пустой закупочной цены",
            "format": "int64"
          }
        }
      },
      "ProductTagInfo": {
        "type": "object",
        "properties": {
          "productId": {
            "type": "integer",
            "format": "int64"
          },
          "productTags": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ProductTag"
            }
          }
        },
        "description": "Строки с результатом поиска"
      }
    },
    "securitySchemes": {
      "ApiKey": {
        "type": "apiKey",
        "name": "Authorization",
        "in": "header"
      }
    }
  }
}