export pact json from consumer
pact jvmで定義したコンシューマーのpactを他の環境で使いたい場合があり、jsonでエキスポートしたい
toMapを呼んでjsonでシリアライズすれば良い code:clojure
(ns app
(.toMap
(-> (ConsumerPactBuilder/consumer "Consumer")
(.hasPactWith "Provider")
(.uponReceiving "a request to say Hello")
(.path "/hello")
(.method "POST")
(.body "{\"name\": \"harry\"}")
(.willRespondWith)
(.status 200)
(.body "{\"hello\": \"harry\"}")
(.toPact))
PactSpecVersion/V4)
Supposedly you need to add "type": "Synchronous/HTTP", to interaction entries, else PactReader complains
code:clojure
{
"provider": {
"name": "Provider"
},
"consumer": {
"name": "Consumer"
},
"interactions": [
{
"description": "a request to say Hello",
"type": "Synchronous/HTTP",
"request": {
"method": "POST",
"path": "/hello",
"body": {
"name": "harry"
}
},
"response": {
"status": 200,
"body": {
"hello": "harry"
}
}
}
],
"metadata": {
"pactSpecification": {
"version": "4.0"
},
"pact-jvm": {
"version": "4.6.0"
}
}
}