Each generator is now a standalone Go module with its own go.mod: TOOLS/ ├── yaml-generator/ ← service_spec_gen (API → YAML) ├── resource-generator/ ← gen_v2 (YAML → Go resources) ├── docs-generator/ ← docs_template_gen_v2 (YAML → Markdown) ├── ops-generator/ ← ops_docs_gen (ops documentation) └── bin/ ← pre-built binaries All scripts updated to use TOOLS/bin/* binaries. Removed old universal_rebuild/tools/ and universal_rebuild/bin/.
70 lines
1.7 KiB
Go
70 lines
1.7 KiB
Go
// Package normalize — утилиты нормализации имён и endpoint'ов.
|
|
package normalize
|
|
|
|
import "strings"
|
|
|
|
// ServiceName нормализует имя сервиса для использования в именах файлов.
|
|
func ServiceName(raw string) string {
|
|
return Identifier(raw)
|
|
}
|
|
|
|
// OperationName нормализует имя операции в snake_case.
|
|
func OperationName(raw string) string {
|
|
return Identifier(raw)
|
|
}
|
|
|
|
// Identifier конвертирует строку в ASCII snake_case.
|
|
func Identifier(raw string) string {
|
|
if strings.TrimSpace(raw) == "" {
|
|
return ""
|
|
}
|
|
var out []rune
|
|
lastUnderscore := false
|
|
prevLowerOrDigit := false
|
|
for _, r := range raw {
|
|
if r >= 'A' && r <= 'Z' {
|
|
if prevLowerOrDigit && !lastUnderscore {
|
|
out = append(out, '_')
|
|
}
|
|
out = append(out, r+'a'-'A')
|
|
lastUnderscore = false
|
|
prevLowerOrDigit = true
|
|
continue
|
|
}
|
|
if r >= 'a' && r <= 'z' {
|
|
out = append(out, r)
|
|
lastUnderscore = false
|
|
prevLowerOrDigit = true
|
|
continue
|
|
}
|
|
if r >= '0' && r <= '9' {
|
|
out = append(out, r)
|
|
lastUnderscore = false
|
|
prevLowerOrDigit = true
|
|
continue
|
|
}
|
|
if !lastUnderscore && len(out) > 0 {
|
|
out = append(out, '_')
|
|
lastUnderscore = true
|
|
}
|
|
prevLowerOrDigit = false
|
|
}
|
|
result := strings.Trim(string(out), "_")
|
|
return collapseUnderscores(result)
|
|
}
|
|
|
|
// APIEndpoint нормализует URL API-эндпоинта (убирает trailing slash).
|
|
func APIEndpoint(raw string) string {
|
|
return strings.TrimRight(strings.TrimSpace(raw), "/")
|
|
}
|
|
|
|
func collapseUnderscores(value string) string {
|
|
if value == "" {
|
|
return value
|
|
}
|
|
for strings.Contains(value, "__") {
|
|
value = strings.ReplaceAll(value, "__", "_")
|
|
}
|
|
return strings.Trim(value, "_")
|
|
}
|