@@ -420,24 +420,31 @@ proc hasArrayOfFiles*(data: JsonNode;
420420 path: Path ;
421421 context = " " ;
422422 relativeToPath: Path ;
423- errorAnnotation = " " ): bool =
424- if hasArrayOfStrings (data, key, path, context):
425- result = true
426- var processedItems = initHashSet [string ](data[key].len)
427-
428- for item in data[key]:
429- let relativeFilePath = item.getStr ()
430- let absoluteFilePath = relativeToPath / relativeFilePath
431- if fileExists (absoluteFilePath):
432- let itemStr = item.getStr ()
433- if processedItems.containsOrIncl (itemStr):
434- let msg = & " The { q context} array contains duplicate " &
435- & " { q itemStr} values"
423+ errorAnnotation = " " ;
424+ isRequired = true ): bool =
425+ # # Returns true in any of these cases:
426+ # # - `hasArrayOfStrings` returns true for `data[key]`.
427+ # # - `data` lacks the key `key` and `isRequired` is false.
428+ if data.hasKey (key, path, context, isRequired):
429+ if hasArrayOfStrings (data, key, path, context):
430+ result = true
431+ var processedItems = initHashSet [string ](data[key].len)
432+
433+ for item in data[key]:
434+ let relativeFilePath = item.getStr ()
435+ let absoluteFilePath = relativeToPath / relativeFilePath
436+ if fileExists (absoluteFilePath):
437+ let itemStr = item.getStr ()
438+ if processedItems.containsOrIncl (itemStr):
439+ let msg = & " The { q context} array contains duplicate " &
440+ & " { q itemStr} values"
441+ result .setFalseAndPrint (msg, path, annotation = errorAnnotation)
442+ else :
443+ let msg = & " The { q context} array contains value " &
444+ & " { q relativeFilePath} but { q $ absoluteFilePath} could not be found"
436445 result .setFalseAndPrint (msg, path, annotation = errorAnnotation)
437- else :
438- let msg = & " The { q context} array contains value " &
439- & " { q relativeFilePath} but { q $ absoluteFilePath} could not be found"
440- result .setFalseAndPrint (msg, path, annotation = errorAnnotation)
446+ elif not isRequired:
447+ result = true
441448
442449type
443450 ItemCall = proc (data: JsonNode ; context: string ; path: Path ): bool {.nimcall .}
0 commit comments