Skip to content

Commit

Permalink
dont invalidate config if there are extra fields
Browse files Browse the repository at this point in the history
  • Loading branch information
plally committed Feb 3, 2024
1 parent ad4d69c commit acef033
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lua/includes/modules/schemavalidator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ end

---@class SchemaTypeObject: SchemaType
---@field ValidateField fun(self: SchemaTypeObject, key: any, value: any): (boolean, string)
---@field HasField fun(self: SchemaTypeObject, key: any): boolean
---@field fields { [string]: SchemaType }

---@param tbl { [string]: SchemaType }
Expand All @@ -90,6 +91,9 @@ function SchemaValidator.Object( tbl )
Optional = function( self )
return SchemaValidator.Optional( self )
end,
HasField = function( self, key )
return self.fields[key] ~= nil
end,
ValidateField = function( self, key, value )
local fieldType = self.fields[key]
if not fieldType then
Expand Down
8 changes: 6 additions & 2 deletions lua/mapvote/server/modules/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ end

function MapVote.MergeConfig( conf )
for k, v in pairs( conf ) do
local hasField = MapVote.configSchema:HasField( k )
local valid, reason = MapVote.configSchema:ValidateField( k, v )
if not valid then
if not hasField then
print( "MapVote MergeConfig config has extra field: " .. k )
elseif not valid then
MapVote.configIssues = {}
print( "MapVote MergeConfig config is invalid: " .. reason )
return reason
else
MapVote.config[k] = v
end
MapVote.config[k] = v
end
end

Expand Down

0 comments on commit acef033

Please sign in to comment.