fix(docs-generator): строковые дефолты в кавычках (default 81.22.46.22 ломал HCL-парсер: Invalid number literal)

This commit is contained in:
Repinoid
2026-09-21 20:26:41 +03:00
parent 7c2cc673cc
commit 3ca0752df8
@@ -769,6 +769,14 @@ func formatParamOrBlock(p types.ParamSpec, indent string, requiredOnly bool) str
func sampleValue(p types.ParamSpec) string {
if hasDefault(p.Default) {
// ВАЖНО: тип атрибута в схеме важнее «вида» значения в YAML.
// YAML-парсер отдаёт `default: 81.22.46.22` как float64, и formatLiteral
// печатает его без кавычек — а HCL не может распарсить такой литерал:
// Error: Invalid number literal (Failed to recognize the value of this number literal)
// Для строковых параметров значение обязано быть в кавычках.
if isStringParam(p) {
return strconv.Quote(fmt.Sprintf("%v", p.Default))
}
return formatLiteral(p.Default)
}
if len(p.ValueList) > 0 {
@@ -786,6 +794,11 @@ func sampleValue(p types.ParamSpec) string {
return "\"TODO\""
}
// isStringParam — параметр является строкой по схеме (data_type: string / varchar).
func isStringParam(p types.ParamSpec) bool {
return strings.Contains(strings.ToLower(firstType(p)), "string")
}
func formatLiteral(value interface{}) string {
switch v := value.(type) {
case bool: