File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change 11local store = require ' jsonschema.store'
2+ local json_encode = require (" cjson.safe" ).encode
23local loadstring = loadstring
34local tostring = tostring
45local pairs = pairs
@@ -844,14 +845,28 @@ generate_validator = function(ctx, schema)
844845
845846 if schema .anyOf then
846847 local lasti = # schema .anyOf
848+ local requires = {}
847849 ctx :stmt (' if not (' )
848850 for i , subschema in ipairs (schema .anyOf ) do
849851 local op = i == lasti and ' ' or ' or'
850852 local validator = ctx :validator ({ ' anyOf' , tostring (i - 1 ) }, subschema )
851853 ctx :stmt (sformat (' %s(%s)' , validator , ctx :param (1 )), op )
854+ if type (subschema ) == " table" and subschema .required then
855+ local str = json_encode (subschema .required )
856+ if str then
857+ tab_insert (requires , str )
858+ end
859+ end
860+ end
861+
862+ if # requires > 0 then
863+ requires = ' ": " .. ' .. sformat (" %q" , tab_concat (requires , " or " ))
864+ else
865+ requires = ' ""'
852866 end
867+
853868 ctx :stmt (' ) then' )
854- ctx :stmt (' return false, "object matches none of the alternatives" ' )
869+ ctx :stmt (' return false, "object matches none of the requireds" .. ' .. requires )
855870 ctx :stmt (' end' )
856871 end
857872
You can’t perform that action at this time.
0 commit comments