contract-validation

1.0.6 • Public • Published

Contract validation

A convenience tool for checking consumer contracts (supports Pact) against openapi contract.

Nodejs Installation

Requires Nodejs to be installed: https://nodejs.org/en/download/

Make sure the command npm is available in terminals (npm = node package manager). More documentation can be found here https://docs.npmjs.com/

Install requirements

Required npm packages. Execute these lines in a terminal:

npm install -g @stoplight/prism-cli
npm install -g contract-validation

In case of upgrades

npm upgrade -g @stoplight/prism-cli
npm upgrade -g contract-validation    

Run the check-contract command line script

To run the the test you need a pact contract and an openapi contract.

You can download an openapi contract by using curl.

curl http://localhost:8080/api/openapi.json -O

Execute script:

check-contract --contract consumer-contract.json --openapi openapi-contract.json 

Run prism mocking server separately

The check-contract script runs a prism server internally. The prism server doc can be found here: https://stoplight.io/p/docs/gh/stoplightio/prism

The prism server takes as input an openapi contract and can act as a mocking http server.

To start the mocking server, execute:

prism mock openapi.json

You can then execute the check-contract script without the openapi.json file:

Execute script:

check-contract --contract consumer-contract.json 

Input requirements

Open api contract

A valid openapi contract is required for prism to do its job. Formats supported are json and yaml.

Consumer contract json formats

The consumer contracts has to be in the following format (a subset of a Pact contract):

[
    {
        request: {
            path: string,
            method: string,
            body: object,
            headers: object
        },
        response: {
            body: object
        }
    }
]

Example:

[
  {
    "request": {
      "method": "POST",
      "path": "/product",
      "headers": {
        "X-Company-header": "data",
        "Accept": "application/json",
        "Content-Type": "application/json"
      },
      "body": {
        "productId": "1"
      }
    },
    "response": {
      "body": {
        "productName": "spade"
      }
    }
  }
]

Readme

Keywords

Package Sidebar

Install

npm i contract-validation

Weekly Downloads

7

Version

1.0.6

License

MIT

Unpacked Size

12 kB

Total Files

10

Last publish

Collaborators

  • intact.software.systems