From af2e10b1d52aea2e7d058dae1aafc18ae1b494bb Mon Sep 17 00:00:00 2001 From: Repinoid Date: Mon, 21 Sep 2026 20:19:42 +0300 Subject: [PATCH] =?UTF-8?q?fix(docs-generator):=20=D0=B2=D0=BB=D0=BE=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D1=8B=D0=B5=20map-fixed=20=D0=BA=D0=B0=D0=BA?= =?UTF-8?q?=20=D0=B0=D1=80=D0=B3=D1=83=D0=BC=D0=B5=D0=BD=D1=82=20'=3D=20{'?= =?UTF-8?q?=20(=D0=B0=20=D0=BD=D0=B5=20=D0=B1=D0=BB=D0=BE=D0=BA),=20array-?= =?UTF-8?q?map-fixed=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20jsonencode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../internal/writers/writers.go | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/TOOLS/docs-generator/internal/writers/writers.go b/TOOLS/docs-generator/internal/writers/writers.go index 0682d35..bd41d4e 100644 --- a/TOOLS/docs-generator/internal/writers/writers.go +++ b/TOOLS/docs-generator/internal/writers/writers.go @@ -708,11 +708,15 @@ func formatParamOrBlock(p types.ParamSpec, indent string, requiredOnly bool) str if requiredOnly && !p.Required { return "" } - // Для map-fixed генерируем вложенный HCL-блок + // Для map-fixed генерируем HCL-АРГУМЕНТ объекта: `param = { ... }`. + // ВАЖНО: resource-generator объявляет такие поля как schema.SingleNestedAttribute, + // а SingleNestedAttribute в HCL — это аргумент (через `=`), НЕ блок. + // Блочный синтаксис (`param { ... }`) ломает terraform validate: + // "Unsupported block type ... Did you mean to define argument?". if p.HasSubParams && len(p.SubParams) > 0 && !p.IsJson { paramCode := ToSnake(p.Code) var b strings.Builder - b.WriteString(fmt.Sprintf("%s%s {\n", indent, paramCode)) + b.WriteString(fmt.Sprintf("%s%s = {\n", indent, paramCode)) for _, sp := range p.SubParams { spVal := sampleValue(sp) if isJsonType(sp) { @@ -732,12 +736,14 @@ func formatParamOrBlock(p types.ParamSpec, indent string, requiredOnly bool) str b.WriteString(fmt.Sprintf("%s}\n", indent)) return b.String() } - // Для array-map-fixed генерируем dynamic блок + // array-map-fixed: resource-generator объявляет такие поля как schema.StringAttribute + // (JSON-строка), поэтому в доке это тоже аргумент-строка через jsonencode([...]), + // а НЕ блок и НЕ dynamic-блок. if p.HasSubParams && len(p.SubParams) > 0 && p.IsJson { paramCode := ToSnake(p.Code) var b strings.Builder - b.WriteString(fmt.Sprintf("%s%s {\n", indent, paramCode)) - b.WriteString(fmt.Sprintf("%s # Каждый элемент массива — объект с полями:\n", indent)) + b.WriteString(fmt.Sprintf("%s%s = jsonencode([\n", indent, paramCode)) + b.WriteString(fmt.Sprintf("%s {\n", indent)) for _, sp := range p.SubParams { spVal := sampleValue(sp) if isJsonType(sp) { @@ -749,12 +755,13 @@ func formatParamOrBlock(p types.ParamSpec, indent string, requiredOnly bool) str spComment = strings.TrimSpace(stripHTML(sp.Man)) } if spComment != "" { - b.WriteString(fmt.Sprintf("%s %s = %s # %s\n", indent, spCode, spVal, spComment)) + b.WriteString(fmt.Sprintf("%s %s = %s # %s\n", indent, spCode, spVal, spComment)) } else { - b.WriteString(fmt.Sprintf("%s %s = %s\n", indent, spCode, spVal)) + b.WriteString(fmt.Sprintf("%s %s = %s\n", indent, spCode, spVal)) } } - b.WriteString(fmt.Sprintf("%s}\n", indent)) + b.WriteString(fmt.Sprintf("%s },\n", indent)) + b.WriteString(fmt.Sprintf("%s])\n", indent)) return b.String() } return formatParamLine(p, indent, requiredOnly)