We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I found some issue about validator It's not check the property is nil before try to get it's properties name and here is reproduce code
{ "$schema": "http://json-schema.org/draft-04/schema", "properties": { "prop_1": { "type": "string" }, "prop_2": { "type": "string" }, "child": { "type": "object", "properties": { "child_prop_1": { "type": "string" } } } }, "required": ["prop1"] }
package restbot_test import ( "fmt" "testing" schema "github.com/lestrrat/go-jsschema" "github.com/lestrrat/go-jsschema/validator" ) type TestSubject struct { Prop1 string `json:"prop_1,omitempty"` Prop2 string `json:"prop_2,omitempty"` Child *TestChildSubject `json:"child,omitempty"` } type TestChildSubject struct { ChildProp1 string `json:"child_prop_1,omitempty"` } func Test_Validator(t *testing.T) { data := TestSubject{ Prop1: "aaa", } schemaFileName := "validate_schema.json" s, err := schema.ReadFile(schemaFileName) if err != nil { t.Fatal(fmt.Errorf("failed to read schema: %s", err)) } v := validator.New(s) if err := v.Validate(data); err != nil { t.Fatal(fmt.Errorf("failed to validate data: %s", err)) } }
And error message
--- FAIL: Test_Validator (0.00s) z:\go\src\booboo-bear.com\restbot\validate_test.go:34: failed to validate data: validator 0xc04210dec0 failed: object property 'child' validation failed: cannot get property names from this value (Kind: invalid) FAIL FAIL booboo-bear.com/restbot 0.479s Error: Tests failed.
The text was updated successfully, but these errors were encountered:
i'm using this code to workaround but i don't how it's affect.
diff --git a/object.go b/object.go index 274ce1f..7d04086 100644 --- a/object.go +++ b/object.go @@ -392,6 +392,8 @@ func (o *ObjectConstraint) Validate(v interface{}) (err error) { out = mv.Call(nil) pval = out[0] } + case (pval.Kind() == reflect.Ptr || pval.Kind() == reflect.Interface) && pval.IsNil(): + // If we got nil, we're done for default: // Everything else, we have *something* propExists = true
Sorry, something went wrong.
No branches or pull requests
I found some issue about validator It's not check the property is nil before try to get it's properties name and here is reproduce code
And error message
The text was updated successfully, but these errors were encountered: