Hi! First of all, APISimulator is a very interesting project and I am checking its features to see if I can integrate it into a new project that I am part of!
I am having an issue when using the CSV data provided in the simlet's YAML configuration: I can't match/retrieve the first (data) line of the CSV.
It seems the first data line is ignored when matching the results.
#----------------------------------------------------------------------
# Simlet-specific configuration.
#----------------------------------------------------------------------
simlet: read-products-csv
ProductID:
is: parameter
from: uriPathPattern
pattern: "/v1.2/product/{ProductID}/**"
# Parameter names must match the name of the columns in the CSV data
ProductColor:
is: parameter
from: uriPathPattern
pattern: "/v1.2/product/*/{Color}/*"
# Parameter names must match the name of the columns in the CSV data
ProductSize:
is: parameter
from: uriPathPattern
pattern: "/v1.2/product/*/*/{Size}"
ProductData:
is: parameter
from: csv
# The first row in the CSV file is expected to contain unique column names
# with no spaces or special characters in the names other than underscore.
# A column value that contains a comma or double quote(s) is to be surrounded
# by double quotes. Each double quote inside of a column value is to be escaped
# with another double quote. This is what file export to CSV from MS Excel does
data: `
ProductID,ProductCategory,ProductSubcategory,ProductName,ProductColor,ProductSize,ProductSKU,Original_Price,Sale_Price
2706414,Men,Hoodies & Sweatshirts,Fleece Pullover Hoodie,Black Charcoal,S,769409213,55.00,39.99
2706414,Men,Hoodies & Sweatshirts,Fleece Pullover Hoodie,Black Charcoal,M,769413463,55.00,39.99
2706414,Men,Hoodies & Sweatshirts,Fleece Pullover Hoodie,Black Charcoal,L,769413609,55.00,39.99
2706414,Men,Hoodies & Sweatshirts,Fleece Pullover Hoodie,Black Charcoal,XL,769413531,55.00,39.99
2706414,Men,Hoodies & Sweatshirts,Fleece Pullover Hoodie,Black Charcoal,XXL,769413579,55.00,39.99
2706414,Men,Hoodies & Sweatshirts,Fleece Pullover Hoodie,Solid Gray,S,769417959,55.00,35.95
2706414,Men,Hoodies & Sweatshirts,Fleece Pullover Hoodie,Solid Gray,M,769417966,55.00,36.96
2706414,Men,Hoodies & Sweatshirts,Fleece Pullover Hoodie,Solid Gray,L,769413623,55.00,37.97
2706414,Men,Hoodies & Sweatshirts,Fleece Pullover Hoodie,Solid Gray,XL,769413692,55.00,38.98
2706414,Men,Hoodies & Sweatshirts,Fleece Pullover Hoodie,Solid Gray,XXL,769413678,55.00,39.99
2592228,Men,Hoodies & Sweatshirts,Full-Zip Hooded Fleece Jacket,Dark Gray,S,769458440,65.00,52.00
2592228,Men,Hoodies & Sweatshirts,Full-Zip Hooded Fleece Jacket,Dark Gray,M,769458501,65.00,52.00
2592228,Men,Hoodies & Sweatshirts,Full-Zip Hooded Fleece Jacket,Dark Gray,L,769458327,65.00,52.00
2592228,Men,Hoodies & Sweatshirts,Full-Zip Hooded Fleece Jacket,Dark Gray,XL,769458303,65.00,52.00
2592228,Men,Hoodies & Sweatshirts,Full-Zip Hooded Fleece Jacket,Dark Gray,XXL,769458426,65.00,52.00
6218877,Children,Shoes,The "Rockets",White,4,669032116,35.59,31.99
`
# List of keys from parameters to use in querying the CSV data.
# A parameter as key may appear more than once in the list.
# Parameter names must match the column names in the CSV data
keys:
- ProductID
- ProductColor
- ProductSize
request:
- method: GET
- where: uriPathPattern
matches: "/v1.2/product/{id}/{color}/{size}"
- where: parameter
named: ProductData
exists: true
response:
from: template
template: Simula
status: 200
headers:
- "Content-Type: application/json; charset=UTF-8"
body: `
{
"product": {
"id": "${ ProductData['ProductID'] }",
"sku": "${ ProductData['ProductSKU'] }",
"name": "${ jsonEncode( ProductData['ProductName'] ) }",
"category": "${ ProductData['ProductCategory'] }",
"subCategory": "${ ProductData['ProductSubcategory'] }",
"color": "${ ProductData['ProductColor'] }",
"size": "${ ProductData['ProductSize'] }",
"orig_price": ${ ProductData['Original_Price'] },
"sale_price": ${ ProductData['Sale_Price'] }
}
}
`
4.1. Checking for the product in the first line - Result: 404 Not Found
curl --location 'http://localhost:6090/v1.2/product/2706414/Black Charcoal/S'
curl --location 'http://localhost:6090/v1.2/product/2706414/Black Charcoal/M'
If I change the places of the "S" product to the second line, and the "M" product to the first line, then the "M" (medium) product is the one that is not matched:
ProductID,ProductCategory,ProductSubcategory,ProductName,ProductColor,ProductSize,ProductSKU,Original_Price,Sale_Price
2706414,Men,Hoodies & Sweatshirts,Fleece Pullover Hoodie,Black Charcoal,M,769413463,55.00,39.99
2706414,Men,Hoodies & Sweatshirts,Fleece Pullover Hoodie,Black Charcoal,S,769409213,55.00,39.99
So, the behavior seems tied to the first data line of the csv configuration.
2023-11-27T14:27:50.284+0000|INFO|10|main|[+--------------------------+]
2023-11-27T14:27:50.285+0000|INFO|10|main|[| A P I S i m u l a t o r |]
2023-11-27T14:27:50.285+0000|INFO|10|main|[+--------------------------+]
2023-11-27T14:27:50.291+0000|INFO|10|main|[API Simulator initialization in progress...]
2023-11-27T14:27:50.291+0000|INFO|10|main|[API Simulator: {java version:"11.0.19+7", jvm name:"OpenJDK 64-Bit Server VM", jvm version:"11.0.19+7", jvm pid:10}]
2023-11-27T14:27:50.291+0000|INFO|10|main|[API Simulator: implementation {title:"API Simulator",version:"1.11"}]
2023-11-27T14:27:50.291+0000|INFO|10|main|[API Simulator: args=[-c, /apisimulator/apisimulator-http-1.11/config, -s, /templates/simlets, /templates]]
2023-11-27T14:27:50.305+0000|INFO|10|main|[Loading configuration from '/apisimulator/apisimulator-http-1.11/config/apisim.yaml'...]
2023-11-27T14:27:50.338+0000|INFO|10|main|[Loaded admin configuration]
2023-11-27T14:27:50.342+0000|INFO|10|main|[Loaded simulator configuration]
2023-11-27T14:27:50.346+0000|INFO|10|main|[Loaded simulation configuration]
2023-11-27T14:27:50.374+0000|INFO|10|main|[Loaded 2 simlets in 69 ms]
2023-11-27T14:27:50.376+0000|INFO|10|main|[Loading configuration from '/templates/apisim.yaml'...]
2023-11-27T14:27:51.410+0000|INFO|10|main|[Loaded 1 simlet in 1034 ms]
2023-11-27T14:27:51.411+0000|INFO|10|main|[Loading simlets from '/templates/simlets'...]
2023-11-27T14:27:51.413+0000|INFO|10|main|[Loaded 0 simlets in 1 ms]
2023-11-27T14:27:51.783+0000|INFO|10|API-Simulator-Boss-1-1|[API Simulator Server is listening on 0.0.0.0:6090]
2023-11-27T14:27:51.783+0000|INFO|10|main|[API Simulator started]
2023-11-27T14:27:51.802+0000|INFO|10|AdminServer-Boss-6-1|[Admin HTTP Server is listening on 0.0.0.0:6190]