@azure-tools/typespec-metadata

中文文档
0.4.2发布于 2026/11/11MITTypeScriptES Module近 30 天下载 3.2万

TypeSpec emitter that produces structured metadata snapshots for APIView and other tooling.

原始使用文档
文档目录4 节
  1. Install
  2. Usage
  3. Options
  4. Output

@azure-tools/typespec-metadata

TypeSpec emitter that produces structured metadata snapshots for APIView and other tooling.

Install

npm install @azure-tools/typespec-metadata

Usage

Add the emitter to your TypeSpec project:

tsp compile . --emit @azure-tools/typespec-metadata

Or configure it in your tspconfig.yaml:

emit:
  - "@azure-tools/typespec-metadata"

Options

The emitter supports the following options:

  • output-file: Output filename (default: typespec-metadata.yaml for YAML, typespec-metadata.json for JSON)
  • format: Output format - either "yaml" or "json" (default: "yaml")

Example (YAML output):

emit:
  - "@azure-tools/typespec-metadata"
options:
  "@azure-tools/typespec-metadata":
    output-file: "api-metadata.yaml"
    format: "yaml"

Example (JSON output):

emit:
  - "@azure-tools/typespec-metadata"
options:
  "@azure-tools/typespec-metadata":
    output-file: "api-metadata.json"
    format: "json"

Output

The emitter generates structured metadata in YAML or JSON format. This metadata is used by tools like APIView for API review and comparison.

Here is an example using KeyVault Keys:

emitterVersion: 0.1.0
generatedAt: 2026-01-15T23:14:08.554Z
typespec:
  namespace: KeyVault
  documentation: The key vault client performs cryptographic key operations and vault operations against the Key Vault service.
  type: data
languages:
  python:
    emitterName: "@azure-tools/typespec-python"
    packageName: azure-keyvault-keys
    namespace: azure.keyvault.keys
    outputDir: "{output-dir}/sdk/keyvault/azure-keyvault-keys"
    flavor: azure
    serviceDir: sdk/keyvault
  java:
    emitterName: "@azure-tools/typespec-java"
    packageName: "com.azure:azure-security-keyvault-keys"
    namespace: com.azure.security.keyvault.keys
    outputDir: "{output-dir}/sdk/keyvault/azure-security-keyvault-keys"
    flavor: azure
    serviceDir: sdk/keyvault
  typescript:
    emitterName: "@azure-tools/typespec-ts"
    packageName: "@azure/keyvault-keys"
    namespace: "@azure/keyvault-keys"
    outputDir: "{output-dir}/sdk/keyvault/keyvault-keys"
    flavor: azure
    serviceDir: sdk/keyvault
  go:
    emitterName: "@azure-tools/typespec-go"
    packageName: sdk/security/keyvault/azkeys
    namespace: sdk/security/keyvault/azkeys
    outputDir: "{output-dir}/sdk/security/keyvault/azkeys"
    serviceDir: sdk/security/keyvault
  rust:
    emitterName: "@azure-tools/typespec-rust"
    packageName: azure_security_keyvault_keys
    namespace: azure_security_keyvault_keys
    outputDir: "{output-dir}/sdk/keyvault/azure_security_keyvault_keys"
    serviceDir: sdk/keyvault
sourceConfigPath: C:/repos/azure-rest-api-specs/specification/keyvault/Security.KeyVault.Keys/tspconfig.yaml

版本与发布记录

@azure-tools/typespec-metadata 共发布 19 个版本,首次发布于 2026/01/31;过去 12 个月发布了 19 个版本。

版本发布日期距今
0.4.2latest2026/11/11今天
0.4.2-dev.1next2026/10/2219 天前
0.4.12026/10/2219 天前
0.4.1-dev.12026/10/2220 天前
0.4.1-dev.02026/09/121 个月前
0.4.02026/09/121 个月前

关于 @azure-tools/typespec-metadata 的常见问题

@azure-tools/typespec-metadata 是什么?

TypeSpec emitter that produces structured metadata snapshots for APIView and other tooling.

如何安装 @azure-tools/typespec-metadata?

在项目目录运行 npm install @azure-tools/typespec-metadata,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@typespec/compiler(^1.18.0)、@typespec/versioning(^0.88.0)、@azure-tools/typespec-azure-core(^0.74.0)、@azure-tools/typespec-client-generator-core(^0.74.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@azure-tools/typespec-metadata 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@azure-tools/typespec-metadata 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@azure-tools/typespec-metadata 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@azure-tools/typespec-metadata 可以商用吗?

@azure-tools/typespec-metadata 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@azure-tools/typespec-metadata 的下载量有多少?

根据 npm 官方下载统计,@azure-tools/typespec-metadata 在 2026/10/08 – 2026/11/06 这 30 天内被下载 32,475 次,日均约 1,083 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@azure-tools/typespec-metadata 还在维护吗?

最新版本 0.4.2 发布于 2026/11/11(今天);至今共发布 19 个版本,其中过去 12 个月发布了 19 个;首次发布于 2026/01/31。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。