mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-26 21:05:30 +00:00
validate config updates via cmd and api with schema
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/google/jsonschema-go/jsonschema"
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
var ConfigSchema = jsonschema.Schema{
|
||||
@@ -24,22 +21,19 @@ var ConfigSchema = jsonschema.Schema{
|
||||
},
|
||||
}
|
||||
|
||||
func ValidateConfig(config config.Config) error {
|
||||
func ApplyDefaults(cfg *map[string]any) error {
|
||||
resolvedSchema, err := GetResolvedConfigSchema()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
jsonBytes, err := json.Marshal(config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
jsonMap := make(map[string]any)
|
||||
err = json.Unmarshal(jsonBytes, &jsonMap)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return resolvedSchema.Validate(jsonMap)
|
||||
return resolvedSchema.ApplyDefaults(cfg)
|
||||
}
|
||||
|
||||
func ValidateConfig(cfg map[string]any) error {
|
||||
resolvedSchema, err := GetResolvedConfigSchema()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return resolvedSchema.Validate(cfg)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user