loader: Insert root schema with key 'schema'

Previously if there was only one schema it was inserted into the
schema set with key 'input'. There was no good reason for this and
'schema' will do. This allows for us to have tighter validation of
schema references.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
This commit is contained in:
Torin Sandall
2021-04-19 16:13:28 -04:00
parent d3adb906f0
commit 7d58f038c5
3 changed files with 11 additions and 3 deletions
+3
View File
@@ -1616,6 +1616,9 @@ func (b *metadataParser) Parse() (*Annotations, error) {
var errInvalidSchemaRef = fmt.Errorf("invalid schema reference")
// NOTE(tsandall): 'schema' is not registered as a root because it's not
// supported by the compiler or evaluator today. Once we fix that, we can remove
// this function.
func parseSchemaRef(s string) (Ref, error) {
term, err := ParseTerm(s)
+1 -1
View File
@@ -282,7 +282,7 @@ func loadSchemas(schemaPath string) (*ast.SchemaSet, error) {
if err != nil {
return nil, err
}
ss.Put(ast.InputRootRef, schema)
ss.Put(ast.SchemaRootRef, schema)
return ss, nil
}
+7 -2
View File
@@ -765,7 +765,7 @@ func TestSchemas(t *testing.T) {
"foo/bar/baz.json": `{"type": "string"}`,
},
exp: map[string]string{
"input": `{"type": "string"}`,
"schema": `{"type": "string"}`,
},
},
{
@@ -802,7 +802,12 @@ func TestSchemas(t *testing.T) {
t.Fatal("unexpected error:", err)
}
for k, v := range tc.exp {
key := ast.MustParseRef(k)
var key ast.Ref
if k == "schema" {
key = ast.SchemaRootRef.Copy()
} else {
key = ast.MustParseRef(k)
}
var schema interface{}
util.Unmarshal([]byte(v), &schema)
result := ss.Get(key)