mirror of
https://github.com/frosch95/SmartCSV.fx.git
synced 2026-04-11 13:38:23 +02:00
Updated Validation Configuration (markdown)
@@ -1,98 +1,67 @@
|
||||
# Validation Configuration
|
||||
The configuration file for validations is written in JSON. Each file has two sections.
|
||||
The configuration file for validations is a subset of [JSON Table Schema](http://specs.frictionlessdata.io/json-table-schema/ "JSON Table Schema").
|
||||
|
||||
{
|
||||
"headers" : {
|
||||
...
|
||||
},
|
||||
Full support of the standard is planned in future.
|
||||
|
||||
"columns" : {
|
||||
...
|
||||
}
|
||||
}
|
||||
I will refer to the differences or limitations to the defined standard in this wiki page.
|
||||
|
||||
## header section
|
||||
In the header section a list of headers are defined. The CSV file should have the same headers in the same order. Otherwise the validation fails.
|
||||
## Types
|
||||
Read all about the possible [types](http://specs.frictionlessdata.io/json-table-schema/#field-types-and-formats "Types") in the [JSON Table Schema](http://specs.frictionlessdata.io/json-table-schema/ "JSON Table Schema") specification.
|
||||
|
||||
"headers" : {
|
||||
"list": ["COLUMN 1","COLUMN 2","NAME","SOME OTHER COLUMN"]
|
||||
}
|
||||
### supported types
|
||||
|
||||
- string
|
||||
- integer
|
||||
- number
|
||||
- date
|
||||
- datetime
|
||||
- time
|
||||
|
||||
## column section
|
||||
In the column section, each column that should be validated, should have an entry. Columns without the need of validation can be omitted. Each column can have multiple validations and each of them is checked.
|
||||
|
||||
"columns" : {
|
||||
"COLUMN 1": {
|
||||
"integer" : true,
|
||||
"not empty" : true,
|
||||
"maxlength" : 4,
|
||||
"minlength" : 4
|
||||
},
|
||||
|
||||
"COLUMN 2": {
|
||||
"value of" : ["0", "1"]
|
||||
},
|
||||
|
||||
"SOME OTHER COLUMN": {
|
||||
"double" : true
|
||||
}
|
||||
}
|
||||
### not supported types
|
||||
- object
|
||||
- array
|
||||
- duration
|
||||
- geopoint
|
||||
- geojson
|
||||
|
||||
## Available Validations
|
||||
### not empty
|
||||
Read all about the possible [constraints](http://specs.frictionlessdata.io/json-table-schema/#field-constraints "Constraints") in the [JSON Table Schema](http://specs.frictionlessdata.io/json-table-schema/ "JSON Table Schema") specification.
|
||||
|
||||
"not empty" : true
|
||||
### required
|
||||
|
||||
"required" : true
|
||||
|
||||
The cell could not be empty. Otherwise a cell can be empty or has to be valid in combination of the other validations. If an empty cell is not allowed, this validations has to be set!
|
||||
|
||||
### integer
|
||||
### minLength
|
||||
|
||||
"integer" : true
|
||||
|
||||
The value of the cell has to be an Integer based on java.lang.Integer.
|
||||
_(Empty cells are not checked, see not empty validation)_
|
||||
|
||||
### double
|
||||
|
||||
"double" : true
|
||||
|
||||
The value of the cell has to be an Double based on java.lang.Double.
|
||||
_(Empty cells are not checked, see not empty validation)_
|
||||
|
||||
### minlength
|
||||
|
||||
"minlength" : 4
|
||||
"minLength" : 4
|
||||
|
||||
The cell must have at least the given number of characters, in the above example a number of 4.
|
||||
_(Empty cells are not checked, see not empty validation)_
|
||||
|
||||
### maxlength
|
||||
### maxLength
|
||||
|
||||
"maxlength" : 4
|
||||
"maxLength" : 4
|
||||
|
||||
The cell should not have more than the given number of characters, in the above example a number of 4.
|
||||
_(Empty cells are not checked, see not empty validation)_
|
||||
|
||||
### value of
|
||||
### enum
|
||||
|
||||
"value of" : ["0", "1", "TWO", "SOME OTHER VALUE"]
|
||||
"enum" : ["0", "1", "TWO", "SOME OTHER VALUE"]
|
||||
|
||||
The value must be one of the values defined in a list of strings.
|
||||
_(Empty cells are not checked, see not empty validation)_
|
||||
|
||||
### date
|
||||
### date, datetime, time
|
||||
|
||||
"date" : "yyyyMMdd"
|
||||
"datetime" : "yyyyMMdd hh:mm"
|
||||
"time" : "hh:mm"
|
||||
|
||||
The value has to be a date in the given format. The format is defined for java.text.SimpleDateFormat, check the official documentation of this java class for further information.
|
||||
_(Empty cells are not checked, see not empty validation)_
|
||||
|
||||
### alphanumeric
|
||||
|
||||
"alphanumeric" : true
|
||||
|
||||
The value can only be numerics and alphabetic characters.
|
||||
The value has to be a date in the given format. If the format is given and not prefixed with **fmt:** the format is defined for java.text.SimpleDateFormat, check the official documentation of this java class for further information.
|
||||
If prefixed with fmt: it is defined as standard Python/C strptime [more ...](http://specs.frictionlessdata.io/json-table-schema/#date)
|
||||
_(Empty cells are not checked, see not empty validation)_
|
||||
|
||||
### unique
|
||||
@@ -101,64 +70,83 @@ _(Empty cells are not checked, see not empty validation)_
|
||||
|
||||
The value can only exist once in this column.
|
||||
|
||||
### regexp
|
||||
### pattern
|
||||
|
||||
"regexp" : "[0-9a-zA-Z]*"
|
||||
"pattern" : "[0-9a-zA-Z]*"
|
||||
|
||||
To support more complex validations, the cell can be matched against a regular expression.
|
||||
_(Empty cells are not checked, see not empty validation)_
|
||||
|
||||
### groovy
|
||||
### special groovy constraint
|
||||
|
||||
"groovy" : "value.contains('9') ? true : 'SOME ERROR TEXT'"
|
||||
|
||||
The groovy constraint is not part of the official constraints. The standard does not provide the possibility to define custom constraints, but custom attributes on the field directly. So the groovy
|
||||
If the regexp is not enough, the groovy validation should fit. The groovy expressions can use the variable value which is the String in the cell. It should return a boolean true or the String "true" to be valid, in all other cases the toString representation of the result will be the error message. That also means, that there is no i18n support for the message!
|
||||
_(Empty cells are not checked, see not empty validation)_
|
||||
|
||||
## Full Example
|
||||
{
|
||||
"headers" : {
|
||||
"list": ["COLUMN WITH EXACTLY 4 DIGITS","COLUMN MAYBE EMPTY OR 1 OR 0","COLUMN MAYBE EMPTY OR DOUBLE","UNCHECKED COLUMN","NOT EMPTY AND ONE OF THE COLORS","AN INTEGER AND NOT EMPTY","SOME MANDATORY DATE","OPTIONAL DATE","EMPTY OR STRING STARTS WIDTH ID MINUS"]
|
||||
"fields": [
|
||||
{
|
||||
"name": "COLUMN WITH EXACTLY 4 DIGITS",
|
||||
"type": "integer",
|
||||
"constraints": {
|
||||
"required": true,
|
||||
"minLength": 4,
|
||||
"maxLength": 4
|
||||
}
|
||||
},
|
||||
|
||||
"columns" : {
|
||||
"COLUMN WITH EXACTLY 4 DIGITS": {
|
||||
"integer" : true,
|
||||
"not empty" : true,
|
||||
"maxlength" : 4,
|
||||
"minlength" : 4
|
||||
{
|
||||
"name": "COLUMN MAYBE EMPTY OR 1 OR 0",
|
||||
"type": "string",
|
||||
"constraints": {
|
||||
"enum": [
|
||||
"0","1"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
"COLUMN MAYBE EMPTY OR 1 OR 0": {
|
||||
"value of" : ["0", "1"]
|
||||
{
|
||||
"name": "COLUMN MAYBE EMPTY OR DOUBLE",
|
||||
"type": "number",
|
||||
},
|
||||
|
||||
"COLUMN MAYBE EMPTY OR DOUBLE": {
|
||||
"double" : true
|
||||
{
|
||||
"name": "UNCHECKED COLUMN"
|
||||
},
|
||||
|
||||
"NOT EMPTY AND ONE OF THE COLORS" : {
|
||||
"not empty" : true,
|
||||
"value of" : ["red","green","blue"]
|
||||
{
|
||||
"name": "NOT EMPTY AND ONE OF THE COLORS",
|
||||
"type": "string",
|
||||
"constraints": {
|
||||
"required": true,
|
||||
"enum": [
|
||||
"red","green","blue"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
"AN INTEGER AND NOT EMPTY" : {
|
||||
"not empty" : true,
|
||||
"integer" : true
|
||||
{
|
||||
"name": "AN INTEGER AND NOT EMPTY",
|
||||
"type": "integer",
|
||||
"constraints": {
|
||||
"required": true
|
||||
}
|
||||
},
|
||||
|
||||
"SOME MANDATORY DATE": {
|
||||
"date" : "yyyyMMdd",
|
||||
"not empty" : true
|
||||
{
|
||||
"name": "SOME MANDATORY DATE",
|
||||
"type": "date",
|
||||
"format": "yyyyMMdd",
|
||||
"constraints": {
|
||||
"required": true
|
||||
}
|
||||
},
|
||||
|
||||
"OPTIONAL DATE": {
|
||||
"date" : "yyyyMMdd"
|
||||
{
|
||||
"name": "OPTIONAL DATE TIME",
|
||||
"type": "datetime",
|
||||
"format": "yyyyMMdd hh:mm",
|
||||
},
|
||||
|
||||
"EMPTY OR STRING STARTS WIDTH ID MINUS" : {
|
||||
{
|
||||
"name": "EMPTY OR STRING STARTS WIDTH ID MINUS",
|
||||
"type": "string",
|
||||
"groovy": "value.startsWith('ID-') ? true : 'NOT A CORRECT ID'"
|
||||
}
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user