fix(docs-generator): вложенные map-fixed как аргумент '= {' (а не блок), array-map-fixed через jsonencode
This commit is contained in:
@@ -708,11 +708,15 @@ func formatParamOrBlock(p types.ParamSpec, indent string, requiredOnly bool) str
|
|||||||
if requiredOnly && !p.Required {
|
if requiredOnly && !p.Required {
|
||||||
return ""
|
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 {
|
if p.HasSubParams && len(p.SubParams) > 0 && !p.IsJson {
|
||||||
paramCode := ToSnake(p.Code)
|
paramCode := ToSnake(p.Code)
|
||||||
var b strings.Builder
|
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 {
|
for _, sp := range p.SubParams {
|
||||||
spVal := sampleValue(sp)
|
spVal := sampleValue(sp)
|
||||||
if isJsonType(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))
|
b.WriteString(fmt.Sprintf("%s}\n", indent))
|
||||||
return b.String()
|
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 {
|
if p.HasSubParams && len(p.SubParams) > 0 && p.IsJson {
|
||||||
paramCode := ToSnake(p.Code)
|
paramCode := ToSnake(p.Code)
|
||||||
var b strings.Builder
|
var b strings.Builder
|
||||||
b.WriteString(fmt.Sprintf("%s%s {\n", indent, paramCode))
|
b.WriteString(fmt.Sprintf("%s%s = jsonencode([\n", indent, paramCode))
|
||||||
b.WriteString(fmt.Sprintf("%s # Каждый элемент массива — объект с полями:\n", indent))
|
b.WriteString(fmt.Sprintf("%s {\n", indent))
|
||||||
for _, sp := range p.SubParams {
|
for _, sp := range p.SubParams {
|
||||||
spVal := sampleValue(sp)
|
spVal := sampleValue(sp)
|
||||||
if isJsonType(sp) {
|
if isJsonType(sp) {
|
||||||
@@ -749,12 +755,13 @@ func formatParamOrBlock(p types.ParamSpec, indent string, requiredOnly bool) str
|
|||||||
spComment = strings.TrimSpace(stripHTML(sp.Man))
|
spComment = strings.TrimSpace(stripHTML(sp.Man))
|
||||||
}
|
}
|
||||||
if spComment != "" {
|
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 {
|
} 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 b.String()
|
||||||
}
|
}
|
||||||
return formatParamLine(p, indent, requiredOnly)
|
return formatParamLine(p, indent, requiredOnly)
|
||||||
|
|||||||
Reference in New Issue
Block a user