From 5dbb2acda4a7407364994592b8bd23872f002062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Fri, 17 Jul 2026 10:18:24 +0400 Subject: [PATCH] =?UTF-8?q?fix:=20example=20blocks=20=E2=80=94=20jsonencod?= =?UTF-8?q?e=20for=20json=20types,=20TODO=20instead=20of=20hardcoded=20val?= =?UTF-8?q?ues,=20add=20resource=5Fname?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TOOLS/docs-generator/internal/writers/writers.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/TOOLS/docs-generator/internal/writers/writers.go b/TOOLS/docs-generator/internal/writers/writers.go index a63150b..ec09f28 100644 --- a/TOOLS/docs-generator/internal/writers/writers.go +++ b/TOOLS/docs-generator/internal/writers/writers.go @@ -219,6 +219,7 @@ func exampleBlock(spec types.ServiceSpec, version string, apiEndpoint string) st b.WriteString(fmt.Sprintf(" api_endpoint = \"%s\"\n", apiEndpoint)) b.WriteString("}\n") b.WriteString(fmt.Sprintf("resource \"nubes_%s\" \"baza\" {\n", spec.Name)) + b.WriteString(" resource_name = \"TODO\"\n\n") for _, p := range requiredParams { b.WriteString(formatParamOrBlock(p, " ", true)) @@ -555,6 +556,9 @@ func formatParamLine(p types.ParamSpec, indent string, requiredOnly bool) string return "" } value := sampleValue(p) + if isJsonType(p) { + value = fmt.Sprintf("jsonencode(%s)", value) + } comment := strings.TrimSpace(stripHTML(p.Descr)) if comment == "" { comment = strings.TrimSpace(stripHTML(p.Man)) @@ -578,6 +582,9 @@ func formatParamOrBlock(p types.ParamSpec, indent string, requiredOnly bool) str b.WriteString(fmt.Sprintf("%s%s {\n", indent, paramCode)) for _, sp := range p.SubParams { spVal := sampleValue(sp) + if isJsonType(sp) { + spVal = fmt.Sprintf("jsonencode(%s)", spVal) + } spCode := ToSnake(sp.Code) spComment := strings.TrimSpace(stripHTML(sp.Descr)) if spComment == "" { @@ -600,6 +607,9 @@ func formatParamOrBlock(p types.ParamSpec, indent string, requiredOnly bool) str b.WriteString(fmt.Sprintf("%s # Каждый элемент массива — объект с полями:\n", indent)) for _, sp := range p.SubParams { spVal := sampleValue(sp) + if isJsonType(sp) { + spVal = fmt.Sprintf("jsonencode(%s)", spVal) + } spCode := ToSnake(sp.Code) spComment := strings.TrimSpace(stripHTML(sp.Descr)) if spComment == "" { @@ -622,7 +632,7 @@ func sampleValue(p types.ParamSpec) string { return formatLiteral(p.Default) } if len(p.ValueList) > 0 { - return formatLiteral(p.ValueList[0]) + return "\"TODO\"" } dtype := strings.ToLower(firstType(p)) switch { @@ -713,6 +723,10 @@ func normalizeType(dtype string) string { return strings.TrimSpace(cleaned) } +func isJsonType(p types.ParamSpec) bool { + return strings.Contains(strings.ToLower(firstType(p)), "json") +} + func defaultCell(value interface{}) string { if !hasDefault(value) { return ""