/create-contract - Create API Contract
Create a Pact contract definition for consumer-driven contract testing.
Steps
- Ask the user for the consumer service name and provider service name
- Identify the API interactions to define (endpoints, methods, request/response schemas)
- Check if Pact is installed in the project; if not, suggest installation
- Create the contract test file with consumer and provider configuration
- Define each interaction: request method, path, headers, query params, and body
- Specify expected response status codes, headers, and body matchers
- Use Pact matchers (like, eachLike, term) for flexible matching instead of exact values
- Add provider states for each interaction describing required preconditions
- Generate the contract test and run it to produce the Pact file
- Validate the generated Pact JSON file is well-formed
- Save the Pact file to the pacts directory for sharing with the provider team
Rules
- Use semantic versioning for consumer and provider names
- Prefer Pact matchers over exact value matching for resilient contracts
- Each interaction must have a unique description
- Include both success and error response scenarios
- Do not include authentication tokens in the contract; use provider states instead
- Keep contracts focused on the data structure, not specific values
- Name contract files as
consumer-provider.json