Compose glossary collections through configuration
This commit is contained in:
@@ -115,13 +115,27 @@ func defaults() Config {
|
||||
}
|
||||
}
|
||||
|
||||
const glossaryImports = `config:
|
||||
imports:
|
||||
- path: glossary.yml
|
||||
required: false
|
||||
destination: [glossary_collections]
|
||||
- dir: glossary
|
||||
required: false
|
||||
recursive: true
|
||||
pattern: ["*.yml", "*.yaml"]
|
||||
destination: [glossary_collections]
|
||||
`
|
||||
|
||||
// Load resolves the selected main source and preserves native source evidence.
|
||||
func Load(input ck.Input, overlay string, overrides ...ck.Override) (*ck.Result[Config], error) {
|
||||
input.Imports = true
|
||||
return ck.LoadLayered(input, ck.LayeredOptions[Config]{
|
||||
Overlay: overlay, Overrides: overrides,
|
||||
Underlays: []ck.Underlay{{Inputs: []ck.Input{{Source: ck.Bytes("Audita glossary imports", []byte(glossaryImports)), Imports: true, MainRelative: ck.MainRelative()}}}},
|
||||
Definition: ck.Definition[Config]{
|
||||
Defaults: defaults,
|
||||
Defaults: defaults,
|
||||
SequenceIdentities: []ck.SequenceIdentity{ck.SequenceIdentityMatching(ck.SequenceSelector{ck.SequenceLiteralKey("glossary_collections"), ck.SequenceAnyMappingKey(), ck.SequenceLiteralKey("entries")}, "id")},
|
||||
Version: &ck.VersionRule{Path: ck.Keys("version"), Check: func(version ck.Version, v *ck.Validation) error {
|
||||
if version.Present && (version.Null || version.Text != "3") {
|
||||
v.Error(ck.Keys("version"), "use application configuration version 3; see docs/migrations/v3.md")
|
||||
@@ -139,6 +153,18 @@ func validate(c *Config, v *ck.Validation) {
|
||||
v.Error(path, message)
|
||||
}
|
||||
}
|
||||
for name, collection := range c.GlossaryCollections {
|
||||
for i, entry := range collection.Entries {
|
||||
path := ck.Keys("glossary_collections", name, "entries").Index(i)
|
||||
check(entry.ID != "", path.Key("id"), "entry id must not be empty")
|
||||
check(entry.Name != "", path.Key("name"), "entry name must not be empty")
|
||||
check(entry.Category != "", path.Key("category"), "entry category must not be empty")
|
||||
for index, alias := range entry.Aliases {
|
||||
check(alias != "", path.Key("aliases").Index(index), "alias must not be empty")
|
||||
}
|
||||
check(entry.Plural == nil || *entry.Plural != "", path.Key("plural"), "plural must not be empty")
|
||||
}
|
||||
}
|
||||
check(c.LLM.TransientRetries >= 0, ck.Keys("llm", "transient_retries"), "retry budget must be non-negative")
|
||||
check(c.LLM.RepairAttempts >= 0 && c.LLM.RepairAttempts <= 3, ck.Keys("llm", "repair_attempts"), "repair attempts must be between zero and three")
|
||||
check(c.LLM.OperationTimeout > 0, ck.Keys("llm", "operation_timeout"), "operation timeout must be positive")
|
||||
|
||||
Reference in New Issue
Block a user