Skip to content

Commit 5311075

Browse files
committed
change: throw more information only in OpenResty land.
1 parent 1319a80 commit 5311075

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ fast: it works by transforming the given schema into a pure Lua function
1111
on-the-fly. Work is currently in progress to make it as JIT-friendly as
1212
possible.
1313

14-
This project base on [ljsonschema](https://github.com/jdesgats/ljsonschema).
14+
This project base on [ljsonschema](https://github.com/jdesgats/ljsonschema). Many thanks to the author `jdesgats` for the perfect work. The re-implementation is we need to support OpenResty env,
15+
and we can use more optimization methods only available in OpenResty, which can make it run faster in OpenResty land.
1516

1617
Installation
1718
------------

lib/jsonschema.lua

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
local store = require 'jsonschema.store'
2-
local json_encode = require("cjson.safe").encode
32
local loadstring = loadstring
43
local tostring = tostring
54
local pairs = pairs
@@ -16,9 +15,13 @@ local string = string
1615

1716
-- default null token
1817
local default_null = nil
18+
local json_encode
1919
do
20-
local ok, cjson = pcall(require, 'cjson')
21-
if ok then default_null = cjson.null end
20+
local ok, cjson = pcall(require, 'cjson.safe')
21+
if ok then
22+
default_null = cjson.null
23+
json_encode = cjson.encode
24+
end
2225
end
2326

2427
local tab_nkeys = nil
@@ -851,7 +854,7 @@ generate_validator = function(ctx, schema)
851854
local op = i == lasti and '' or ' or'
852855
local validator = ctx:validator({ 'anyOf', tostring(i-1) }, subschema)
853856
ctx:stmt(sformat(' %s(%s)', validator, ctx:param(1)), op)
854-
if type(subschema) == "table" and subschema.required then
857+
if json_encode and type(subschema) == "table" and subschema.required then
855858
local str = json_encode(subschema.required)
856859
if str then
857860
tab_insert(requires, str)

0 commit comments

Comments
 (0)