Skip to content

Commit 9ac17b8

Browse files
renamed json.checkExists to json.exists (#146)
rename checkExists to exists
1 parent 4740d71 commit 9ac17b8

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

function/json/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ weight: 4601
66
# JSON Functions
77
This function package exposes common json functions.
88

9-
## checkExists()
9+
## exists()
1010
Check if the key/JSONPath is present in the json object. Refer https://github.com/oliveagle/jsonpath for expression format.
1111
### Input Args
1212

function/json/descriptor.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
"homepage": "https://github.com/prject-flogo/contrib/tree/master/function/json",
88
"functions": [
99
{
10-
"name": "checkExists",
10+
"name": "exists",
1111
"description": "Check if the key/JSONPath is present in the json object. Refer https://github.com/oliveagle/jsonpath for expression format.",
12-
"example": "json.checkExists(jsonObject, \"$.key\") => value",
12+
"example": "json.exists(jsonObject, \"$.key\") => value",
1313
"args": [
1414
{
1515
"name": "jsonObject",

function/json/checkexists.go function/json/exists.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@ import (
1010
)
1111

1212
func init() {
13-
_ = function.Register(&fnCheckExists{})
13+
_ = function.Register(&fnExists{})
1414
}
1515

16-
type fnCheckExists struct {
16+
type fnExists struct {
1717
}
1818

1919
// Name returns the name of the function
20-
func (fnCheckExists) Name() string {
21-
return "checkExists"
20+
func (fnExists) Name() string {
21+
return "exists"
2222
}
2323

2424
// Sig returns the function signature
25-
func (fnCheckExists) Sig() (paramTypes []data.Type, isVariadic bool) {
25+
func (fnExists) Sig() (paramTypes []data.Type, isVariadic bool) {
2626
return []data.Type{data.TypeAny, data.TypeString}, false
2727
}
2828

2929
// Eval executes the function
30-
func (fnCheckExists) Eval(params ...interface{}) (interface{}, error) {
30+
func (fnExists) Eval(params ...interface{}) (interface{}, error) {
3131
expression, ok := params[1].(string)
3232
if !ok {
3333
return false, fmt.Errorf("The JSON key/path must be a string")

function/json/checkexists_test.go function/json/exists_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestFnCheckExists(t *testing.T) {
3838
err := json.Unmarshal([]byte(inputCheckExists), &inputJSON)
3939
assert.Nil(t, err)
4040

41-
f := &fnCheckExists{}
41+
f := &fnExists{}
4242
v, err := function.Eval(f, inputJSON, "$.store.book[?(@.price == 12.99)].price[0]")
4343
assert.Nil(t, err)
4444
assert.Equal(t, true, v)
@@ -49,7 +49,7 @@ func TestFnCheckExistsLoop(t *testing.T) {
4949
err := json.Unmarshal([]byte(inputCheckExists), &inputJSON)
5050
assert.Nil(t, err)
5151

52-
f := &fnCheckExists{}
52+
f := &fnExists{}
5353
v, err := function.Eval(f, inputJSON, "$loop.store.book[?(@.price == 22.99)].price[0]")
5454
assert.NotNil(t, err)
5555
assert.Equal(t, false, v)
@@ -60,7 +60,7 @@ func TestFnCheckExistsNegative(t *testing.T) {
6060
err := json.Unmarshal([]byte(inputCheckExists), &inputJSON)
6161
assert.Nil(t, err)
6262

63-
f := &fnCheckExists{}
63+
f := &fnExists{}
6464
v, err := function.Eval(f, inputJSON, "$.store.abc")
6565
assert.NotNil(t, err)
6666
assert.Equal(t, false, v)
@@ -71,7 +71,7 @@ func TestFnCheckExistsEmpty(t *testing.T) {
7171
err := json.Unmarshal([]byte(inputCheckExists), &inputJSON)
7272
assert.Nil(t, err)
7373

74-
f := &fnCheckExists{}
74+
f := &fnExists{}
7575
v, err := function.Eval(f, inputJSON, "$.emptyString")
7676
assert.Nil(t, err)
7777
assert.Equal(t, true, v)

0 commit comments

Comments
 (0)