When our Golang developer, Alexander Melentyev, was engaged on one in all our shopper’s tasks, he needed to work on integrations with the companion’s API. Throughout the integration, we didn’t need 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, which means that for those who 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. Often, that is time-consuming, and on this case, we didn’t have the required time. So the thought got here as much as launch a server primarily based on the specification, which might give examples described within the specification when going by means of the “deal with”.
We began on the lookout for instruments that might do one thing comparable. We discovered a prism open-source answer written in NodeJS and needed to implement an analogous thought in Go. So, we talked with QA specialists and located {that a} instrument akin to a Golang mock server for testing would even be helpful for them, in order that they’d not have to jot down every part by hand. With its assist, QA specialists may merely take a specification from a companion and simply run every part with a single command—saving numerous time and sources.
So Alexander created dummy, a really helpful and in-demand instrument that may assist launch a mock server primarily based on an API contract, which helps folks see how the API will work earlier than it is even constructed. You may run it regionally with the dummy server
command to run your API on an HTTP server you could work together with.
The right way to use dummy?
Utilizing dummy is straightforward: you simply want to put in it, then it is advisable to use the server command and cross the trail to the specification into it. Each hyperlinks and file paths are supported. It’s helpful when it is advisable 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 may simply use dummy.
Set up:
go set up github.com/neotoolkit/dummy/cmd/dummy@newest
Utilization:
Run it regionally with the dummy s
command to run your API on a HTTP server you may work together with.
dummy s openapi.yml
dummy s https://uncooked.githubusercontent.com/neotoolkit/dummy/important/examples/docker/openapi.yml
Options
If there’s a want for dynamic knowledge throughout integration, you should use the built-in faker. Within the specification for the fields, it is advisable to add a customized discipline x-faker
and cross the required knowledge sort to it. For instance, if it is advisable to dynamically generate a reputation, it is advisable to set the next: x-faker: firstname
You could be questioning, why not use mills like swagger-codegen? It’s as a result of swagger-codegen generates a server, which means that it is advisable to make a number of actions as a substitute of 1. The server will likely be generated, and it is possible for you to to go to the addresses which might be described within the documentation, however the response will likely be empty. In truth, you’ll not obtain any integration, as a result of there will likely be no knowledge within the response. And in dummy, if any examples are described within the specification, then they may come within the response.
Plans for the longer term
Presently, solely OpenAPI is supported, however plans for the longer term embody including assist 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—exhibits our initiative and understanding of what builders love and want. Attain out to us through the shape under if it is advisable to develop an open-source answer or are on the lookout for a staff of pros to construct a challenge from scratch!