pact-foundation / pact-reference

Reference implementations for the pact specifications
https://pact.io
MIT License
91 stars 46 forks source link

fix: Fallback to always generate a value to fix 'Could not generate a random TYPE from null' #335

Closed tienvx closed 8 months ago

tienvx commented 8 months ago

Remove the errors similar to Could not generate a random decimal from null.

It then allow to use integration json like this:

{
    "pact:matcher:type": "null",
    "pact:generator:type": "RandomDecimal"
}

This change is for implementing compatibility suite in pact-php (and probably other languages that use FFI calls as well).

For more information, please take a look at this discussion

rholshausen commented 8 months ago

While this fixes the issue above, it regresses behavior of the random integer and decimal generators.

What the previous code was doing was generating either a number or a string depending on the type of the value. With this change, it will always now generate a string value.

For instant, with input JSON:

{
  "value": 100
}

It will now generate:

{
  "value": "3498499"
}

and not

{
  "value": 3498499
}

I think the fix is to only change the fallback to generate either type of value.

tienvx commented 8 months ago

I updated the code follow your suggestion

rholshausen commented 8 months ago

Nice!