Closed MarcoMartins86 closed 1 year ago
@MarcoMartins86
If you want to return something like {"A":"A6408"}
, a better approach would be to generate a json with only the value generated.
Like:
var responseBuilder = Response.Create()
.WithBodyAsJson(new
{
A = "{{Xeger.Generate \"[A[0-9]{3}[1-9]\"}}"
})
.WithTransformer();
@StefH Thank you for your reply, in reality, I wanted something more similar to this:
"{[\"]A[\"]:[\"]A[0-9]{3}[1-9][\"]}|{[\"]B[\"]:[\"]B[0-9]{3}[1-9][\"]}"
Which will result in {"A":"A6408"}
or {"B":"B6408"}
, the JSON property must be the start of the JSON value.
@StefH While debugging I had a better understanding of the parsing rules and noticed what I was doing wrong, I needed to add single quotes for the Xeger argument to be read as a LiteralExpressionToken, otherwise, it would be read as a WordExpressionToken and it would be split into two arguments because of the closing }
in {3}
.
Conclusion: "{{Xeger.Generate '{[\"]A[\"]:[\"]A[0-9]{3}[1-9][\"]}' }}"
works as expected.
I will close this, thank you again.
Describe the bug
Calling
or calling
Returns
}}
Calling Fare directly
Returns (1 example)
{"A":"A6408"}
Expected behavior:
It should return the same value.
Test to reproduce
Other related info
I'm using Wiremock.Net and caught this while creating a stub that I would like to do something like this:
"{[\"]A[\"]:[\"]A[0-9]{3}[1-9][\"]}|{[\"]B[\"]:[\"]B[0-9]{3}[1-9][\"]}"