Skip to main content

Provides the basic setup of an API mockserver.

Project description


What does it do

It creates expectations for mockserver based on an OpenAPI2 yaml.

If no scenarios are provided, it creates expectations for all endpoints with the first status-code defined. If example values are given in contract, these values will be used for response body.

If scenarios are provided, they must match the defined endpoints in the OpenAPI2 file.


start a mockserver: docker run -it --rm -P jamesdbloom/mockserver

Create expectations: oapi2mockserver mock localhost:<port_of_mockserver_docker_container> <path_to_open_api_2_contract_yaml>

Scenario Parameter

-s json of scenarios to push to the mockserver

Example: oapi2mockserver mock localhost:32768 foo.yaml -s '{"scenarios":[["\/v1\/foo\/{id}","get","200", "{\"foo\":\"bar\"}", "application/json"]]}'

This pushes one scenario to mockserver with path /v1/foo/{id}, operation get, expected status-code 200, expected response-body {"foo":"bar"} and expected response Content-Type header application/json

Response-Body and Content-Type are optional and will be generated out of the contract if not given. If the Response-Body is a json, it will be validated against the schema defined in the contract before the scenario will be send to mock-server. Also the Content-Type header needs to be defined in produces part of contract before the scenario will be send to mock-server.


run current development state:

  • cd into package root directory
  • install dependencies with pip3 install -r requirements.txt (just before first run or after adding new dependencies)
  • run python3 mock <url_to_mockserver> <path_to_open_api_2_contract_yaml>


cd into package root directory and run python3 -m unittest discover -s tests -v


cd into package root directory and run pip3 install ./

Upload to

WARNING: This will overwrite the current version on!

raise version in, then run ./upload

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oapi2mockserver-0.0.13.tar.gz (7.6 kB view hashes)

Uploaded source

Built Distribution

oapi2mockserver-0.0.13-py3-none-any.whl (10.2 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page