Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger/OpenAPI mock server

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.

like image 609
rafakob Avatar asked Jul 13 '16 07:07

rafakob


People also ask

Is mock server free?

Having a simulated version of your real APIs can help your team develop your project faster errors efficiently, and that is when mock APIs comes in handy. Are there any Open-Source and free solutions for mock API? Yes, Mocky and Mockoon are both completely free and open-source that you can use in your project.

What is SwaggerHub API auto mocking?

The API Auto Mocking integration creates and maintains a semi-static mock of your API based on the responses and examples defined in your OpenAPI 3.0 or 2.0 definition. The mock is updated every time you save your API. The mock helps you test your API when designing it, that is, before it is implemented by developers.


2 Answers

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 written in Typescript.

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.

like image 157
Arnaud Lauret Avatar answered Sep 23 '22 05:09

Arnaud Lauret


SwaggerHub provides a mock server for OpenAPI 2.0 and 3.0 specs. Mocking is supported on both free and paid plans.

To use the mock server, import your spec into SwaggerHub and enable "API Auto Mocking". Mock responses can be JSON, YAML and XML, and are generated based on your response schemas and the example, default and enum values defined in the schemas.

Disclosure: I work for the company that makes SwaggerHub.

like image 23
Helen Avatar answered Sep 21 '22 05:09

Helen