| I recently joined a product where the teams manually write the client for each REST API. It's fine if we use REST sparingly but the product is a microservice architecture is so we have tons of API. Spend hours writing the client, testing, and reviewing the code feels very wrong to me. To make things worst, the tests aren't good enough because there are no integration or contract tests. The client tests will still pass even if the API's URL is changed. How ca we be more efficient? I have some ideas but I don't know what's the best. 1. Be more efficient in writing the client Our client code is written using a low-level HTTP library so just switching to a REST client library such as Square's Retrofit or Flurl will make us more efficient. We still need to write integration or contract tests (see Pactflow) though. 2. Use OpenAPI OpenAPI is the WSDL of the REST world. The great thing about OpenAPI is it has tools that automatically generates client code. However, those generators are either buggy or may require us to customize the generator. 3. Use Postman or Apimatic Those two products can automatically generate client code as well but instead of OpenAPI, you use their product to define the API specification. I don't have experience in using those products but my hunch is we will eventually want to customize the generator as well. What's the best practice? Do you prefer a hand-rolled client or generated client? If you are hand-rolling your client, how do you test it? Lastly, how important is contract testing in your product? It seems that I don't need contract testing to test the schema if I'm already using OpenAPI. Contract testing is still important though for replying the requests or responses. |
You can use customized templates (e.g. via -t option in the CLI) to meet your unique requirements. Another tips is to use code formatter such as https://prettier.io/, eslint etc to format the auto-generated code based on the style you want.
Please open an issue via http://github.com/OpenAPITools/openapi-generator/issues/new if you need help with OpenAPI Generator.
Disclosure: I'm the top contributor to OpenAPI Generator