This project demonstrates how to implement a mock server based on an Openapi spec.
Install required dependencies:
npm installGenerate Openapi specs:
npm run genLint specs:
npm run lintStart mock servers (each command is a foreground process, so you're going to need several terminals):
npm run v1
npm run v2You 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
Preferheader and a specific example name will return that examplecurl -L -X GET 'http://127.0.0.1:4010/products' \ -H 'Prefer: example=three_products'