I know this may sound a bit weird, but I have an u...
# pact-jvm
d
I know this may sound a bit weird, but I have an use case where a response must only return a decimal that is like
0.12
,
0.35
or
0.5
etc. Essentially, it is "percentage" with maximal 2 digits after the separator. How would I add this to my contract?
decimalType
allows all kinds of decimals, such as
-1234.23456
stringMatcher
will make it a string type instead of decimal Is there maybe some more general
matches(...)
which I could then tell the type + a custom regex matching? If not, how could I implement what I need as extension? Any hints? While at it, what about other similar stuff, such as "any positive number"?
u
There was a really old issue for using a format string (similar to how dates work), but there hasn't been anyone asking for it
A regex matcher will work
d
how would that look like? if i use
stringMatcher
it would make it a string, i.e.
"123"
instead of a number type in json
123
in the generated json request/response. I need it to be a number type, but still want to have a matcher on it - didnt find any method for that at first glance
r
Oh, I see the problem, there is no way with the DSL to configure a regex with a number value.
Can you raise a GitHub issue for that at https://github.com/pact-foundation/pact-jvm
👍 1
t
Essentially, it is "percentage" with maximal 2 digits after the separator.
This is an aside, but personally I would do this with a string instead of a number. That way I would have full control, rather than it come down to how the number was serialised by whatever JSON library wrote it.
d
agreed. unfortunately, i dont have control over it. but yeah, the actual issue expands to stuff like "test that a number type is positive", which sounds like a valid use case