11
11
<!-- /top-badges -->
12
12
13
13
<!-- rules-counter -->
14
- [ ![ Static Badge] ( https://img.shields.io/badge/Rules-366 -green?label=Total%20number%20of%20rules&labelColor=darkgreen&color=gray )] ( schema-examples/full.yml )
14
+ [ ![ Static Badge] ( https://img.shields.io/badge/Rules-367 -green?label=Total%20number%20of%20rules&labelColor=darkgreen&color=gray )] ( schema-examples/full.yml )
15
15
[ ![ Static Badge] ( https://img.shields.io/badge/Rules-153-green?label=Cell%20rules&labelColor=blue&color=gray )] ( src/Rules/Cell )
16
16
[ ![ Static Badge] ( https://img.shields.io/badge/Rules-206-green?label=Aggregate%20rules&labelColor=blue&color=gray )] ( src/Rules/Aggregate )
17
- [ ![ Static Badge] ( https://img.shields.io/badge/Rules-7 -green?label=Extra%20checks&labelColor=blue&color=gray )] ( #extra-checks )
18
- [ ![ Static Badge] ( https://img.shields.io/badge/Rules-32/54/13 -green?label=Plan%20to%20add&labelColor=gray&color=gray )] ( tests/schemas/todo.yml )
17
+ [ ![ Static Badge] ( https://img.shields.io/badge/Rules-8 -green?label=Extra%20checks&labelColor=blue&color=gray )] ( #extra-checks )
18
+ [ ![ Static Badge] ( https://img.shields.io/badge/Rules-32/54/9 -green?label=Plan%20to%20add&labelColor=gray&color=gray )] ( tests/schemas/todo.yml )
19
19
<!-- /rules-counter -->
20
20
21
21
A console utility designed for validating CSV files against a strictly defined schema and validation rules outlined
@@ -232,7 +232,6 @@ columns:
232
232
count: 10
233
233
234
234
` ` `
235
-
236
235
<!-- /readme-sample-yml -->
237
236
238
237
@@ -242,19 +241,33 @@ In the [example Yml file](schema-examples/full.yml) you can find a detailed desc
242
241
It's also covered by tests, so it's always up-to-date.
243
242
244
243
**Important notes**
244
+
245
245
* I have deliberately refused typing of columns (like `type: integer`) and replaced them with rules,
246
246
which can be combined in any sequence and completely at your discretion.
247
247
This gives you great flexibility when validating CSV files.
248
- * All fields (unless explicitly stated otherwise) are optional, and you can choose not to declare them. Up to you.
249
- * If you specify a wrong rule name, non-existent values (which are not in the example below) or a different variable
250
- type for any of the options, you will get a schema validation error. At your own risk, you can use the `skip-schema`
248
+ * All options (unless explicitly stated otherwise) are optional, and you can choose not to declare them. Up to you.
249
+ * If you specify a wrong rule name, non-existent values (which are not in the example below) or a different variable
250
+ type for any of the options, you will get a schema validation error. At your own risk, you can use the `-- skip-schema`
251
251
option to avoid seeing these errors and use your keys in the schema.
252
-
252
+ * All rules except `not_empty` ignored for empty strings (length 0). If the value must be non-empty,
253
+ use `not_empty : true` as extra rule. Keep in mind that a space (` `) is also a character. In this case the string
254
+ length
255
+ will be `1`. If you want to avoid such situations, add the `is_trimmed : true` rule.
256
+ * All rules don't depend on each other. They know nothing about each other and cannot influence each other.
257
+ * You can use the rules in any combination. Or not use any of them. They are grouped below simply for ease of navigation
258
+ and reading.
259
+ * If you see the value for the rule is `is_some_rule: true` - that's just an enable flag. In other cases, these are rule
260
+ parameters.
261
+ * The order of rules execution is the same as in the schema. But in reality it will only change the order of errors in
262
+ the report.
263
+ * Most of the rules are case-sensitive. Unless otherwise specified.
264
+ * As backup plan, you always can use the `regex` rule. But it is much more reliable to use clear combinations of rules.
265
+ That way it will be more obvious what went wrong.
253
266
254
267
Below you'll find the full list of rules and a brief commentary and example for context.
255
268
This part of the readme is also covered by autotests, so these code are always up-to-date.
256
269
257
- In any unclear situation, look into it first.
270
+ In any unclear situation, look into it first ;)
258
271
259
272
<!-- full-yml -->
260
273
` ` ` yml
@@ -265,7 +278,7 @@ In any unclear situation, look into it first.
265
278
name: CSV Blueprint Schema Example # Name of a CSV file. Not used in the validation process.
266
279
description: | # Any description of the CSV file. Not used in the validation process.
267
280
This YAML file provides a detailed description and validation rules for CSV files
268
- to be processed by JBZoo/Csv- Blueprint tool. It includes specifications for file name patterns,
281
+ to be processed by CSV Blueprint tool. It includes specifications for file name patterns,
269
282
CSV formatting options, and extensive validation criteria for individual columns and their values,
270
283
supporting a wide range of data validation rules from basic type checks to complex regex validations.
271
284
This example serves as a comprehensive guide for creating robust CSV file validations.
@@ -298,26 +311,17 @@ structural_rules: # Here are default values.
298
311
# This will not affect the validator, but will make it easier for you to navigate.
299
312
# For convenience, use the first line as a header (if possible).
300
313
columns:
301
- - name: Column Name (header) # Any custom name of the column in the CSV file (first row). Required if "csv_structure .header" is true.
314
+ - name: Column Name (header) # Any custom name of the column in the CSV file (first row). Required if "csv .header" is true.
302
315
description: Lorem ipsum # Description of the column. Not used in the validation process.
303
316
example: Some example # Example of the column value. Schema will also check this value on its own.
304
317
305
- # Important notes about the validation rules.
306
- # 1. All rules except "not_empty" ignored for empty strings (length 0).
307
- # If the value must be non-empty, use "not_empty" as extra rule!
308
- # 2. All rules don't depend on each other. They are independent.
309
- # They know nothing about each other and cannot influence each other.
310
- # 3. You can use the rules in any combination. Or not use any of them.
311
- # They are grouped below simply for ease of navigation and reading.
312
- # 4. If you see the value for the rule is "true" - that's just an enable flag.
313
- # In other cases, these are rule parameters.
314
- # 5. The order of rules execution is the same as in the schema. But it doesn't matter.
315
- # The result will be the same in any order.
316
- # 6. Most of the rules are case-sensitive. Unless otherwise specified.
317
- # 7. As backup plan, you always can use the "regex" rule. ON YOUR OWN RISK!
318
+ # If the column is required. If true, the column must be present in the CSV file. If false, the column can be missing in the CSV file.
319
+ # So, if you want to make the column optional, set this value to false, and it will validate the column only if it is present.
320
+ # By default, the column is required. It works only if "csv.header" is true and "structural_rules.allow_extra_columns" is false.
321
+ required: true
318
322
319
323
####################################################################################################################
320
- # Data validation for each(!) value in the column.
324
+ # Data validation for each(!) value in the column. Please, see notes in README.md
321
325
# Every rule is optional.
322
326
rules:
323
327
# General rules
@@ -487,7 +491,7 @@ columns:
487
491
488
492
# Check if the column is sorted in a specific order.
489
493
# - Direction: ["asc", "desc"].
490
- # - Method: ["natural", "regular", "numeric", "string"].
494
+ # - Method: ["natural", "regular", "numeric", "string"].
491
495
# See: https://www.php.net/manual/en/function.sort.php
492
496
sorted : [ asc, natural ] # Expected ascending order, natural sorting.
493
497
@@ -821,7 +825,8 @@ Behind the scenes to what is outlined in the yml above, there are additional che
821
825
<!-- extra-rules -->
822
826
823
827
* With ` filename_pattern ` rule, you can check if the file name matches the pattern.
824
- * Property ` name ` is not defined in a column. If ` csv.header: true ` .
828
+ * Checks if property ` name ` is not defined in a column. Only if ` csv.header: true ` .
829
+ * If property ` required ` is set to ` true ` , the column must must be present in CSV. Only if ` csv.header: true `
825
830
* Check that each row matches the number of columns.
826
831
* With ` strict_column_order ` rule, you can check that the columns are in the correct order.
827
832
* With ` allow_extra_columns ` rule, you can check that there are no extra columns in the CSV file.
@@ -1284,7 +1289,6 @@ It's random ideas and plans. No promises and deadlines. Feel free to [help me!](
1284
1289
file name.
1285
1290
1286
1291
* ** Validation**
1287
- * ` required ` flag for the column.
1288
1292
* Multi values in one cell.
1289
1293
* Custom cell rule as a callback. It's useful when you have a complex rule that can't be described in the schema
1290
1294
file.
0 commit comments