mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2025-07-25 21:56:07 +02:00
Fix broken schema and add tests
This commit is contained in:
@@ -9,7 +9,8 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/ClusterCockpit/cc-backend/pkg/log"
|
||||
"github.com/santhosh-tekuri/jsonschema/v5"
|
||||
@@ -27,31 +28,22 @@ const (
|
||||
//go:embed schemas/*
|
||||
var schemaFiles embed.FS
|
||||
|
||||
func Load(s string) (io.ReadCloser, error) {
|
||||
u, err := url.Parse(s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
f := u.Path
|
||||
return schemaFiles.Open(f)
|
||||
}
|
||||
|
||||
func init() {
|
||||
jsonschema.Loaders["embedFS"] = Load
|
||||
}
|
||||
|
||||
func Validate(k Kind, r io.Reader) (err error) {
|
||||
jsonschema.Loaders["embedfs"] = func(s string) (io.ReadCloser, error) {
|
||||
f := filepath.Join("schemas", strings.Split(s, "//")[1])
|
||||
return schemaFiles.Open(f)
|
||||
}
|
||||
var s *jsonschema.Schema
|
||||
|
||||
switch k {
|
||||
case Meta:
|
||||
s, err = jsonschema.Compile("embedFS://schemas/job-meta.schema.json")
|
||||
s, err = jsonschema.Compile("embedfs://job-meta.schema.json")
|
||||
case Data:
|
||||
s, err = jsonschema.Compile("embedFS://schemas/job-data.schema.json")
|
||||
s, err = jsonschema.Compile("embedfs://job-data.schema.json")
|
||||
case ClusterCfg:
|
||||
s, err = jsonschema.Compile("embedFS://schemas/cluster.schema.json")
|
||||
s, err = jsonschema.Compile("embedfs://cluster.schema.json")
|
||||
case Config:
|
||||
s, err = jsonschema.Compile("embedFS://schemas/config.schema.json")
|
||||
s, err = jsonschema.Compile("embedfs://config.schema.json")
|
||||
default:
|
||||
return fmt.Errorf("unkown schema kind ")
|
||||
}
|
||||
|
Reference in New Issue
Block a user