{
  "components": {
    "parameters": {},
    "schemas": {
      "CreateVersionResult": {
        "anyOf": [
          {
            "$ref": "#/components/schemas/Version"
          },
          {
            "properties": {
              "message": {
                "description": "Пояснение",
                "type": "string"
              },
              "skipped": {
                "description": "Версия не создана — значимых изменений нет",
                "enum": [
                  true
                ],
                "type": "boolean"
              }
            },
            "required": [
              "skipped",
              "message"
            ],
            "type": "object"
          }
        ],
        "description": "Созданная версия либо отметка о пропуске"
      },
      "ProblemDetails": {
        "additionalProperties": true,
        "properties": {
          "code": {
            "description": "Стабильный машиночитаемый код ошибки",
            "type": "string"
          },
          "detail": {
            "description": "Пояснение для человека",
            "type": "string"
          },
          "errors": {
            "description": "Ошибки валидации по полям",
            "items": {
              "properties": {
                "name": {
                  "description": "Имя поля",
                  "type": "string"
                },
                "pointer": {
                  "description": "JSON Pointer на поле",
                  "type": "string"
                },
                "reason": {
                  "description": "Причина",
                  "type": "string"
                },
                "rule": {
                  "description": "Нарушенное правило",
                  "type": "string"
                }
              },
              "required": [
                "reason"
              ],
              "type": "object"
            },
            "type": "array"
          },
          "instance": {
            "description": "Путь запроса, в котором возникла ошибка",
            "type": "string"
          },
          "request_id": {
            "description": "Идентификатор запроса для обращения в поддержку",
            "type": "string"
          },
          "status": {
            "description": "HTTP-статус",
            "type": "integer"
          },
          "title": {
            "description": "Краткое описание ошибки, соответствующее HTTP-статусу",
            "type": "string"
          },
          "trace_id": {
            "description": "Идентификатор трассы",
            "type": "string"
          },
          "type": {
            "description": "URI типа ошибки, ведёт на описание в документации",
            "format": "uri",
            "type": "string"
          }
        },
        "required": [
          "type",
          "title",
          "status",
          "code"
        ],
        "type": "object"
      },
      "Version": {
        "additionalProperties": true,
        "properties": {
          "comment": {
            "description": "Комментарий к версии",
            "type": [
              "string",
              "null"
            ]
          },
          "createdAt": {
            "description": "Когда создана, ISO 8601",
            "type": "string"
          },
          "createdBy": {
            "description": "Кто создал версию",
            "type": "string"
          },
          "documentId": {
            "description": "Шаблон версии",
            "type": "string"
          },
          "id": {
            "description": "Идентификатор версии",
            "type": "string"
          },
          "snapshot": {
            "description": "Снимок содержимого шаблона"
          },
          "versionNumber": {
            "description": "Порядковый номер версии",
            "type": "number"
          }
        },
        "required": [
          "id",
          "documentId",
          "versionNumber",
          "createdBy",
          "createdAt"
        ],
        "type": "object"
      }
    },
    "securitySchemes": {
      "dpop": {
        "bearerFormat": "JWT",
        "description": "Access token, привязанный к ключу клиента по RFC 9449: заголовок `Authorization: DPoP <token>` и заголовок `DPoP` с доказательством для каждого запроса. Сервер выдаёт `DPoP-Nonce`, который клиент включает в доказательство.",
        "scheme": "dpop",
        "type": "http"
      },
      "mutualTLS": {
        "description": "Access token, привязанный к клиентскому сертификату по RFC 8705: заголовок `Authorization: Bearer <token>` поверх mTLS-соединения тем же сертификатом.",
        "type": "mutualTLS"
      },
      "oauth2": {
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://app.legalstack.ru/oauth/authorize",
            "scopes": {
              "versioning:read": "Read versions",
              "versioning:write": "Manage versions"
            },
            "tokenUrl": "https://api.legalstack.ru/oauth/token"
          },
          "clientCredentials": {
            "scopes": {
              "versioning:read": "Read versions",
              "versioning:write": "Manage versions"
            },
            "tokenUrl": "https://api.legalstack.ru/oauth/token"
          }
        },
        "type": "oauth2"
      }
    }
  },
  "info": {
    "title": "LegalStack Versioning API",
    "version": "1.0.0"
  },
  "openapi": "3.1.0",
  "paths": {
    "/versions": {
      "get": {
        "operationId": "get_versions",
        "parameters": [
          {
            "description": "Шаблон, версии которого запрашиваются",
            "in": "query",
            "name": "documentId",
            "required": true,
            "schema": {
              "description": "Шаблон, версии которого запрашиваются",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "items": {
                    "$ref": "#/components/schemas/Version"
                  },
                  "type": "array"
                }
              }
            },
            "description": "Версии шаблона, новые первыми"
          },
          "400": {
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Некорректный запрос: не прошла валидация параметров или тела"
          },
          "401": {
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Токен отсутствует, недействителен или истёк"
          },
          "403": {
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Недостаточно прав или scope"
          }
        },
        "security": [
          {
            "dpop": []
          }
        ],
        "summary": "Список версий шаблона",
        "tags": [
          "versioning"
        ]
      },
      "post": {
        "operationId": "post_versions",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "properties": {
                  "comment": {
                    "description": "Комментарий к версии",
                    "type": "string"
                  },
                  "documentId": {
                    "description": "Шаблон, для которого создаётся версия",
                    "minLength": 1,
                    "type": "string"
                  },
                  "force": {
                    "description": "Создать версию даже без значимых изменений",
                    "type": "boolean"
                  },
                  "snapshot": {
                    "description": "Снимок содержимого шаблона",
                    "properties": {
                      "blocks": {
                        "description": "Блоки шаблона на момент снимка",
                        "items": {
                          "properties": {
                            "depth": {
                              "description": "Уровень вложенности",
                              "type": "number"
                            },
                            "id": {
                              "description": "Идентификатор блока",
                              "type": "string"
                            },
                            "label": {
                              "description": "Подпись блока",
                              "type": "string"
                            },
                            "order": {
                              "description": "Позиция блока в шаблоне",
                              "type": "number"
                            },
                            "renderAs": {
                              "description": "Способ отображения блока",
                              "type": "string"
                            },
                            "template": {
                              "description": "Шаблон текста блока",
                              "type": "string"
                            },
                            "type": {
                              "description": "Тип блока",
                              "type": "string"
                            },
                            "variables": {
                              "additionalProperties": true,
                              "description": "Значения переменных блока",
                              "type": "object"
                            }
                          },
                          "required": [
                            "id",
                            "type",
                            "label",
                            "order",
                            "depth",
                            "template",
                            "variables"
                          ],
                          "type": "object"
                        },
                        "type": "array"
                      },
                      "status": {
                        "description": "Статус шаблона на момент снимка",
                        "type": "string"
                      },
                      "title": {
                        "description": "Название шаблона на момент снимка",
                        "type": "string"
                      }
                    },
                    "required": [
                      "title",
                      "status",
                      "blocks"
                    ],
                    "type": "object"
                  }
                },
                "required": [
                  "documentId",
                  "snapshot"
                ],
                "type": "object"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateVersionResult"
                }
              }
            },
            "description": "Версия создана или пропущена (нет значимых изменений)"
          },
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Version"
                }
              }
            },
            "description": "Версия создана принудительно"
          },
          "400": {
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Некорректный запрос: не прошла валидация параметров или тела"
          },
          "401": {
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Токен отсутствует, недействителен или истёк"
          },
          "403": {
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Недостаточно прав или scope"
          }
        },
        "security": [
          {
            "dpop": []
          }
        ],
        "summary": "Создать версию шаблона",
        "tags": [
          "versioning"
        ]
      }
    },
    "/versions/document/{documentId}/number/{number}": {
      "get": {
        "operationId": "get_versions_document_documentId_number_number",
        "parameters": [
          {
            "description": "Идентификатор шаблона",
            "in": "path",
            "name": "documentId",
            "required": true,
            "schema": {
              "description": "Идентификатор шаблона",
              "type": "string"
            }
          },
          {
            "description": "Порядковый номер версии (с 1)",
            "in": "path",
            "name": "number",
            "required": true,
            "schema": {
              "description": "Порядковый номер версии (с 1)",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Version"
                }
              }
            },
            "description": "Версия шаблона"
          },
          "400": {
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Некорректный запрос: не прошла валидация параметров или тела"
          },
          "401": {
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Токен отсутствует, недействителен или истёк"
          },
          "403": {
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Недостаточно прав или scope"
          },
          "404": {
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Ресурс не найден"
          }
        },
        "security": [
          {
            "dpop": []
          }
        ],
        "summary": "Получить версию по ID шаблона и номеру",
        "tags": [
          "versioning"
        ]
      }
    },
    "/versions/{id}": {
      "get": {
        "operationId": "get_versions_id",
        "parameters": [
          {
            "description": "Идентификатор версии",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "description": "Идентификатор версии",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Version"
                }
              }
            },
            "description": "Версия шаблона"
          },
          "400": {
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Некорректный запрос: не прошла валидация параметров или тела"
          },
          "401": {
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Токен отсутствует, недействителен или истёк"
          },
          "403": {
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Недостаточно прав или scope"
          },
          "404": {
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            },
            "description": "Ресурс не найден"
          }
        },
        "security": [
          {
            "dpop": []
          }
        ],
        "summary": "Получить версию по ID",
        "tags": [
          "versioning"
        ]
      }
    }
  },
  "servers": [
    {
      "description": "Публичный API LegalStack",
      "url": "https://api.legalstack.ru"
    }
  ],
  "tags": [
    {
      "description": "Версии шаблонов и снимки состояния.",
      "name": "versioning",
      "x-displayName": "Версии и снимки"
    }
  ],
  "webhooks": {}
}
