{
  "components": {
    "parameters": {},
    "schemas": {
      "ProblemDetails": {
        "description": "Ошибка в формате Problem Details (RFC 9457)",
        "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": "Краткое описание",
            "type": "string"
          },
          "trace_id": {
            "description": "Идентификатор трассы",
            "type": "string"
          },
          "type": {
            "description": "URI типа ошибки, ведёт на описание в документации",
            "format": "uri",
            "type": "string"
          }
        },
        "required": [
          "type",
          "title",
          "status",
          "code"
        ],
        "type": "object"
      },
      "SystemField": {
        "additionalProperties": true,
        "properties": {
          "cardinality": {
            "description": "Кратность: one или many",
            "type": "string"
          },
          "dataType": {
            "description": "Тип данных поля",
            "type": "string"
          },
          "defaultValue": {
            "description": "Значение по умолчанию"
          },
          "description": {
            "description": "Описание поля",
            "type": [
              "string",
              "null"
            ]
          },
          "id": {
            "description": "Идентификатор поля",
            "type": "string"
          },
          "key": {
            "description": "Машинный ключ поля",
            "type": "string"
          },
          "name": {
            "description": "Название поля",
            "type": "string"
          },
          "options": {
            "description": "Настройки значений"
          },
          "ordinal": {
            "description": "Порядок поля",
            "type": "number"
          },
          "refTypeId": {
            "description": "Для reference: целевой тип",
            "type": [
              "string",
              "null"
            ]
          },
          "required": {
            "description": "Обязательность заполнения",
            "type": "boolean"
          },
          "typeId": {
            "description": "Тип, которому принадлежит поле",
            "type": "string"
          },
          "validation": {
            "description": "Правила валидации"
          }
        },
        "required": [
          "id",
          "typeId",
          "key",
          "name",
          "dataType",
          "cardinality",
          "ordinal",
          "required"
        ],
        "type": "object"
      },
      "SystemRegistryTemplate": {
        "allOf": [
          {
            "$ref": "#/components/schemas/SystemTemplate"
          },
          {
            "additionalProperties": true,
            "properties": {
              "fields": {
                "description": "Колонки реестра по порядку",
                "items": {
                  "additionalProperties": true,
                  "properties": {
                    "dataType": {
                      "description": "Тип колонки",
                      "type": "string"
                    },
                    "key": {
                      "description": "Машинный ключ колонки",
                      "type": "string"
                    },
                    "name": {
                      "description": "Название колонки",
                      "type": "string"
                    }
                  },
                  "required": [
                    "key",
                    "name",
                    "dataType"
                  ],
                  "type": "object"
                },
                "type": "array"
              }
            },
            "required": [
              "fields"
            ],
            "type": "object"
          }
        ]
      },
      "SystemTemplate": {
        "additionalProperties": true,
        "properties": {
          "builtIn": {
            "description": "Системный шаблон (true)",
            "type": "boolean"
          },
          "description": {
            "description": "Описание шаблона",
            "type": [
              "string",
              "null"
            ]
          },
          "id": {
            "description": "Идентификатор шаблона",
            "type": "string"
          },
          "key": {
            "description": "Машинный ключ шаблона",
            "type": "string"
          },
          "kind": {
            "description": "Тип: document",
            "type": "string"
          },
          "name": {
            "description": "Название шаблона",
            "type": "string"
          }
        },
        "required": [
          "id",
          "kind",
          "key",
          "name",
          "builtIn"
        ],
        "type": "object"
      },
      "SystemType": {
        "additionalProperties": true,
        "properties": {
          "builtIn": {
            "description": "Системный тип (true)",
            "type": "boolean"
          },
          "description": {
            "description": "Описание типа",
            "type": [
              "string",
              "null"
            ]
          },
          "icon": {
            "description": "Иконка типа",
            "type": [
              "string",
              "null"
            ]
          },
          "id": {
            "description": "Идентификатор типа",
            "type": "string"
          },
          "key": {
            "description": "Машинный ключ",
            "type": "string"
          },
          "kind": {
            "description": "Вид типа, например document",
            "type": "string"
          },
          "name": {
            "description": "Название типа",
            "type": "string"
          },
          "templates": {
            "description": "Настройки шаблона"
          }
        },
        "required": [
          "id",
          "kind",
          "key",
          "name",
          "builtIn"
        ],
        "type": "object"
      },
      "SystemTypeWithFields": {
        "properties": {
          "fields": {
            "description": "Поля типа по порядку",
            "items": {
              "$ref": "#/components/schemas/SystemField"
            },
            "type": "array"
          },
          "type": {
            "$ref": "#/components/schemas/SystemType"
          }
        },
        "required": [
          "type",
          "fields"
        ],
        "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": {
              "admin:read": "Read system catalog (types/fields)",
              "admin:write": "Edit system catalog (types/fields)"
            },
            "tokenUrl": "https://api.legalstack.ru/oauth/token"
          },
          "clientCredentials": {
            "scopes": {
              "admin:read": "Read system catalog (types/fields)",
              "admin:write": "Edit system catalog (types/fields)"
            },
            "tokenUrl": "https://api.legalstack.ru/oauth/token"
          }
        },
        "type": "oauth2"
      }
    }
  },
  "info": {
    "title": "LegalStack Templates API",
    "version": "1.0.0"
  },
  "openapi": "3.1.0",
  "paths": {
    "/api/v1/templates/fields/{fieldId}": {
      "delete": {
        "operationId": "delete_api_v1_templates_fields_fieldId",
        "parameters": [
          {
            "description": "Идентификатор системного поля",
            "in": "path",
            "name": "fieldId",
            "required": true,
            "schema": {
              "description": "Идентификатор системного поля",
              "format": "uuid",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SystemField"
                }
              }
            },
            "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": []
          },
          {
            "oauth2": [
              "admin:write"
            ]
          }
        ],
        "summary": "Удалить системное поле",
        "tags": [
          "templates"
        ]
      },
      "patch": {
        "operationId": "patch_api_v1_templates_fields_fieldId",
        "parameters": [
          {
            "description": "Идентификатор системного поля",
            "in": "path",
            "name": "fieldId",
            "required": true,
            "schema": {
              "description": "Идентификатор системного поля",
              "format": "uuid",
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "properties": {
                  "cardinality": {
                    "description": "Кратность: одно значение или список",
                    "enum": [
                      "one",
                      "many"
                    ],
                    "type": "string"
                  },
                  "defaultValue": {
                    "description": "Значение по умолчанию"
                  },
                  "description": {
                    "description": "Новое описание",
                    "maxLength": 2048,
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "key": {
                    "description": "Новый машинный ключ",
                    "maxLength": 128,
                    "minLength": 1,
                    "pattern": "^[a-z][a-z0-9_]*$",
                    "type": "string"
                  },
                  "name": {
                    "description": "Новое название",
                    "maxLength": 256,
                    "minLength": 1,
                    "type": "string"
                  },
                  "options": {
                    "additionalProperties": true,
                    "description": "Настройки значений; items — только добавление",
                    "properties": {
                      "__deprecated": {
                        "description": "Значения, скрытые для новых блоков",
                        "items": {
                          "type": "string"
                        },
                        "type": "array"
                      },
                      "colors": {
                        "additionalProperties": {
                          "type": "string",
                          "x-additionalPropertiesName": "value"
                        },
                        "description": "Цвета значений",
                        "type": "object"
                      },
                      "groups": {
                        "additionalProperties": {
                          "items": {
                            "type": "string"
                          },
                          "type": "array",
                          "x-additionalPropertiesName": "group"
                        },
                        "description": "Группировка значений",
                        "type": "object"
                      },
                      "items": {
                        "description": "Допустимые значения enum/status",
                        "items": {
                          "type": "string"
                        },
                        "type": "array"
                      },
                      "labels": {
                        "additionalProperties": {
                          "type": "string",
                          "x-additionalPropertiesName": "value"
                        },
                        "description": "Подписи значений",
                        "type": "object"
                      }
                    },
                    "type": [
                      "object",
                      "null"
                    ]
                  },
                  "ordinal": {
                    "description": "Новый порядок",
                    "minimum": 0,
                    "type": "integer"
                  },
                  "refTypeId": {
                    "description": "Для reference: тип, на который ссылается поле",
                    "format": "uuid",
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "required": {
                    "description": "Обязательность заполнения",
                    "type": "boolean"
                  },
                  "validation": {
                    "additionalProperties": true,
                    "description": "Правила валидации",
                    "type": [
                      "object",
                      "null"
                    ]
                  }
                },
                "type": "object"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SystemField"
                }
              }
            },
            "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": []
          },
          {
            "oauth2": [
              "admin:write"
            ]
          }
        ],
        "summary": "Обновить системное поле (в options.items значения можно только добавлять)",
        "tags": [
          "templates"
        ]
      }
    },
    "/api/v1/templates/fields/{fieldId}/options/deprecate": {
      "post": {
        "operationId": "post_api_v1_templates_fields_fieldId_options_deprecate",
        "parameters": [
          {
            "description": "Идентификатор системного поля",
            "in": "path",
            "name": "fieldId",
            "required": true,
            "schema": {
              "description": "Идентификатор системного поля",
              "format": "uuid",
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "properties": {
                  "items": {
                    "description": "Значения options.items для скрытия у новых блоков",
                    "items": {
                      "minLength": 1,
                      "type": "string"
                    },
                    "minItems": 1,
                    "type": "array"
                  }
                },
                "required": [
                  "items"
                ],
                "type": "object"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SystemField"
                }
              }
            },
            "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": []
          },
          {
            "oauth2": [
              "admin:write"
            ]
          }
        ],
        "summary": "Пометить значения списка устаревшими (новые блоки их не видят, существующие показывают подпись)",
        "tags": [
          "templates"
        ]
      }
    },
    "/api/v1/templates/system/documents": {
      "get": {
        "operationId": "get_api_v1_templates_system_documents",
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "items": {
                    "$ref": "#/components/schemas/SystemTemplate"
                  },
                  "type": "array"
                }
              }
            },
            "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": [
          "system-templates"
        ]
      }
    },
    "/api/v1/templates/system/registries": {
      "get": {
        "operationId": "get_api_v1_templates_system_registries",
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "items": {
                    "$ref": "#/components/schemas/SystemRegistryTemplate"
                  },
                  "type": "array"
                }
              }
            },
            "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": [
          "system-templates"
        ]
      }
    },
    "/api/v1/templates/types": {
      "get": {
        "operationId": "get_api_v1_templates_types",
        "parameters": [
          {
            "description": "Фильтр по виду типа, например document",
            "in": "query",
            "name": "kind",
            "required": false,
            "schema": {
              "description": "Фильтр по виду типа, например document",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "items": {
                    "$ref": "#/components/schemas/SystemType"
                  },
                  "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": []
          },
          {
            "oauth2": [
              "admin:read"
            ]
          }
        ],
        "summary": "Список системных типов (built_in=true)",
        "tags": [
          "templates"
        ]
      },
      "post": {
        "operationId": "post_api_v1_templates_types",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "properties": {
                  "description": {
                    "description": "Описание типа",
                    "maxLength": 2048,
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "icon": {
                    "description": "Иконка типа",
                    "maxLength": 64,
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "key": {
                    "description": "Машинный ключ: латиница, цифры, подчёркивание",
                    "maxLength": 128,
                    "minLength": 1,
                    "pattern": "^[a-z][a-z0-9_]*$",
                    "type": "string"
                  },
                  "kind": {
                    "description": "Вид системного типа, например document",
                    "maxLength": 64,
                    "minLength": 1,
                    "type": "string"
                  },
                  "name": {
                    "description": "Название типа",
                    "maxLength": 256,
                    "minLength": 1,
                    "type": "string"
                  },
                  "templates": {
                    "additionalProperties": true,
                    "description": "Настройки шаблона; для kind=document — структура DocumentTemplates",
                    "type": [
                      "object",
                      "null"
                    ]
                  }
                },
                "required": [
                  "kind",
                  "key",
                  "name"
                ],
                "type": "object"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SystemType"
                }
              }
            },
            "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": []
          },
          {
            "oauth2": [
              "admin:write"
            ]
          }
        ],
        "summary": "Создать системный тип",
        "tags": [
          "templates"
        ]
      }
    },
    "/api/v1/templates/types/{typeId}": {
      "delete": {
        "operationId": "delete_api_v1_templates_types_typeId",
        "parameters": [
          {
            "description": "Идентификатор системного типа",
            "in": "path",
            "name": "typeId",
            "required": true,
            "schema": {
              "description": "Идентификатор системного типа",
              "format": "uuid",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SystemType"
                }
              }
            },
            "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": []
          },
          {
            "oauth2": [
              "admin:write"
            ]
          }
        ],
        "summary": "Удалить системный тип",
        "tags": [
          "templates"
        ]
      },
      "get": {
        "operationId": "get_api_v1_templates_types_typeId",
        "parameters": [
          {
            "description": "Идентификатор системного типа",
            "in": "path",
            "name": "typeId",
            "required": true,
            "schema": {
              "description": "Идентификатор системного типа",
              "format": "uuid",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SystemTypeWithFields"
                }
              }
            },
            "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": []
          },
          {
            "oauth2": [
              "admin:read"
            ]
          }
        ],
        "summary": "Получить системный тип с полями",
        "tags": [
          "templates"
        ]
      },
      "patch": {
        "operationId": "patch_api_v1_templates_types_typeId",
        "parameters": [
          {
            "description": "Идентификатор системного типа",
            "in": "path",
            "name": "typeId",
            "required": true,
            "schema": {
              "description": "Идентификатор системного типа",
              "format": "uuid",
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "properties": {
                  "description": {
                    "description": "Новое описание",
                    "maxLength": 2048,
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "icon": {
                    "description": "Новая иконка",
                    "maxLength": 64,
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "name": {
                    "description": "Новое название типа",
                    "maxLength": 256,
                    "minLength": 1,
                    "type": "string"
                  },
                  "templates": {
                    "additionalProperties": true,
                    "description": "Новые настройки шаблона",
                    "type": [
                      "object",
                      "null"
                    ]
                  }
                },
                "type": "object"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SystemType"
                }
              }
            },
            "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": []
          },
          {
            "oauth2": [
              "admin:write"
            ]
          }
        ],
        "summary": "Обновить системный тип",
        "tags": [
          "templates"
        ]
      }
    },
    "/api/v1/templates/types/{typeId}/fields": {
      "get": {
        "operationId": "get_api_v1_templates_types_typeId_fields",
        "parameters": [
          {
            "description": "Идентификатор системного типа",
            "in": "path",
            "name": "typeId",
            "required": true,
            "schema": {
              "description": "Идентификатор системного типа",
              "format": "uuid",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "items": {
                    "$ref": "#/components/schemas/SystemField"
                  },
                  "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": []
          },
          {
            "oauth2": [
              "admin:read"
            ]
          }
        ],
        "summary": "Список системных полей типа",
        "tags": [
          "templates"
        ]
      },
      "post": {
        "operationId": "post_api_v1_templates_types_typeId_fields",
        "parameters": [
          {
            "description": "Идентификатор системного типа",
            "in": "path",
            "name": "typeId",
            "required": true,
            "schema": {
              "description": "Идентификатор системного типа",
              "format": "uuid",
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "properties": {
                  "cardinality": {
                    "default": "one",
                    "description": "Кратность: одно значение или список",
                    "enum": [
                      "one",
                      "many"
                    ],
                    "type": "string"
                  },
                  "dataType": {
                    "description": "Тип данных поля",
                    "enum": [
                      "text",
                      "select",
                      "checkbox",
                      "user",
                      "document",
                      "string",
                      "number",
                      "integer",
                      "boolean",
                      "date",
                      "datetime",
                      "enum",
                      "status",
                      "rich_text",
                      "reference",
                      "json"
                    ],
                    "type": "string"
                  },
                  "defaultValue": {
                    "description": "Значение по умолчанию"
                  },
                  "description": {
                    "description": "Описание поля",
                    "maxLength": 2048,
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "key": {
                    "description": "Машинный ключ поля",
                    "maxLength": 128,
                    "minLength": 1,
                    "pattern": "^[a-z][a-z0-9_]*$",
                    "type": "string"
                  },
                  "name": {
                    "description": "Название поля",
                    "maxLength": 256,
                    "minLength": 1,
                    "type": "string"
                  },
                  "options": {
                    "additionalProperties": true,
                    "description": "Настройки значений (для enum/status)",
                    "properties": {
                      "__deprecated": {
                        "description": "Значения, скрытые для новых блоков",
                        "items": {
                          "type": "string"
                        },
                        "type": "array"
                      },
                      "colors": {
                        "additionalProperties": {
                          "type": "string",
                          "x-additionalPropertiesName": "value"
                        },
                        "description": "Цвета значений",
                        "type": "object"
                      },
                      "groups": {
                        "additionalProperties": {
                          "items": {
                            "type": "string"
                          },
                          "type": "array",
                          "x-additionalPropertiesName": "group"
                        },
                        "description": "Группировка значений",
                        "type": "object"
                      },
                      "items": {
                        "description": "Допустимые значения enum/status",
                        "items": {
                          "type": "string"
                        },
                        "type": "array"
                      },
                      "labels": {
                        "additionalProperties": {
                          "type": "string",
                          "x-additionalPropertiesName": "value"
                        },
                        "description": "Подписи значений",
                        "type": "object"
                      }
                    },
                    "type": [
                      "object",
                      "null"
                    ]
                  },
                  "ordinal": {
                    "description": "Порядок поля",
                    "minimum": 0,
                    "type": "integer"
                  },
                  "refTypeId": {
                    "description": "Для reference: тип, на который ссылается поле",
                    "format": "uuid",
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "required": {
                    "default": false,
                    "description": "Обязательность заполнения",
                    "type": "boolean"
                  },
                  "validation": {
                    "additionalProperties": true,
                    "description": "Правила валидации",
                    "type": [
                      "object",
                      "null"
                    ]
                  }
                },
                "required": [
                  "key",
                  "name",
                  "dataType",
                  "ordinal"
                ],
                "type": "object"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SystemField"
                }
              }
            },
            "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": []
          },
          {
            "oauth2": [
              "admin:write"
            ]
          }
        ],
        "summary": "Создать системное поле",
        "tags": [
          "templates"
        ]
      }
    }
  },
  "servers": [
    {
      "description": "Публичный API LegalStack",
      "url": "https://api.legalstack.ru"
    }
  ],
  "tags": [
    {
      "description": "Шаблоны платформы: системные переменные, виды блоков, шаблоны блоков, документов, реестров, проверок и автоматизаций; жизненный цикл — черновик, публикация, откат.",
      "name": "templates",
      "x-displayName": "Управление шаблонами"
    },
    {
      "description": "Системный каталог шаблонов: типы документов, поля, справочники.",
      "name": "system-templates",
      "x-displayName": "Системный каталог"
    }
  ],
  "webhooks": {}
}
