As of my last update in June 2023, there are several tools available for generating TypeScript client code from OpenAPI specifications. Each tool has its strengths and weaknesses, and the best one for you will depend on your specific needs and preferences. Here are some popular options:
-
OpenAPI Generator - This is a very popular tool that supports multiple languages, including TypeScript. It's highly configurable and can generate a wide range of artifacts, from simple API clients to more complex server stubs.
-
ts-morph - While not specifically designed for OpenAPI, ts-morph is a powerful tool for creating, transforming, and manipulating TypeScript code. It can be used to generate TypeScript clients based on an OpenAPI specification.
-
Redocly's OpenAPI Code Generator - This is a newer tool built by the team behind Redoc, an API documentation generator. It focuses on generating high-quality TypeScript clients and is designed to be simple to use and integrate with your development workflow.
-
TypeScript Codegen - This is a flexible code generation tool that can generate TypeScript types, models, and operations based on an OpenAPI specification. It's designed to be opinionated and easy to use.
-
Nexus - Nexus is a GraphQL schema definition language for TypeScript that can be used to generate a GraphQL server from an OpenAPI specification. While it's not specifically for generating TypeScript clients, it can be used to create a GraphQL API that mirrors your OpenAPI spec.
-
Swagger-Codegen - This is an older tool that has been replaced by OpenAPI Generator but is still widely used. It generates clients, servers, and documentation from an OpenAPI spec.
When choosing a tool, consider the following:
- Ease of use: How simple is it to set up and generate code?
- Community and support: Is the tool actively maintained and supported? Does it have a large community?
- Customizability: Can you customize the generated code to fit your project's needs?
- Type safety: How well does the generated code enforce type safety?
- Integration: How easily can the generated code integrate with your existing workflow and tooling?
It's also worth noting that OpenAPI specifications can be imported into many IDEs and code editors, which can provide type checking and auto-completion features without the need for a separate code generation step. Tools like Visual Studio Code, for example, can understand and provide feedback based on the OpenAPI specification when you're working with client code that doesn't yet have full TypeScript definitions.
Remember to check the latest updates for these tools, as they may have evolved since this post was last updated.