Monday, March 27, 2023
HomeCrypto Miningis a instrument that may assist launch a mock server based mostly...

is a instrument that may assist launch a mock server based mostly on an API contract

When our Golang developer, Alexander Melentyev, was engaged on one in every of our shopper’s tasks, he needed to work on integrations with the companion’s API. Through the integration, we didn’t wish to pull the actual API, so there was a necessity use mock knowledge to check API. The companion had an openAPI specification, on the idea of which it was attainable to generate a server utilizing swagger-codegen, however such instruments have a nuance—they generate stubs, that means that in case you observe the “deal with” from the specification, you’re going to get an empty response, and you will have to jot down it your self. Normally, that is time-consuming, and on this case, we didn’t have the mandatory time. So the concept got here as much as launch a server based mostly on the specification, which might give examples described within the specification when going by way of the “deal with”.


We began in search of instruments that may do one thing related. We discovered a prism open-source answer written in NodeJS and wished to implement an analogous thought in Go. So, we talked with QA specialists and located {that a} instrument equivalent to a Golang mock server for testing would even be helpful for them, in order that they might not have to jot down all the things by hand. With its assist, QA specialists may merely take a specification from a companion and simply run all the things with a single command—saving loads of time and assets.

So Alexander created dummy, a really helpful and in-demand instrument that may assist launch a mock server based mostly on an API contract, which helps individuals see how the API will work earlier than it is even constructed. You possibly can run it domestically with the dummy server command to run your API on an HTTP server which you could work together with.

The best way to use dummy?

Utilizing dummy is simple: you simply want to put in it, then you’ll want to use the server command and move the trail to the specification into it. Each hyperlinks and file paths are supported. It’s helpful when you’ll want to combine with an actual API, with out creating an additional load. Additionally, the instrument is appropriate for testing, so that you don’t have to jot down a mock API—you’ll be able to simply use dummy.

Set up:

go set up


Run it domestically with the dummy s command to run your API on a HTTP server you’ll be able to work together with.

dummy s openapi.yml
dummy s


If there’s a want for dynamic knowledge throughout integration, you should use the built-in faker. Within the specification for the fields, you’ll want to add a customized area x-faker and move the required knowledge kind to it. For instance, if you’ll want to dynamically generate a reputation, you’ll want to set the next: x-faker: firstname

You is likely to be questioning, why not use mills like swagger-codegen? It’s as a result of swagger-codegen generates a server, that means that you’ll want to make a number of actions as an alternative of 1. The server shall be generated, and it is possible for you to to go to the addresses which can be described within the documentation, however the response shall be empty. The truth is, you’ll not obtain any integration, as a result of there shall be no knowledge within the response. And in dummy, if any examples are described within the specification, then they are going to come within the response.

Plans for the long run

At present, solely OpenAPI is supported, however plans for the long run embrace including help for GraphQL, RAML and gRPC. Our work on open-source tasks—and the truth that each month we select a number of OSS tasks to sponsor—reveals our initiative and understanding of what builders love and wish. Attain out to us through the shape beneath if you’ll want to develop an open-source answer or are in search of a workforce of execs to construct a challenge from scratch!



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments