{
  "openapi": "3.0.3",
  "info": {
    "title": "TechInspect Partner API",
    "version": "v1",
    "description": "REST JSON API кабинета TechInspect. Живой транспорт — /api/partner/v1. SOAP-сервиса нет. Готового коннектора 1С нет. Ключ кабинета: заголовок X-Api-Key или Authorization: Bearer, префикс ti_live_… Примеры синтетические."
  },
  "servers": [
    {
      "url": "https://tech-inspect.ru",
      "description": "Production"
    }
  ],
  "tags": [
    {
      "name": "health"
    },
    {
      "name": "me"
    },
    {
      "name": "catalog"
    },
    {
      "name": "units"
    },
    {
      "name": "inspections"
    },
    {
      "name": "calendar"
    }
  ],
  "security": [
    {
      "apiKey": []
    },
    {
      "bearer": []
    }
  ],
  "paths": {
    "/api/partner/v1/health": {
      "get": {
        "tags": [
          "health"
        ],
        "summary": "Проверка без ключа",
        "security": [],
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                },
                "example": {
                  "ok": true,
                  "name": "techinspect-partner"
                }
              }
            }
          }
        }
      }
    },
    "/api/partner/v1/me": {
      "get": {
        "tags": [
          "me"
        ],
        "summary": "Кабинет и маска ключа",
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Me"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/partner/v1/owners": {
      "get": {
        "tags": [
          "catalog"
        ],
        "summary": "Владельцы",
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OwnerList"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/partner/v1/equipment-brands": {
      "get": {
        "tags": [
          "catalog"
        ],
        "summary": "Справочник марок",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BrandList"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/partner/v1/unit-kinds": {
      "get": {
        "tags": [
          "catalog"
        ],
        "summary": "Типы техники",
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnitKindGroups"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/partner/v1/inspectors": {
      "get": {
        "tags": [
          "catalog"
        ],
        "summary": "Инспекторы без email",
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InspectorList"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/partner/v1/templates": {
      "get": {
        "tags": [
          "catalog"
        ],
        "summary": "Опубликованные шаблоны",
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TemplateList"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/partner/v1/units": {
      "get": {
        "tags": [
          "units"
        ],
        "summary": "Список техники без VIN",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnitList"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "tags": [
          "units"
        ],
        "summary": "Создать единицу",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UnitIn"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnitDetail"
                }
              }
            }
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/partner/v1/units/{uid}": {
      "get": {
        "tags": [
          "units"
        ],
        "summary": "Карточка с VIN",
        "parameters": [
          {
            "name": "uid",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnitDetail"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/partner/v1/inspections": {
      "get": {
        "tags": [
          "inspections"
        ],
        "summary": "Список без VIN и без ответов",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "assigned",
                "in_progress",
                "completed"
              ]
            }
          },
          {
            "name": "date_from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "date_to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InspectionList"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "tags": [
          "inspections"
        ],
        "summary": "Назначить инспекцию",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InspectionIn"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InspectionListItem"
                }
              }
            }
          },
          "422": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/partner/v1/inspections/{iid}": {
      "get": {
        "tags": [
          "inspections"
        ],
        "summary": "Выгрузка: ответы без фото и PDF",
        "parameters": [
          {
            "name": "iid",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InspectionExport"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/partner/v1/inspections/{iid}/schedule": {
      "patch": {
        "tags": [
          "inspections"
        ],
        "summary": "Перенести план, только статус assigned",
        "parameters": [
          {
            "name": "iid",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ScheduleIn"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InspectionListItem"
                }
              }
            }
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/partner/v1/inspections/{iid}/cancel": {
      "post": {
        "tags": [
          "inspections"
        ],
        "summary": "Отмена: удаление строки, 204. Завершённую нельзя.",
        "parameters": [
          {
            "name": "iid",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "deleted"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/partner/v1/calendar": {
      "get": {
        "tags": [
          "calendar"
        ],
        "summary": "Сетка плана без VIN",
        "parameters": [
          {
            "name": "view",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "day",
                "week",
                "month"
              ]
            }
          },
          {
            "name": "date",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Calendar"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Api-Key",
        "description": "ti_live_…"
      },
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "Bearer ti_live_…"
      }
    },
    "responses": {
      "Error": {
        "description": "Ошибка",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorBody"
            }
          }
        }
      }
    },
    "schemas": {
      "Health": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "name": {
            "type": "string"
          }
        },
        "required": [
          "ok",
          "name"
        ]
      },
      "ErrorBody": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "example": "auth"
              },
              "message": {
                "type": "string"
              },
              "missing": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "required": [
              "code",
              "message"
            ]
          }
        },
        "required": [
          "error"
        ]
      },
      "Me": {
        "type": "object",
        "properties": {
          "api": {
            "type": "string",
            "example": "partner"
          },
          "version": {
            "type": "string",
            "example": "v1"
          },
          "organization": {
            "type": "object",
            "properties": {
              "id": {
                "type": "integer",
                "example": 1
              },
              "name": {
                "type": "string",
                "example": "ООО Демо"
              },
              "short_name": {
                "type": "string"
              }
            }
          },
          "key": {
            "type": "object",
            "properties": {
              "id": {
                "type": "integer"
              },
              "name": {
                "type": "string",
                "example": "Интеграция склада"
              },
              "prefix": {
                "type": "string",
                "example": "ti_live_"
              },
              "last4": {
                "type": "string",
                "example": "ab12"
              }
            }
          }
        }
      },
      "OwnerList": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "integer"
                },
                "name": {
                  "type": "string",
                  "example": "ООО Демо"
                }
              }
            }
          }
        }
      },
      "BrandList": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "integer"
                },
                "name": {
                  "type": "string",
                  "example": "Caterpillar"
                }
              }
            }
          }
        }
      },
      "UnitKindGroups": {
        "type": "object",
        "additionalProperties": true
      },
      "InspectorList": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "integer"
                },
                "full_name": {
                  "type": "string",
                  "example": "Иван Инспекторов"
                },
                "role": {
                  "type": "string"
                },
                "role_label": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "TemplateList": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "integer"
                },
                "name": {
                  "type": "string",
                  "example": "S·O·S — масло"
                },
                "inspection_kind": {
                  "type": "string"
                },
                "code": {
                  "type": "string",
                  "example": "sos-oil"
                }
              }
            }
          }
        }
      },
      "UnitIn": {
        "type": "object",
        "required": [
          "vin",
          "brand_id",
          "owner_id"
        ],
        "properties": {
          "vin": {
            "type": "string",
            "example": "TESTVIN0000000001"
          },
          "brand_id": {
            "type": "integer"
          },
          "owner_id": {
            "type": "integer"
          },
          "model": {
            "type": "string"
          },
          "unit_kind": {
            "type": "string"
          },
          "plate": {
            "type": "string"
          },
          "year": {
            "type": "integer",
            "example": 2020
          }
        }
      },
      "UnitListItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "fleet_no": {
            "type": "integer",
            "nullable": true
          },
          "unit_kind": {
            "type": "string"
          },
          "kind_label": {
            "type": "string"
          },
          "brand": {
            "type": "string",
            "example": "Caterpillar"
          },
          "brand_id": {
            "type": "integer",
            "nullable": true
          },
          "model": {
            "type": "string"
          },
          "plate": {
            "type": "string"
          },
          "year": {
            "type": "integer",
            "nullable": true
          },
          "owner_id": {
            "type": "integer"
          },
          "owner_name": {
            "type": "string",
            "example": "ООО Демо"
          },
          "status": {
            "type": "string"
          }
        }
      },
      "UnitDetail": {
        "allOf": [
          {
            "$ref": "#/components/schemas/UnitListItem"
          },
          {
            "type": "object",
            "properties": {
              "vin": {
                "type": "string",
                "example": "TESTVIN0000000001"
              }
            }
          }
        ]
      },
      "UnitList": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/UnitListItem"
            }
          }
        }
      },
      "InspectionIn": {
        "type": "object",
        "required": [
          "unit_id",
          "template_id",
          "inspector_id",
          "scheduled_date"
        ],
        "properties": {
          "unit_id": {
            "type": "integer"
          },
          "template_id": {
            "type": "integer"
          },
          "inspector_id": {
            "type": "integer"
          },
          "scheduled_date": {
            "type": "string",
            "format": "date",
            "example": "2026-10-14"
          },
          "scheduled_time": {
            "type": "string",
            "nullable": true,
            "example": "14:00",
            "description": "Пустое время не равно 00:00"
          },
          "scheduled_end_time": {
            "type": "string",
            "nullable": true,
            "example": "16:00",
            "description": "Конец плана в тот же день. Пусто — только начало"
          }
        }
      },
      "ScheduleIn": {
        "type": "object",
        "required": [
          "scheduled_date"
        ],
        "properties": {
          "scheduled_date": {
            "type": "string",
            "format": "date"
          },
          "scheduled_time": {
            "type": "string",
            "nullable": true,
            "example": "14:00"
          },
          "scheduled_end_time": {
            "type": "string",
            "nullable": true,
            "example": "16:00"
          }
        }
      },
      "InspectionListItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "example": 1001
          },
          "status": {
            "type": "string",
            "example": "assigned"
          },
          "status_label": {
            "type": "string"
          },
          "condition": {
            "type": "string"
          },
          "condition_label": {
            "type": "string"
          },
          "score": {
            "type": "integer",
            "nullable": true
          },
          "scheduled_date": {
            "type": "string",
            "example": "2026-10-14"
          },
          "scheduled_time": {
            "type": "string",
            "nullable": true,
            "example": "14:00"
          },
          "scheduled_end_time": {
            "type": "string",
            "nullable": true,
            "example": "16:00"
          },
          "started_at": {
            "type": "string",
            "nullable": true
          },
          "completed_at": {
            "type": "string",
            "nullable": true
          },
          "template": {
            "type": "object",
            "nullable": true,
            "properties": {
              "id": {
                "type": "integer"
              },
              "name": {
                "type": "string"
              }
            }
          },
          "unit": {
            "type": "object",
            "nullable": true
          },
          "owner_name": {
            "type": "string",
            "example": "ООО Демо"
          },
          "inspector": {
            "type": "object",
            "nullable": true,
            "properties": {
              "id": {
                "type": "integer"
              },
              "full_name": {
                "type": "string",
                "example": "Иван Инспекторов"
              }
            }
          }
        }
      },
      "InspectionList": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/InspectionListItem"
            }
          }
        }
      },
      "InspectionValue": {
        "type": "object",
        "properties": {
          "field_id": {
            "type": "integer"
          },
          "label": {
            "type": "string"
          },
          "field_type": {
            "type": "string"
          },
          "value_text": {
            "type": "string"
          },
          "value_number": {
            "type": "number",
            "nullable": true
          },
          "comment": {
            "type": "string"
          },
          "auto_status": {
            "type": "string",
            "nullable": true
          },
          "auto_score": {
            "type": "integer",
            "nullable": true
          },
          "inspector_status": {
            "type": "string",
            "nullable": true
          },
          "inspector_score": {
            "type": "integer",
            "nullable": true
          },
          "is_overridden": {
            "type": "boolean"
          }
        }
      },
      "InspectionExport": {
        "allOf": [
          {
            "$ref": "#/components/schemas/InspectionListItem"
          },
          {
            "type": "object",
            "properties": {
              "values": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/InspectionValue"
                }
              },
              "photos_count": {
                "type": "integer",
                "example": 0
              },
              "scoring": {
                "type": "object"
              }
            }
          }
        ]
      },
      "CalendarEvent": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "scheduled_date": {
            "type": "string",
            "nullable": true
          },
          "scheduled_time": {
            "type": "string",
            "nullable": true
          },
          "scheduled_end_time": {
            "type": "string",
            "nullable": true
          },
          "status": {
            "type": "string"
          },
          "status_label": {
            "type": "string"
          },
          "overdue": {
            "type": "boolean"
          },
          "label": {
            "type": "string",
            "example": "№ 12 · Caterpillar 320"
          },
          "template_name": {
            "type": "string"
          },
          "condition": {
            "type": "string"
          },
          "condition_label": {
            "type": "string"
          }
        }
      },
      "Calendar": {
        "type": "object",
        "additionalProperties": true,
        "properties": {
          "view": {
            "type": "string"
          },
          "date": {
            "type": "string"
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CalendarEvent"
            }
          }
        }
      }
    }
  }
}
