DEV Community

Lucas Bleme
Lucas Bleme

Posted on

Stubbing responses from documented APIs. Worth it?

On the project I currently work, we use swagger for documenting our API. The frontend team use this documentation to create the calls, send the given parameters and so on...

It's a Contract First approach: since we have the contract defined both teams can start working together, since they are respecting the contract.

The problem is: some endpoints returns complex objects, some API calls depends on different frontend data to be sent as headers or parameters. Because of this, frontend developers tend to be blocked waiting for the API endpoint to be ready to be called, because it's impossible to perform the call if the endpoint isn't implemented yet.

One of our collegues suggested us to use some tool that creates enpoints with returned values according to our swagger documentation.

For example: we have in our swagger an endpoint such as

GET /machine?name=foo&type=bar

This tool would read it and then expose an enpoint such as

GET tool.com/45er3z7/machine?name=foo&type=bar

When this endpoint is called, an object with the swagger specification format will be returned.

Do you guys know any tool with this propose? It doesn't need to be open source.

Would be usefull to use such a tool? In our case I do think so.

Some people suggested we coud build a tool to solve it...

Personally I feel like it's a "super engineering" effort.

What are you thoughts on this situation and building a tool for such a pourpose?

Top comments (5)

Collapse
 
rafalpienkowski profile image
Rafal Pienkowski

Another options

My personall choice would be Swagger Hub. Apiary works better with API Blueprint.

Collapse
 
andreybleme profile image
Lucas Bleme

Thanks for you comment @Rafal. We're trying Swagger Hub.

Collapse
 
rafalpienkowski profile image
Rafal Pienkowski

Please give us an info with information how Swagger Hub works in your solution ;)

Cheers.

Collapse
 
rhymes profile image
rhymes
  • oatts is an OpenAPI testing tools that can generate (customizable) response bodies.

  • json schema faker can generate JSON from schemas (internally used by oatts)

I'm sure you can setup a HTTP server so that the frontend team can use these mock responses, maybe with something like json-server

Collapse
 
andreybleme profile image
Lucas Bleme

json server seems to be a good fit.
Thanks @rhymes