From acef0338ebb8d36f55e146eb4a7fd52477e42614 Mon Sep 17 00:00:00 2001 From: Pierce Date: Sat, 3 Feb 2024 15:36:51 -0500 Subject: [PATCH] dont invalidate config if there are extra fields --- lua/includes/modules/schemavalidator.lua | 4 ++++ lua/mapvote/server/modules/config.lua | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lua/includes/modules/schemavalidator.lua b/lua/includes/modules/schemavalidator.lua index 670c499..68804a4 100644 --- a/lua/includes/modules/schemavalidator.lua +++ b/lua/includes/modules/schemavalidator.lua @@ -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 } @@ -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 diff --git a/lua/mapvote/server/modules/config.lua b/lua/mapvote/server/modules/config.lua index d9be50d..62ef262 100644 --- a/lua/mapvote/server/modules/config.lua +++ b/lua/mapvote/server/modules/config.lua @@ -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