Skip to content

Commit fbd7943

Browse files
committed
schema: make builtin schema the default.
With schema-based validation split out from the Cache and being disabled by default, it is safe to make the builtin Schema the default one. Signed-off-by: Krisztian Litkey <[email protected]>
1 parent 2bc484e commit fbd7943

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

schema/schema.go

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,10 @@ import (
3434
)
3535

3636
const (
37-
// BuiltinSchemaName references the builtin schema for Load()/Set().
37+
// BuiltinSchemaName names the builtin schema for Load()/Set().
3838
BuiltinSchemaName = "builtin"
39-
// NoneSchemaName references a disabled/NOP schema for Load()/Set().
39+
// NoneSchemaName names the NOP-schema for Load()/Set().
4040
NoneSchemaName = "none"
41-
// DefaultSchemaName is the none schema.
42-
DefaultSchemaName = NoneSchemaName
43-
4441
// builtinSchemaFile is the builtin schema URI in our embedded FS.
4542
builtinSchemaFile = "file:///schema.json"
4643
)
@@ -65,8 +62,26 @@ func Get() *Schema {
6562
return current
6663
}
6764

68-
// BuiltinSchema returns the builtin validating JSON Schema.
65+
// BuiltinSchema returns the builtin schema if we have a valid one. Otherwise
66+
// it falls back to NopSchema().
6967
func BuiltinSchema() *Schema {
68+
if builtin != nil {
69+
return builtin
70+
}
71+
72+
s, err := schema.NewSchema(
73+
schema.NewReferenceLoaderFileSystem(
74+
builtinSchemaFile,
75+
http.FS(builtinFS),
76+
),
77+
)
78+
79+
if err == nil {
80+
builtin = &Schema{schema: s}
81+
} else {
82+
builtin = NopSchema()
83+
}
84+
7085
return builtin
7186
}
7287

@@ -229,25 +244,8 @@ var (
229244
// our builtin schema
230245
builtin *Schema
231246
// currently loaded schema, builtin by default
232-
current *Schema
247+
current = BuiltinSchema()
233248
)
234249

235250
//go:embed *.json
236251
var builtinFS embed.FS
237-
238-
func init() {
239-
s, err := schema.NewSchema(
240-
schema.NewReferenceLoaderFileSystem(
241-
builtinSchemaFile,
242-
http.FS(builtinFS),
243-
),
244-
)
245-
246-
if err != nil {
247-
builtin = NopSchema()
248-
} else {
249-
builtin = &Schema{schema: s}
250-
}
251-
252-
current = builtin
253-
}

0 commit comments

Comments
 (0)