3

I'm looking for a project/tool that is able to get swagger / openapi specifications file as a parameter and generate a mock server that can be controlled programmatically via a REST API interface.

For example - if my API contains the following endpoint: "POST /v1/create" and I have a swagger specs that describe that API, I would like my mock server to be executed in a way similar to:

mock-server -f swagger.yaml -p 8080

While the server runs, It will be possible to interact with it's own REST API (on some control interface via a different port) and change the behavior of the running swagger mock server - i.e: change response code, set response content etc'

I would like to use such mock-server as part of my system-tests suite to better verify my service behavior when interacting with other services - without the need to run those 'real' services.

I'm looking for something similar in spirit to Shopyify's ToxiProxy (https://github.com/Shopify/toxiproxy) but with the above capabilities.

Thanks!

Eldad

HariKrishnan
  • 456
  • 3
  • 14
Eldad
  • 107
  • 1
  • 2
  • 9
  • 1
    Do any of [these mock servers](https://stackoverflow.com/q/38344711/113116) suit your needs? – Helen May 22 '18 at 21:07
  • 2
    No, SwaggerHub and Prism are close but it seems they only allow to set static responses which is nice but not good for automated testing in which I would like to have the ability to change the API response as part of my test setup/teardown steps. – Eldad May 22 '18 at 21:19
  • @Eldad : have you found a solution ? Do you accept the answer? – Phung D. An Feb 16 '19 at 23:26

2 Answers2

2

I know I'm a bit late to the party on this one, but for future searchers, MockLab now supports auto-generation of mock APIs from an imported Swagger definition and Swaggerhub webhooks.

More details here: https://www.mocklab.io/blog/mocklab-now-supports-swagger-and-swaggerhub/

Tom
  • 3,471
  • 21
  • 14
1

I believe Specmatic should help you with this.

mock-server -f swagger.yaml -p 8080

Specmatic works exactly this way. To start a mock server with an OpenAPI specification file we can run below command.

specmatic stub service.yaml --port 8080

Here is the documentation.

While the server runs, It will be possible to interact with it's own REST API (on some control interface via a different port) and change the behaviour of the running swagger mock server - i.e: change response code, set response content etc'

This is also supported. Specmatic has a http interface to which you can post the request and response mappings / expectations. We call this dynamic mocks. Here is the documentation.

Here is a video on this.

Disclosure: I am lead dev and CTO at Specmatic

HariKrishnan
  • 456
  • 3
  • 14