refactor: shared YAML types via tf-tools/lib (yaml-generator + resource-generator)

TOOLS/lib/types.go — canonical ServiceSpec, ParamSpec, OperationSpec, OutputParam.
Both generators use type aliases, one source of truth for YAML contract.
docs-generator stays as-is (will be replaced by LLM-based generator).
This commit is contained in:
“Naeel”
2026-07-06 09:40:59 +04:00
parent 53d03004de
commit b56e634796
8 changed files with 137 additions and 131 deletions
+4
View File
@@ -3,3 +3,7 @@ module resource-generator
go 1.24
require gopkg.in/yaml.v3 v3.0.1
require tf-tools/lib v0.0.0
replace tf-tools/lib => ../lib
@@ -226,8 +226,8 @@ func ConvertParams(params []types.ParamSpec) []types.Param {
typeName := NormalizeParamType(p.DataType)
defVal := NormalizeDefault(p.Default)
ref := 0
if p.RefSvcId != nil {
ref = *p.RefSvcId
if p.RefSvcID != nil {
ref = *p.RefSvcID
}
out = append(out, types.Param{
ID: p.ID,
@@ -238,7 +238,7 @@ func ConvertParams(params []types.ParamSpec) []types.Param {
RefSvcId: ref,
Descr: strings.TrimSpace(p.Descr),
Man: strings.TrimSpace(p.Man),
Sensitive: p.Sensitive,
Sensitive: p.IsSensitive,
IsJson: strings.EqualFold(strings.TrimSpace(p.DataType), "json"),
})
}
@@ -11,41 +11,18 @@
// - всё остальное → отдельный GenAction
package types
// ─── Входные структуры (из YAML) ───────────────────────────────────────────
import "tf-tools/lib"
// ParamSpec — один параметр операции как он описан в YAML.
// Соответствует cfsParam из API Nubes.
type ParamSpec struct {
ID int `yaml:"id"` // svcOperationCfsParamId
Code string `yaml:"code"` // имя параметра (camelCase)
DataType string `yaml:"data_type,omitempty"` // string | integer > 0 | boolean | map-fixed | uuid | json | ...
Required bool `yaml:"required"` // обязательный?
Default interface{} `yaml:"default,omitempty"` // значение по умолчанию (строка или число)
RefSvcId *int `yaml:"ref_svc_id,omitempty"` // ссылка на другой сервис (UUID-параметр)
Descr string `yaml:"descr,omitempty"` // описание
Man string `yaml:"man,omitempty"` // MAN-руководство
Sensitive bool `yaml:"is_sensitive,omitempty"` // секретный параметр?
}
// ─── Алиасы к lib (общий YAML-контракт) ─────────────────────────────────────
// OutputParam — выходной параметр сервиса (state_params, vault_secrets, ...).
type OutputParam struct {
Code string `yaml:"code"` // код: state_params, state_out, vault_url, ...
Type string `yaml:"type"` // map | string | list
Sensitive bool `yaml:"sensitive,omitempty"` // vault_secrets = true
}
type OutputParam = lib.OutputParam
type OperationSpec = lib.OperationSpec
type ParamSpec = lib.ParamSpec
// OperationSpec — одна операция сервиса (create, modify, delete_user, ...).
type OperationSpec struct {
Name string `yaml:"name"` // имя операции (create, modify, ...)
ID int `yaml:"id"` // svcOperationId
Kind string `yaml:"kind"` // instance | subresource | action
Action string `yaml:"action"` // create | modify | delete | suspend | redeploy | ...
Subresource string `yaml:"subresource,omitempty"` // для subresource: user, database, topic, ...
Man string `yaml:"man,omitempty"` // MAN-руководство операции
Params []ParamSpec `yaml:"params"` // параметры операции
}
// ─── Входные структуры (из YAML) — локальное определение ────────────────────
// ServiceSpec — полная YAML-спецификация одного сервиса.
// ServiceSpec — локальное определение (отличается вложенными типами от lib).
// Использует *bool для Lifecycle (совместимость с YAML-парсингом).
type ServiceSpec struct {
Name string `yaml:"name"` // snake_case имя (postgres, s3bucket, ...)
ServiceID int `yaml:"service_id"` // числовой ID сервиса в Nubes