File tree Expand file tree Collapse file tree 3 files changed +43
-6
lines changed Expand file tree Collapse file tree 3 files changed +43
-6
lines changed Original file line number Diff line number Diff line change 11OR_EXEC ?= $(shell which openresty)
22LUA_JIT_DIR ?= $(shell ${OR_EXEC} -V 2>&1 | grep prefix | grep -Eo 'prefix=(.* ?) /nginx' | grep -Eo '/.*/')luajit
33LUAROCKS_VER ?= $(shell luarocks --version | grep -E -o "luarocks [0-9]+.")
4- LUA_PATH ?= $(shell lua -e "print(package.path) ")
5- LUA_CPATH ?= $(shell lua -e "print(package.cpath) ")
4+ LUA_PATH ?= $(shell luajit -e "print(package.path) ")
5+ LUA_CPATH ?= $(shell luajit -e "print(package.cpath) ")
66
77
88# ## help: Show Makefile rules.
@@ -16,12 +16,12 @@ help:
1616# ## dev: Create a development ENV
1717.PHONY : dev
1818dev :
19- ifeq ($(UNAME ) ,Darwin )
19+ ifeq ($(LUAROCKS_VER ) ,luarocks 3. )
2020 luarocks install --lua-dir=$(LUA_JIT_DIR) rockspec/jsonschema-master-0.rockspec --only-deps
21- else ifneq ($(LUAROCKS_VER),'luarocks 3.')
22- luarocks install rockspec/jsonschema-master-0.rockspec --only-deps
21+ luarocks install --lua-dir=$(LUA_JIT_DIR) luaposix
2322else
24- luarocks install --lua-dir=/usr/local/openresty/luajit jsonschema-master-0.rockspec --only-deps
23+ luarocks install rockspec/jsonschema-master-0.rockspec --only-deps
24+ luarocks install luaposix
2525endif
2626
2727
Original file line number Diff line number Diff line change @@ -653,6 +653,13 @@ generate_validator = function(ctx, schema)
653653 end
654654
655655 ctx :stmt (' end' ) -- if object
656+
657+ if schema .required and # schema .required == 0 then
658+ -- return false if the input data is not empty
659+ ctx :stmt (sformat (' if %s ~= 1 then' , datakind ))
660+ ctx :stmt ( ' return false, "the input data should be an empty table"' )
661+ ctx :stmt ( ' end' )
662+ end
656663 end
657664
658665 -- array checks
Original file line number Diff line number Diff line change @@ -28,4 +28,34 @@ if not conf.rule then
2828 ngx .say (" fail: missing default value" )
2929 return
3030end
31+
32+ rule = {
33+ type = " object" ,
34+ properties = {
35+ username = { type = " string" },
36+ passwd = { type = " string" },
37+ },
38+ oneOf = {
39+ {required = {" username" , " passwd" }},
40+ {required = {}}
41+ }
42+ }
43+
44+ validator = jsonschema .generate_validator (rule )
45+
46+ local ok , err = validator ({passwd = " passwd" , username = " name" })
47+ if not ok then
48+ ngx .say (" fail: check default value: " , err )
49+ end
50+
51+ ok , err = validator ({})
52+ if not ok then
53+ ngx .say (" fail: check default value: " , err )
54+ end
55+
56+ ok = validator ({passwd = " passwd" })
57+ if ok then
58+ ngx .say (" fail: expect to fail" )
59+ end
60+
3161ngx .say (" passed: table value as default value" )
You can’t perform that action at this time.
0 commit comments