Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
O

openapi-cop

> 测试质量
Open source

A proxy that validates responses and requests against an OpenAPI document. https://www.npmjs.com/package/openapi-cop https://hub.docker.com/r/lxlu/openapi-cop

370 stars0 likes2 views
WebsiteGitHub

About

A proxy that validates responses and requests against an OpenAPI document. https://www.npmjs.com/package/openapi-cop https://hub.docker.com/r/lxlu/openapi-cop

openapi-cop

OpenAPI Compliance Proxy that validates requests and responses against an OpenAPI document

The idea is to place the proxy between a client (e.g. a frontend app) and a web server to catch invalid requests or responses during development. Use this proxy locally or set it up in your development server. In production environments, set the silent flag to forward unmodified response bodies. In any case, validation headers are set that allow to trace down violations to your OpenAPI definition.

Requirements

We run all tests with Node.js versions 10 and 12. Higher versions could possibly work but are not currently supported.

Installation

To install the CLI globally:

npm install -g openapi-cop

To install the package locally (inside an existing NPM package) and run the proxy programatically:

npm install openapi-cop

Usage

There are three ways to run openapi-cop:

  1. Start it with the CLI (1).
  2. Run it programatically inside Node.js (2).
  3. Start a container based on the Docker image (3).

CLI Usage

The openapi-cop node package installs itself as an executable linked as openapi-cop. Run the command with the --help flag to get information about the CLI:

…

The proxy validates the requests and responses in the communication with a target server. By default, the proxy will respond with a 500 status code when the validation fails.

Sample validation failure response

…

Two headers are added to the response:

  • openapi-cop-validation-result: contains the validation results as JSON. Interface

    typescript
    {
        request: {
          valid: boolean;
          errors?: Ajv.ErrorObject[] | null;
        },
        response: {
          valid: boolean;
          errors?: Ajv.ErrorObject[] | null;
        },
        responseHeaders: {
          valid: boolean;
          errors?: Ajv.ErrorObject[] | null;
        }
    }
  • openapi-cop-source-request: contains a simplified version of the original request sent by the client as JSON.

    Interface

    typescript
    {
      method: string;
      path: string;
      headers: {
        [key: string]: string | string[];
      };
      query?: {
        [key: string]: string | string[];
      } | string;
      body?: any;
    }

See the references of OpenAPI Backend and Ajv for more information.

When the --silent is provided, the proxy will forward the server's response body without modification. In this case, the validation headers are still added.

Module Usage

To run the proxy programatically use runProxy, which returns a Promise:

typescript
import {runProxy} from 'openapi-cop';

const server = await runProxy({
  port: 8888,
  host: 'proxyhost',
  targetUrl: 'http://targethost:8989',
  apiDocPath: '/path/to/openapi-file.yaml',
  defaultForbidAdditionalProperties: false,
  silent: false
});

Docker Image Usage

We publish a Docker image lxlu/openapi-cop that you can use for your convenience. This means you can also run openapi-cop with something like

docker run --rm -p 8888:8888 --env TARGET=https://some-host-name:1234 --env FILE=some-openapi-document.json lxlu/openapi-cop

Read more information about the usage here.

FAQ

Can I use this in production? This tool was originally meant for development scenarios. You can use this in production but we cannot give you any security guarantees. Also running the JSON schema validation is quite CPU-expensive and you likely do not want to validate in both directions in production because of that overhead.

Do I need this if I already generate my client from the OpenAPI? In case your client and server code is generated from the OpenAPI spec, you might still want to use this proxy. Generated code does usually only provide typing information, but JSON Schema defines much more than that. For example you might define a string property to match a given RegEx and start with the letter "C". This will not be ensured by your generated code at compile time, but will be caught by openapi-cop.

Can I use this with other programming languages? Yes. This is a proxy and not a middleware. You can use it between whatever HTTP-endpoints you have in your architecture.

Contributing

If you want to contribute to openapi-cop, be sure to check the Contributing guidelines and the Contributing wiki page.


Made By

Alexis and Daniel

at

Join us now!

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptcontract-testingdata-validationopenapiproxy

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category测试质量
PricingOpen source

> Related tools

J
Jest
JavaScript 测试框架
P
Playwright
现代端到端测试框架
E
eslint-plugin-test-selectors
Enforces that data-test-id attributes are added to interactive DOM elements (JSX) to help with UI testing. JSX only.