Repository navigation
v0.20.0: Realistic mock data, with rules and --explain
What's new
Generated rows that agree with each other
Each column used to be generated on its own, so a Fiori app on mock data showed an order in CHF with items in EUR, a city in Vienna with a country of Netherlands, a total unrelated to its items, and an order shipped months before it was placed. Now a row's columns come from one place and one product, and an order's items agree with it:
PurchaseOrderId;Supplier;CompanyCode;OrderDate;Status;Currency;TotalAmount
4500000002;Stark Manufacturing;1810;2025-04-23;Completed;JPY;552.74
PurchaseOrderId;ItemPosition;Material;Quantity;Unit;NetPrice;Currency
4500000002;00010;Hex Bolt M8;44.000;PC;0.89;JPY
4500000002;00020;Hydraulic Oil;44.312;L;11.59;JPY
- A row's city, postal code (in its country's format), region, country, currency and company code come from one location. Its material, unit and price come from one product.
- Pieces are counted and litres measured:
44.000 PC,44.312 L. - The metadata decides which column is an amount's currency or a quantity's unit when it says so: V2's
sap:unitandsap:semantics, V4'sMeasures.ISOCurrencyandMeasures.Unit. - A row's dates are in order: the change, delivery and due dates are later than the creation and order dates. Documents created later have higher numbers. Validity ends are
9999-12-31. - An order's items take its currency, company code and plant, and are numbered by 10 (
00010,00020). The order's total is the sum of its items. - No more humanized names cut short: a 4-character
Extensionused to beExte, and is now 4 digits.
SAP's number ranges, built in
Standard SAP field names get SAP's standard ranges, by their RAP names and their DDIC names alike. Purchase orders (PurchaseOrder, Ebeln) are 4500000001, sales orders 0000000001, suppliers 17300001, customers 17100001, materials TG01. A key named ID follows its entity type's name, so A_PurchaseOrderType.ID is a purchase order number. Suppliers and customers get a number only where the column is ID-sized: a 100-character Supplier keeps its company name.
Change a column in config.json
When a column is still off, a mock section in the service's config.json changes it. The value's shape is the rule:
{
"mock": {
"PurchaseOrderSet.Status": ["Open", "Open", "Approved"],
"PurchaseOrderSet.ZzProject": "PRJ-####",
"TotalAmount": "100..50000",
"Currency": "EUR"
}
}#s are a running number, .. a range of numbers or dates, a list is picked from (a value repeated is more likely), and anything else is a constant. "Set.Property" is for one entity set, "Property" for every set that has it, and "Address/City" for a complex property's member. "extends": "../shared/config.json" shares rules, and operations, across services.
A rule that doesn't fit the model stops the start, with every mistake listed and how to fix it:
/models/MySrv/config.json: 2 mock rules that don't fit the model:
mock "PurchaseOrderSet.Staus": PurchaseOrderSet has no property Staus. Did you mean "Status"?
mock "PurchaseOrderSet.Currency": "EURO" is 4 long, MaxLength is 3
--explain proposes the rules
At startup, the server says when generated columns are still on filler values:
3 properties use filler values: add --explain to see them, and what to put in config.json
npx odata-prova ./MySrv --explain lists them, with their label and a sample, and a mock block to paste and edit:
3 properties use filler values:
Employees.Extension "Extension" Extension 1
Invoices.CustomerID "Customer ID" 703510
Orders_Qries.CustomerID "Customer ID" 292111
To change them, add to config.json:
"mock": {
"Employees.Extension": ["...", "..."],
"Invoices.CustomerID": ["...", "..."],
"Orders_Qries.CustomerID": ["...", "..."]
}
--explain all shows how every property is generated, and which rule or file decides it.
--write-data on the main command
npx odata-prova ./MySrv --write-data writes the generated rows to data/, to edit them, following the config.json rules, so nobody has to remember a second command. odata-prova-mock-data still works, and follows the rules too.
Upgrading
- Generated rows differ from 0.19.0: other values, dates and amounts. Tests that compare generated values will see diffs. To keep the old rows, write them to files with 0.19.0:
npx -p odata-prova@0.19.0 odata-prova-mock-data ./MySrv. - Keys in SAP's ranges change: a generated
PurchaseOrderIdof0000000001is now4500000001, and a new draft gets the number after the highest,4500000021. Bookmarks and test URLs with the old keys answer 404. - With
--persist, the saved rows are kept. The new ones appear after--persist-reset, which also drops your writes. - A
config.jsonwith amocksection that doesn't fit the model now stops the start. Mistakes inconfig.jsonprint without a stack trace. - The server prints one more line at startup when generated columns are on filler values.
Install
npx odata-prova@0.20.0 ./MySrv
docker run -p 3000:3000 -v "$PWD/MySrv:/models/MySrv:ro" ghcr.io/jaravan/odata-prova:0.20.0Details: Mock data, Changing a column, Rule values, SAP's field names.