mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
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:
@@ -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
@@ -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
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user