返回排行榜

microsoft/typespec

Javatypespec.io
openapi3json-schemaprotobuftypespec
Star 增长趋势
Star
5.8k
Forks
375
周增长
Issues
1.1k
2k4k
2023年2月2024年3月2025年5月2026年7月
制品库Mavengit clone https://github.com/microsoft/typespec.git
README

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 install

The TypeSpec VS Extension can be installed from the VS Marketplace or directly on the command line:

tsp vs install

Usage

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

Hit enter a few times to confirm the defaults.

Copy the contents below into your main.tsp:

import "@typespec/http";
import "@typespec/rest";
import "@typespec/openapi3";

using Http;
using Rest;

/** This is a pet store service. */
@service(#{ title: "Pet Store Service" })
@server("https://example.com", "The service endpoint")
namespace PetStore;

@route("/pets")
interface Pets {
  list(): Pet[];
}

model Pet {
  @minLength(100)
  name: string;

  @minValue(0)
  @maxValue(100)
  age: int32;

  kind: "dog" | "cat" | "fish";
}

Install the dependencies of main.tsp:

tsp install

Compile it to OpenAPI 3.0:

tsp compile main.tsp --emit @typespec/openapi3

You can find the emitted OpenAPI output in ./tsp-output/openapi.json.

Advanced Scenarios

Installing nightly version

On every commit to the main branch, packages with changes are automatically published to npm with the @next tag. The packages section shows which version corresponds to the next tag for each package.

To use a nightly version of the packages, go over each one of the packages in the package.json file and update it to either the latest published @next version or @latest, whichever is the newest. You can also use the tag latest or next instead of an explicit version.

After updating the package.json file you can run npm update --force. Force is required as there might be some incompatible version requirement.

Example

// Stable setup
"dependencies": {
  "@typespec/compiler": "~0.30.0",
  "@typespec/http": "~0.14.0",
  "@typespec/rest": "~0.14.0",
  "@typespec/openapi": "~0.9.0",
}

// Consume next version
// In this example: compiler and openapi have changes but rest library has none
"dependencies": {
  "@typespec/compiler": "~0.31.0-dev.5",
  "@typespec/http": "~0.14.0",
  "@typespec/rest": "~0.14.0", // No changes to @typespec/rest library so need to stay the latest.
  "@typespec/openapi": "~0.10.0-dev.2",
}

Packages

Name Changelog Latest Next
Core functionality
@typespec/compiler Changelog
TypeSpec Libraries
@typespec/http Changelog
@typespec/rest Changelog
@typespec/openapi Changelog
@typespec/openapi3 Changelog
@typespec/versioning Changelog
TypeSpec Tools
@typespec/prettier-plugin-typespec Changelog
typespec-vs Changelog
typespec-vscode Changelog
tmlanguage-generator Changelog

@next version of the package are the latest versions available on the main branch.

相关仓库
fastapi/fastapi

FastAPI framework, high performance, easy to learn, fast to code, ready for production

PythonPyPIMIT Licensepythonjson
fastapi.tiangolo.com
100.8k9.7k
usebruno/bruno

Opensource IDE For Exploring and Testing API's (lightweight alternative to Postman/Insomnia)

JavaScriptnpmMIT Licenseapi-clientgit
usebruno.com
45.8k2.7k
swagger-api/swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.

JavaScriptnpmApache License 2.0swaggerswagger-ui
swagger.io
28.9k9.3k
OpenAPITools/openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)

JavaMavenApache License 2.0rest-apirest-client
openapi-generator.tech
26.6k7.6k
Redocly/redoc

📘 OpenAPI/Swagger-generated API Reference Documentation

TypeScriptnpmMIT Licenseopenapiswagger
redocly.github.io/redoc/
25.8k2.4k
swagger-api/swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.

MustacheApache License 2.0swaggerswagger-codegen
swagger.io
17.8k6k
scalar/scalar

Scalar is an open-source API platform:                                       🌐 Modern REST API Client                                        📖 Beautiful API References                                        ✨ 1st-Class OpenAPI/Swagger Support

TypeScriptnpmMIT Licenseapidocs
scalar.com
15.7k902
swagger-api/swagger-editor

Swagger Editor

JavaScriptnpmswaggerswagger-editor
editor.swagger.io
9.5k2.4k
oapi-codegen/oapi-codegen

Generate Go client and server boilerplate from OpenAPI 3 specifications

GoGo ModulesApache License 2.0openapi3golang
8.5k1k
mockoon/mockoon

Mockoon is the easiest and quickest way to run mock APIs locally. No remote deployment, no account required, open source.

TypeScriptnpmMIT Licensemockserver
mockoon.com
8.3k461
openapi-ts/openapi-typescript

Generate TypeScript types from OpenAPI 3 specs

TypeScriptnpmMIT Licenseopenapi3openapi3-1
openapi-ts.dev
8.2k658
swagger-api/swagger-core

Examples and server integrations for generating the Swagger API Specification, which enables easy access to your REST API

JavaMavenApache License 2.0swaggerjava
swagger.io
7.5k2.3k