CsvValidator optional header column

5 days ago 18
ARTICLE AD BOX

I am using the UK National Archives CSV Validator via the Maven dependency uk.gov.nationalarchives:csv-validator-java-api-1.4.0.jar to validate both the headers and the body of CSV/txt files.

I am using a .csvs file as a schema validation declaration containing the following rules:

version 1.1 @separator ',' @totalColumns 2 uuid: notEmpty and regex("validRegex") endDate: empty or validDateTime

I want to make the endDate column entirely optional. This means the file should pass validation whether the endDate column is completely missing from the header and rows, or if it is present but empty or matching a date.

I removed the @totalColumns 2 line and attempted to use the @optional directive in various ways, but all failed with syntax or parsing errors:

endDate: @optional empty or validDateTime

endDate: empty or validDateTime @optional

Placing @optional on the line above the column name

endDate: @optional(empty or validDateTime)

How do I properly declare a column as fully optional (both missing header and missing content) in a .csvs schema file for this library?

Read Entire Article