DEV Community

Cover image for OpenAPI + Zod + API Gateway + SST = Turbo Productivity
Marko - ServerlessLife.com
Marko - ServerlessLife.com

Posted on • Updated on • Originally published at serverlesslife.com

OpenAPI + Zod + API Gateway + SST = Turbo Productivity

How to boost productivity with OpenAPI schema, Zod library, and client-generated code. Included is a sample serverless app built with SST/CDK.

"Don't repeat yourself" (DRY) is one of the main principles of software development. But we keep on breaking it by rewriting the data structure on each layer. In this article, we'll explore the method of enhancing our productivity through the utilization of OpenAPI schema, the Zod library, and the generation of client code, all aimed at reusing our types, schemas, and structures. l will bundle everything into a sample AWS serverless application built with the SST framework (which uses CDK). The solution also takes into account that you do not want to have exactly the same types everywhere. The Zod library nicely solves the problem and allows you to mix and match types.

> We keep breaking the "Don't repeat yourself" (DRY) principle by rewriting the data structure on each layer.

When you are creating an API and an application that consumes it, you need to (re)create types/schema for each layer:

  • data exchange = OpenAPI, GraphQL
  • client that consume it
  • API validation logic
  • business logic

Continue reading on www.serverlesslife.com...

Top comments (0)