-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
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
Add JSON Schema validation to Lua #23
Conversation
What is the reason for not being able to use the Lua library for this? Is it using a dynamic shared object? |
from a quick review of ljsonschema, i saw:
|
lualibs/go/jsonschema/api.go
Outdated
|
||
func unmarshal(s string) (interface{}, error) { | ||
decoder := json.NewDecoder(strings.NewReader(s)) | ||
decoder.UseNumber() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this being done? Does Lua's cjson decode numbers as string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy/pasta error.
lualibs/go/jsonschema/api.go
Outdated
if err := decoder.Decode(&doc); err != nil { | ||
return nil, err | ||
} | ||
if t, _ := decoder.Token(); t != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this not always return an error == io.EOF?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, we're expecting a nil response. i'll change to check that the error is actually io.EOF
|
||
l.Push(lua.LFalse) | ||
l.Push(lua.LString(err.Error())) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the code missing a return here?
New 'go.jsonschema' module, exports two functions: compile( <schematext> [, <draftname>] ) Where <schematext> is a string containing a JSONSchema and <draftname> is one of "draft4", "draft6", "draft7", "draft2019" or "draft2020". If omitted, "draft4" is assumed. If successful, a compiled schema object will be returned, on error it returns nil and an error message. validate( <schema>, <input> ) Where <schema> is a compiled schema object and <input> is some JSON text. If succesful, returns a single true value. If the validation failes, returns false and a descriptive error. On any other error, returns nil and an error message.
195f065
to
e9f787f
Compare
e9f787f
to
aa26d42
Compare
New 'go.jsonschema' module, exports two functions:
compile( <schematext> [, <draftname>] )
Where
<schematext>
is a string containing a JSONSchema and<draftname>
is one of "draft4", "draft6", "draft7", "draft2019" or "draft2020".
If omitted, "draft4" is assumed.
If successful, a compiled schema object will be returned, on error it
returns nil and an error message.
validate( <schema>, <input> )
Where
<schema>
is a compiled schema object and<input>
is some JSONtext.
If succesful, returns a single true value. If the validation failes,
returns false and a descriptive error. On any other error, returns nil
and an error message.