{"id":20148553,"url":"https://github.com/hltech/pact-gen","last_synced_at":"2025-04-09T19:52:11.904Z","repository":{"id":33893861,"uuid":"152409938","full_name":"HLTech/pact-gen","owner":"HLTech","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-31T19:28:13.000Z","size":422,"stargazers_count":14,"open_issues_count":25,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-31T20:31:11.621Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HLTech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-10T11:05:26.000Z","updated_at":"2022-12-14T22:53:55.000Z","dependencies_parsed_at":"2023-11-16T04:27:13.920Z","dependency_job_id":"64262288-e3d5-45c7-8f13-76f36f5b3868","html_url":"https://github.com/HLTech/pact-gen","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HLTech%2Fpact-gen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HLTech%2Fpact-gen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HLTech%2Fpact-gen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HLTech%2Fpact-gen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HLTech","download_url":"https://codeload.github.com/HLTech/pact-gen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103903,"owners_count":21048244,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T22:38:07.656Z","updated_at":"2025-04-09T19:52:11.875Z","avatar_url":"https://github.com/HLTech.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PACT Generator\n\n[![Build Status](https://travis-ci.org/HLTech/pact-gen.svg?branch=master)](https://travis-ci.org/HLTech/pact-gen)\n[![Coverage Status](https://coveralls.io/repos/github/HLTech/pact-gen/badge.svg?branch=master)](https://coveralls.io/github/HLTech/pact-gen?branch=master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/HLTech/pact-gen/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/HLTech/pact-gen/?branch=master)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n## Table of Contents\n1. [**Overview**](#Overview)\n2. [**Motivation**](#Motivation)\n3. [**Prerequisites**](#Prerequisites)\n4. [**Quick start**](#QuickStart)\n5. [**Interaction info**](#InteractionInfo)\n6. [**Built with**](#BuiltWith)\n7. [**Authors**](#Authors)\n8. [**License**](#License)\n\n## Overview \u003ca name=\"Overview\"\u003e\u003c/a\u003e\n\nThis repository contains library for generating [pact](https://pact.io) files out of [Feign](https://github.com/OpenFeign/feign) clients.\n\n## Motivation\n\nTo generate Pact files, tests for each interaction between service consumer and provider must be written. As number of \nmicroservices and hence number of interaction grows, writing such tests becomes bigger burden. As pact files are currently\nthe only format of expectations supported by Judge Dredd, automatic generation of Pact files makes it much faster to perform\ncontract tests. What is more developers don't need to update Pact tests each time interactions between services is changed.\n\n## Prerequisites \u003ca name=\"Prerequisites\"\u003e\u003c/a\u003e\n\nFirst, the most important thing is that pact-gen is only able to generate pact \nfiles out of Feign clients (at the moment - we have support for \nother http clients in our roadmap).\n\nOur main goal was to create library that doesn't make you write additional boilerplate. However\nit was not possible to generate fully useful pact files by using only Feign clients features.\n\nHere are conventions that we made:\n* `@FeignClient` annotation has a property `name` - value of that property will be used\nas a provider name\n* Feign client's method name will be used as a name for pact interaction\n* we have added custom annotation `@InteractionInfo` - more about this annotation can be found [here](#InteractionInfo)\n* example request/response body is generated using [PODAM](http://mtedone.github.io/podam/) library - so our pojos \nhave to be compliant with its requirements: \n    * no argument constructor and setters\n    * all argument constructor for immutable objects\n* request/response classes must have getters - otherwise pact-gen won't be able to serialize it\n\n## Quick start \u003ca name=\"QuickStart\"\u003e\u003c/a\u003e\n\n### Add pact-gen dependency\n\nAdd pact-gen as a dependency to your project:\n\nif you are using gradle add it to build.gradle:\n```groovy\ndependencies {\n    ...\n    compile \"com.hltech:pact-gen:version\"\n}\n```\n\nif you are using maven add it to pom.xml:\n```xml\n  \u003cdependencies\u003e\n    \u003cdependency\u003e\n      \u003cgroupId\u003ecom.hltech\u003c/groupId\u003e\n      \u003cartifactId\u003epact-gen\u003c/artifactId\u003e\n      \u003cversion\u003eversion\u003c/version\u003e\n    \u003c/dependency\u003e\n  \u003c/dependencies\u003e\n```\n\nAfter your build tool will be able to resolve that dependency you just have to \nwrite simple integration test (you need your application context so your object mapper \nis properly configured). Such test may look like this:\n\n### Generate pact files\n\n```groovy\npackage com.hltech.pact.gen.example\n\nimport com.fasterxml.jackson.databind.ObjectMapper\nimport com.hltech.pact.gen.PactGenerator\nimport org.springframework.beans.factory.annotation.Autowired\nimport org.springframework.boot.test.context.SpringBootTest\n\nimport spock.lang.Specification\n\n@SpringBootTest\nclass ContractTestsGenerator extends Specification {\n\n    @Autowired\n    private ObjectMapper objectMapper\n\n    private PactGenerator pactGenerator = new PactGenerator()\n\n    def \"should generate pact file\"() {\n        expect:\n            pactGenerator.writePactFiles(\"com.hltech.rest\", \"consumer-name\", objectMapper, new File(\"build/pacts/\"))\n    }\n}\n```\n\nThis test will:\n* scan package `com.hltech.rest` and its children looking for Feign clients\n* generate separate pact files for each provider that your application \ncommunicates with via previously found Feign clients\n* bodies of request/response will be serialized to json using YOUR object mapper \nso pact-gen doesn't overwrite any of your configurations\n* write generated pact files to root_of_your_app/build/pacts/ directory\n\n### Further steps\n\nYou can take profit of your generated pact files by testing via [Judge-D](https://github.com/HLTech/judge-d) - an\nopen-source engine for contract testing. \n\n## Interaction info annotation \u003ca name=\"InteractionInfo\"\u003e\u003c/a\u003e\n\nWe have added custom annotation `@InteractionInfo` that contains information about:\n* HTTP status(es) (required)\n\n`@InteractionInfo(responseStatus = HttpStatus.OK)` - will add information to pact file that expected\nstatus is `200 OK`\n\n* header(s) (optional)\n\n`@InteractionInfo(responseStatus = HttpStatus.OK, responseHeaders = {\"key1=val1\", \"key2=val2\"})` - will\nadd information to pact file, that expected status is `200 OK` and that we expect two headers in response:\nfirst with name `key1` and value `val1` and second with name `key2` and value `val2`\n \n* interaction name (optional)\n\n`@InteractionInfo(responseStatus = HttpStatus.OK, description = \"Update test object in the test service\")` - will\nadd information to pact file, that expected status is `200 OK` and that interaction is called \n`Update test object in the test service`\n\n* if expecting empty response (optional)\n\n`@InteractionInfo(responseStatus = HttpStatus.OK, emptyBodyExpected = true)` - will add information to pact file\nthat expected status is `200 OK` and that (despite declared return type) we expect response to be empty.\n\n`@InteractionInfo` can be aggregated thanks to `@InteractionsInfo` annotation - example usage:\n\n```\n@InteractionsInfo({\n    @InteractionInfo(responseStatus = HttpStatus.NOT_FOUND),\n    @InteractionInfo(responseStatus = HttpStatus.ACCEPTED)\n})\n```\nsuch annotations on method will add information to pact file that we expect rest service to be able \nto return any of `404 NOT FOUND` and `202 ACCEPTED` HTTP statuses.\n\n## Built with \u003ca name=\"BuiltWith\"\u003e\u003c/a\u003e\n\n* [Gradle](https://gradle.org/) - dependency management \u0026 build tool \n* [Reflections](https://github.com/ronmamo/reflections) - runtime metadata analysis\n* [PODAM](http://mtedone.github.io/podam/) - POJO filler\n* [Lombok](https://projectlombok.org/) - because who likes boilerplate\n* [Spock](http://spockframework.org/) - for beautiful tests\n\n## Authors \u003ca name=\"Authors\"\u003e\u003c/a\u003e\n\n* **Filip Łazarski** - *Development* - [Felipe444](https://github.com/Felipe444)\n* **Adrian Michalik** - *Development* - [garlicsauce](https://github.com/garlicsauce)\n\n## License \u003ca name=\"License\"\u003e\u003c/a\u003e\n\npact-gen is [MIT licensed](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhltech%2Fpact-gen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhltech%2Fpact-gen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhltech%2Fpact-gen/lists"}