This project demonstrates how to implement a mock server based on an Openapi spec.
Install required dependencies:
npm install
Generate Openapi specs:
npm run gen
Lint specs:
npm run lint
Start mock servers (each command is a foreground process, so you're going to need several terminals):
npm run v1
npm run v2
You can access mock servers on http://127.0.0.1:4010 for v1
and on http://127.0.0.1:4011 for v2
.
First start both APIs (v1
and v2
). Now these examples demonstrate different aspects of mock server responses:
- Simple call will return a set of randomly generated objects
curl -L -X GET 'http://127.0.0.1:4010/products'
- A call with
Prefer
header and a specific example name will return that examplecurl -L -X GET 'http://127.0.0.1:4010/products' \ -H 'Prefer: example=three_products'