安装
使用你习惯的包管理器安装 @powerduck/x-to-openapi。
环境要求
- Node.js:
>= 22.12.0 - **TypeScript:**可选;包中包含完整的类型定义。
安装
npm install @powerduck/x-to-openapi
yarn add @powerduck/x-to-openapi
pnpm add @powerduck/x-to-openapi
运行时依赖
| 包 | 版本 | 用途 |
|---|---|---|
@powerduck/openapi-parser | ^0.3.12 | 规范的 OpenAPI 类型与输出验证 |
curlconverter | ^4.12.0 | 将 curl 命令解析为结构化请求 |
这两个依赖会自动安装。
模块系统:优先 ESM,同时支持 CJS
包声明了 "type": "module",通过同一个入口提供两种构建:
| 构建 | 条件 | 文件 |
|---|---|---|
| ESM | import | ./dist/index.js |
| CommonJS | require | ./dist/index.cjs |
| 类型 | — | ./dist/index.d.ts |
// ESM (Node.js, bundlers)
import { curlToOpenApi, postmanToOpenApi } from "@powerduck/x-to-openapi";
// CommonJS (require)
const { curlToOpenApi, postmanToOpenApi } = require("@powerduck/x-to-openapi");
包声明了 "sideEffects": false,tree shaking 可移除未使用的适配器。
零配置辅助函数
多数用户只需两个函数。它们会创建 XToOpenApi 实例,注册对应适配器,然后调用 convert:
import {
curlToOpenApi, // string | string[] → OpenAPI 3.2
postmanToOpenApi, // collection object | JSON string → OpenAPI 3.2
} from "@powerduck/x-to-openapi";
需要自定义选项、多个适配器、"auto" 检测或自定义适配器时,请使用完整的 XToOpenApi 类。
验证安装
# Check the installed version
npm list @powerduck/x-to-openapi
# Verify the package loads and the helpers exist
node -e "const x = require('@powerduck/x-to-openapi'); console.log(typeof x.curlToOpenApi, typeof x.postmanToOpenApi, typeof x.XToOpenApi);"