DiUS / pact-consumer-swift

A Swift / ObjeciveC DSL for creating pacts.
MIT License
98 stars 43 forks source link

Is there a way to use expressions into generators? #128

Closed marcelinoagile closed 2 years ago

marcelinoagile commented 2 years ago

Hi, I'm using your library and it works like a charm. The problem is that now I'm trying to add "dynamic" dates to the pact and I can't find the way to do it. Given a pact where the response should be:

{
 "id": "321",
 "start": "today +1 day @ 6 o'clock pm"
}

... my backend colleague is adding the following object to the body using the Pacts Java library: object.datetimeExpression("start", "today +1 day @ 6 o'clock pm", "yyyy-MM-dd'T'HH:mm'Z'");

And the datetime expression generates:

"generators": {
 "body": {
  "$.start": {
   "type": "DateTime",
   "format": "yyyy-MM-dd'T'HH:mm:ss'Z'",
   "expression": "today +1 day @ 6 o'clock pm"
  }
 }
}

But unfortunately I don't find the way to do it using this library.

Could you help me? Thank you in advance.

surpher commented 2 years ago

Seems like your back-end colleague is using Pact-JVM that is generating pact contract spec v3. pact-consumer-swift only supports pact spec v2 which does not handle generators.

andrewspinks commented 2 years ago

@marcelinoagile You might want to look at https://github.com/surpher/PactSwift which supports pact v3.

marcelinoagile commented 2 years ago

Thanks @andrewspinks will take a look

surpher commented 2 years ago

Feature implemented in PactSwift on a branch feature/generator/datetime-expression for now (https://github.com/surpher/PactSwift/tree/feature/generator/datetime-expression).

Example usage:

.willRespondWith(
    status: 201,
    body: [
        "start": ExampleGenerator.DateTimeExpression(expression: "@ next hour", format: dateFormat)
    ]
)