TypeSpec
Official Docs | Try TypeSpec Online | Getting Started | Language Overview
TypeSpec is a language for defining cloud service APIs and shapes. TypeSpec is a highly extensible language with primitives that can describe API shapes common among REST, OpenAPI, gRPC, and other protocols.
TypeSpec is excellent for generating many different API description formats, client and service code, documentation, and other assets while keeping your TypeSpec definition as a single source of truth.
Using TypeSpec, you can create reusable patterns for all aspects of an API and package those reusable patterns into libraries. These patterns establish "guardrails" for API designers and make it easier to follow best practices than to deviate from them. TypeSpec also has a rich linter framework with the ability to flag anti-patterns as well as an emitter framework that lets you control the output to ensure it follows the patterns you want.
TypeSpec is a Microsoft-built, community-supported project. Your ideas, feedbacks, and code make all the difference and we deeply appreciate the support from the community.
Installation
npm install -g @typespec/compiler#### Tools
The TypeSpec VS Code extension can be installed from the VS Code marketplace or directly on the command line:
tsp code installThe TypeSpec VS Extension can be installed from the VS Marketplace or directly on the command line:
tsp vs installUsage
TypeSpec to OpenAPI 3.0 Example
This example uses the @typespec/http, @typespec/rest, and @typespec/openapi3 libraries to define a basic REST service and generate an OpenAPI 3.0 document from it.
Run the following command and select "Generic REST API":
tsp init