valid-csv-header
Rule Details
To provide your database with initial data, you can use CSV files. Their filenames are expected to match fully qualified names of respective entity definitions in your CDS models and their content is standard CSV content with the column titles corresponding to declared element names. This rule ensures that the header of the CSV file matches the column names of the entity definition.
Examples
Let's consider the following model definition:
cds
namespace sap.capire.bookshop;
entity Books {
key ID : Integer;
@mandatory title : localized String(111);
@mandatory author : Association to Authors;
}
entity Authors {
key ID : Integer;
@mandatory name : String(111);
books : Association to many Books on books.author = $self;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
✅ Correct example
The following example shows a correct CSV file header that matches the column names of the entity definition:
csv
ID;title;author_ID
201;Wuthering Heights;101
207;Jane Eyre;107
1
2
3
2
3
❌ Incorrect example
In the next example, there's a typo in the header of the CSV file. The column name title
is misspelled as tile
, so the rule reports a warning:
csv
ID;tile;author_ID
201;Wuthering Heights;101
207;Jane Eyre;107
1
2
3
2
3
Version
This rule was introduced in @sap/eslint-plugin-cds 2.3.0
.