Skip to content

Commit

Permalink
Making changes suggested by @ashutosh-narkar
Browse files Browse the repository at this point in the history
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
  • Loading branch information
johanfylling committed Feb 28, 2023
1 parent 85685e3 commit 1bbc4f2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions ast/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -2664,7 +2664,7 @@ var GraphQLSchemaIsValid = &Builtin{
// JSONSchemaVerify returns empty string if the input is valid JSON schema
// and returns error string for all other inputs.
var JSONSchemaVerify = &Builtin{
Name: "jsonschema.verify",
Name: "json.verify_schema",
Description: "Checks that the input is a valid JSON schema object. The schema can be either a JSON string or an JSON object.",
Decl: types.NewFunction(
types.Args(
Expand Down Expand Up @@ -2706,7 +2706,7 @@ var JSONMatchSchema = &Builtin{
),
),
}, nil)).
Description("`output` is of the form `[match, errors]`. If the document is valid given the schema, then `match` is `true`, and `errors` is an empty array. Otherwise, `match` is `true` and `errors` is an array of objects describing the error(s)."),
Description("`output` is of the form `[match, errors]`. If the document is valid given the schema, then `match` is `true`, and `errors` is an empty array. Otherwise, `match` is `false` and `errors` is an array of objects describing the error(s)."),
),
Categories: objectCat,
}
Expand Down
6 changes: 3 additions & 3 deletions topdown/jsonschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ func newResultTerm(valid bool, data *ast.Term) *ast.Term {
return ast.ArrayTerm(ast.BooleanTerm(valid), data)
}

// builtinJSONSchemaValidate accepts 1 argument which can be string or object and checks if it is valid JSON schema.
// builtinJSONSchemaVerify accepts 1 argument which can be string or object and checks if it is valid JSON schema.
// Returns array [false, <string>] with error string at index 1, or [true, ""] with empty string at index 1 otherwise.
func builtinJSONSchemaValidate(_ BuiltinContext, operands []*ast.Term, iter func(*ast.Term) error) error {
func builtinJSONSchemaVerify(_ BuiltinContext, operands []*ast.Term, iter func(*ast.Term) error) error {
// Take first argument and make JSON Loader from it.
loader, err := astValueToJSONSchemaLoader(operands[0].Value)
if err != nil {
Expand Down Expand Up @@ -104,6 +104,6 @@ func builtinJSONMatchSchema(_ BuiltinContext, operands []*ast.Term, iter func(*a
}

func init() {
RegisterBuiltinFunc(ast.JSONSchemaVerify.Name, builtinJSONSchemaValidate)
RegisterBuiltinFunc(ast.JSONSchemaVerify.Name, builtinJSONSchemaVerify)
RegisterBuiltinFunc(ast.JSONMatchSchema.Name, builtinJSONMatchSchema)
}
4 changes: 2 additions & 2 deletions topdown/jsonschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestAstValueToJSONSchemaLoader(t *testing.T) {
}
}

func TestBuiltinJSONSchemaValidate(t *testing.T) {
func TestBuiltinJSONSchemaVerify(t *testing.T) {
cases := []struct {
note string
schema ast.Value
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestBuiltinJSONSchemaValidate(t *testing.T) {
for _, tc := range cases {
t.Run(tc.note, func(t *testing.T) {
result := ast.NullTerm().Value
err := builtinJSONSchemaValidate(
err := builtinJSONSchemaVerify(
BuiltinContext{},
[]*ast.Term{ast.NewTerm(tc.schema)},
func(term *ast.Term) error {
Expand Down

0 comments on commit 1bbc4f2

Please sign in to comment.