Swagger/OpenAPI mock server

rafakob picture rafakob · Jul 13, 2016 · Viewed 59k times · Source

I have an API reference in a Swagger file. I want to create a very simple mock server, so that when I call e.g.:

mymockurl.com/users it will return a predefined JSON (no need to connect to a database).

What's the easiest way to do this? I'm not a backend guy.

Answer

Arnaud Lauret picture Arnaud Lauret · Jul 13, 2016

An easy way to create simple mock from an OpenAPI (fka. Swagger) spec without code is to use a tool call prism available at http://github.com/stoplightio/prism

This command line is all you need:

./prism run --mock --list --spec <your swagger spec file>

The mock server will return a dynamic response based on the OpenAPI spec. If examples are provided in the spec, prism will return them, if not it will generate dummy data based on the spec.

Edit (Aug 2020):

The command has changed in the latest version. The following will do:

prism mock <your spec file>

It accepts swagger and postman doc as well.