resource-generator: SubParams nested fix (Соннет) — AlignParamTypes recursive, HasNestedParams/NeedsStrings skip array-map-fixed, bump 5.0.74
This commit is contained in:
@@ -193,14 +193,15 @@ func PlanModifierExpr(p types.Param) string {
|
||||
|
||||
// ─── Nested (map-fixed) helpers ──────────────────────────────────────────────
|
||||
|
||||
// IsNested возвращает true для параметров с SubParams (map-fixed/array-map-fixed).
|
||||
// IsNested возвращает true для параметров с SubParams (map-fixed).
|
||||
// array-map-fixed исключается — требует отдельной обработки.
|
||||
func IsNested(p types.Param) bool {
|
||||
return p.IsNested
|
||||
return p.HasSubParams && !IsNestedList(p)
|
||||
}
|
||||
|
||||
// IsNestedList возвращает true для array-map-fixed (список объектов).
|
||||
func IsNestedList(p types.Param) bool {
|
||||
return p.IsNested && strings.Contains(strings.ToLower(p.Type), "array")
|
||||
return p.HasSubParams && strings.Contains(strings.ToLower(p.Type), "array")
|
||||
}
|
||||
|
||||
// NestedModelName возвращает имя вложенного Go-struct для ресурса и параметра.
|
||||
@@ -245,12 +246,13 @@ func NestedSchemaBlock(p types.Param) string {
|
||||
}
|
||||
|
||||
// NestedSchemaEnd возвращает закрывающую строку для nested-атрибута.
|
||||
// Закрывает Attributes map и сам атрибут: `}},` для SingleNested, `}}},` для ListNested.
|
||||
func NestedSchemaEnd(p types.Param) string {
|
||||
t := NestedSchemaType(p)
|
||||
if t == "ListNested" {
|
||||
return "}},"
|
||||
return "}}},"
|
||||
}
|
||||
return "},"
|
||||
return "}},"
|
||||
}
|
||||
|
||||
// SubSchemaType возвращает тип схемы для подпараметра.
|
||||
@@ -295,23 +297,20 @@ func SubParamFormat(p types.Param, varPrefix string) string {
|
||||
}
|
||||
|
||||
// NestedJSONExpr возвращает выражение для сборки JSON из nested struct через resources_core.BuildJSON.
|
||||
// BuildJSON принимает map[string]string где ключи — имена полей,
|
||||
// значения — уже отформатированные строки (числа без кавычек, строки с кавычками).
|
||||
// Пример: resources_core.BuildJSON(map[string]string{"cpu": "500", "name": "\"hello\""}) → {"cpu":500,"name":"hello"}
|
||||
func NestedJSONExpr(p types.Param, varName string) string {
|
||||
// varPrefix — префикс переменной (например "data" или "plan").
|
||||
// Генерирует доступ: data.ClusterConfiguration.Cpu, data.ClusterConfiguration.Memory, ...
|
||||
func NestedJSONExpr(p types.Param, varPrefix string) string {
|
||||
varName := varPrefix + "." + ToCamel(p.Code)
|
||||
pairs := make([]string, 0, len(p.SubParams))
|
||||
for _, sp := range p.SubParams {
|
||||
field := varName + "." + ToCamel(sp.Code)
|
||||
var valExpr string
|
||||
switch strings.ToLower(sp.Type) {
|
||||
case "bool":
|
||||
// BuildJSON ожидает "true"/"false" (без кавычек)
|
||||
valExpr = fmt.Sprintf(`fmt.Sprintf("%%v", %s.ValueBool())`, field)
|
||||
case "int64", "int", "number":
|
||||
// BuildJSON ожидает "500" (без кавычек)
|
||||
valExpr = fmt.Sprintf(`fmt.Sprintf("%%d", %s.ValueInt64())`, field)
|
||||
default:
|
||||
// BuildJSON ожидает "\"hello\"" (с кавычками)
|
||||
valExpr = fmt.Sprintf(`fmt.Sprintf("\"%%s\"", %s.ValueString())`, field)
|
||||
}
|
||||
pairs = append(pairs, fmt.Sprintf(`"%s": %s`, sp.Code, valExpr))
|
||||
|
||||
Reference in New Issue
Block a user