mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-26 21:05:30 +00:00
move schema to an internal package
This commit is contained in:
45
internal/schema/config.go
Normal file
45
internal/schema/config.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/google/jsonschema-go/jsonschema"
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
)
|
||||
|
||||
var ConfigSchema = jsonschema.Schema{
|
||||
Schema: "https://json-schema.org/draft/2020-12/schema",
|
||||
ID: "https://showbridge.io/config.schema.json",
|
||||
Title: "Config",
|
||||
Description: "showbridge configuration",
|
||||
Type: "object",
|
||||
Properties: map[string]*jsonschema.Schema{
|
||||
"api": &ApiConfigSchema,
|
||||
"modules": {
|
||||
Ref: "https://showbridge.io/modules.schema.json",
|
||||
},
|
||||
"routes": {
|
||||
Ref: "https://showbridge.io/routes.schema.json",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func ValidateConfig(config config.Config) 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)
|
||||
}
|
||||
Reference in New Issue
Block a user