Decode schema resources independently with exact numeric constraints
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
@@ -41,13 +42,9 @@ func Load(root fs.FS) (*Set, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("catalog.json: %w", err)
|
||||
}
|
||||
// Decode through the shared profile as well, so duplicate JSON keys fail.
|
||||
if !json.Valid(data) {
|
||||
return nil, fmt.Errorf("catalog.json: expected JSON syntax")
|
||||
}
|
||||
if _, err := Decode(data); err != nil {
|
||||
return nil, fmt.Errorf("catalog.json: %w", err)
|
||||
}
|
||||
set := &Set{schemas: make(map[string]*Schema), selections: make(map[string]string)}
|
||||
if err := json.Unmarshal(data, &set.Catalog); err != nil {
|
||||
return nil, fmt.Errorf("catalog.json: %w", err)
|
||||
@@ -98,7 +95,7 @@ func Load(root fs.FS) (*Set, error) {
|
||||
if !json.Valid(data) {
|
||||
return nil, fmt.Errorf("%s: expected JSON syntax", record.Path)
|
||||
}
|
||||
value, err := Decode(data)
|
||||
value, err := decodeResource(data)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: %w", record.Path, err)
|
||||
}
|
||||
@@ -151,6 +148,19 @@ func Load(root fs.FS) (*Set, error) {
|
||||
return set, nil
|
||||
}
|
||||
|
||||
// Schema resources are JSON, not operator configuration. Preserve exact numeric
|
||||
// constraints independently of the domain loader's numeric binding policy.
|
||||
func decodeResource(data []byte) (any, error) {
|
||||
if !json.Valid(data) {
|
||||
return nil, fmt.Errorf("expected one JSON value")
|
||||
}
|
||||
decoder := json.NewDecoder(bytes.NewReader(data))
|
||||
decoder.UseNumber()
|
||||
var value any
|
||||
err := decoder.Decode(&value)
|
||||
return value, err
|
||||
}
|
||||
|
||||
type offlineLoader struct{}
|
||||
|
||||
func (offlineLoader) Load(url string) (any, error) {
|
||||
|
||||
Reference in New Issue
Block a user