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 yaml-generator
go 1.24
require gopkg.in/yaml.v3 v3.0.1
require tf-tools/lib v0.0.0-00010101000000-000000000000
replace tf-tools/lib => ../lib
+12 -74
View File
@@ -1,16 +1,12 @@
// Package types — структуры данных для YAML-спеков сервисов.
//
// Содержит два набора типов:
// - API-ответы (ServiceResponse, ServiceInfo, CfsParam, ...) —
// соответствуют JSON-структурам Nubes API /services/{id} и /serviceOperation/{id}.
// - Выходные YAML-типы (ServiceSpec, ParamSpec, OperationSpec, ...) —
// сериализуются в resources_yaml/*.yaml и читаются генераторами resource-generator и docs-generator.
//
// Разделение API-входа и YAML-выхода позволяет менять формат YAML
// независимо от структуры API.
// API-ответы — собственные типы.
// YAML-типы — алиасы к lib (общий контракт).
package types
// ─── API-ответы ─────────────────────────────────────────────────────────────
import "tf-tools/lib"
// ─── API-ответы (специфичны для yaml-generator, не из lib) ──────────────────
// ServiceResponse — ответ /services/{id}.
type ServiceResponse struct {
@@ -69,69 +65,11 @@ type CfsParam struct {
IsSensitive bool `json:"isSensitive"`
}
// ─── Выходные структуры (YAML) ──────────────────────────────────────────────
// ─── YAML-типы (алиасы к lib — общий контракт) ─────────────────────────────
// ServiceSpec — полная YAML-спецификация сервиса.
type ServiceSpec struct {
Name string `yaml:"name"`
ServiceID int `yaml:"service_id"`
ServiceDisplayName string `yaml:"service_display_name,omitempty"`
ServiceShortName string `yaml:"service_short_name,omitempty"`
ServiceMan string `yaml:"service_man,omitempty"`
Lifecycle Lifecycle `yaml:"lifecycle"`
Outputs OutputSection `yaml:"outputs"`
Operations []OperationSpec `yaml:"operations"`
}
// Lifecycle — настройки жизненного цикла сервиса.
type Lifecycle struct {
SuspendOnDestroyDefault bool `yaml:"suspend_on_destroy_default"`
AdoptExistingOnCreateDefault bool `yaml:"adopt_existing_on_create_default"`
}
// OutputSection — секция выходных параметров.
type OutputSection struct {
Params []OutputParam `yaml:"params"`
}
// OutputParam — выходной параметр (state_params, vault_secrets, ...).
type OutputParam struct {
Code string `yaml:"code"`
Type string `yaml:"type"`
Sensitive bool `yaml:"sensitive,omitempty"`
}
// OperationSpec — одна операция в YAML-спеке.
type OperationSpec struct {
Name string `yaml:"name"`
ID int `yaml:"id"`
Kind string `yaml:"kind"`
Action string `yaml:"action"`
Subresource string `yaml:"subresource,omitempty"`
Man string `yaml:"man,omitempty"`
Params []ParamSpec `yaml:"params"`
}
// ParamSpec — параметр операции в YAML-спеке.
type ParamSpec struct {
ID int `yaml:"id"`
Code string `yaml:"code"`
DataType string `yaml:"data_type,omitempty"`
Required bool `yaml:"required"`
Default interface{} `yaml:"default,omitempty"`
ValueList []string `yaml:"value_list,omitempty"`
RefSvcID *int `yaml:"ref_svc_id,omitempty"`
Func string `yaml:"func,omitempty"`
Regex string `yaml:"regex,omitempty"`
UniqueScope string `yaml:"unique_scope,omitempty"`
MaxLength *int `yaml:"maxlength,omitempty"`
MinLength *int `yaml:"minlength,omitempty"`
MaxValue interface{} `yaml:"maxvalue,omitempty"`
MinValue interface{} `yaml:"minvalue,omitempty"`
Descr string `yaml:"descr,omitempty"`
Man string `yaml:"man,omitempty"`
Sort *int `yaml:"sort,omitempty"`
DependsOn interface{} `yaml:"depends_on,omitempty"`
IsModifiable *bool `yaml:"is_modifiable,omitempty"`
IsSensitive bool `yaml:"is_sensitive,omitempty"`
}
type ServiceSpec = lib.ServiceSpec
type Lifecycle = lib.Lifecycle
type OutputSection = lib.OutputSection
type OutputParam = lib.OutputParam
type OperationSpec = lib.OperationSpec
type ParamSpec = lib.ParamSpec