@apidevtools/openapi-schemas

中文文档
2.1.0发布于 2021/05/01MITTypeScriptCommonJS零依赖近 30 天下载 2245.8万

JSON Schemas for every version of the OpenAPI Specification

原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. Contributing
  4. License
  5. Big Thanks To

OpenAPI Specification Schemas

Cross-Platform Compatibility Build Status

Coverage Status Dependencies

npm License Buy us a tree

This package contains the official JSON Schemas for every version of Swagger/OpenAPI Specification:

VersionSchemaDocs
Swagger 1.2v1.2 schemav1.2 docs
Swagger 2.0v2.0 schemav2.0 docs
OpenAPI 3.0.xv3.0.x schemav3.0.3 docs
OpenAPI 3.1.xv3.1.x schemav3.1.0 docs

All schemas are kept up-to-date with the latest official definitions via an automated CI/CD job. 🤖📦

Installation

You can install OpenAPI Schemas via npm.

npm install @apidevtools/openapi-schemas

Usage

The default export contains all OpenAPI Specification versions:

const openapi = require("@apidevtools/openapi-schemas");

console.log(openapi.v1);    // { $schema, id, properties, definitions, ... }
console.log(openapi.v2);    // { $schema, id, properties, definitions, ... }
console.log(openapi.v3);    // { $schema, id, properties, definitions, ... }
console.log(openapi.v31);    // { $schema, id, properties, definitions, ... }

Or you can import the specific version(s) that you need:

const { openapiV1, openapiV2, openapiV3, openapiV31 } = require("@apidevtools/openapi-schemas");

console.log(openapiV1);    // { $schema, id, properties, definitions, ... }
console.log(openapiV2);    // { $schema, id, properties, definitions, ... }
console.log(openapiV3);    // { $schema, id, properties, definitions, ... }
console.log(openapiV31);    // { $schema, id, properties, definitions, ... }

You can use a JSON Schema validator such as Z-Schema or AJV to validate OpenAPI definitions against the specification.

const { openapiV31 } = require("@apidevtools/openapi-schemas");
const ZSchema = require("z-schema");

// Create a ZSchema validator
let validator = new ZSchema();

// Validate an OpenAPI definition against the OpenAPI v3.0 specification
validator.validate(openapiDefinition, openapiV31);

Contributing

Contributions, enhancements, and bug-fixes are welcome! Open an issue on GitHub and submit a pull request.

Building

To build the project locally on your computer:

  1. Clone this repo
    git clone https://github.com/APIDevTools/openapi-schemas.git

  2. Install dependencies
    npm install

  3. Build the code
    npm run build

  4. Run the tests
    npm test

License

OpenAPI Schemas is 100% free and open-source, under the MIT license. Use it however you want.

This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

Big Thanks To

Thanks to these awesome companies for their support of Open Source developers ❤

GitHub NPM Coveralls Travis CI SauceLabs

版本与发布记录

@apidevtools/openapi-schemas 共发布 7 个版本,首次发布于 2020/03/10;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.1.0latest2021/05/015 年前
2.0.42020/07/196 年前
2.0.32020/03/156 年前
2.0.22020/03/146 年前
2.0.12020/03/106 年前
2.0.02020/03/106 年前

关于 @apidevtools/openapi-schemas 的常见问题

@apidevtools/openapi-schemas 是什么?

JSON Schemas for every version of the OpenAPI Specification

如何安装 @apidevtools/openapi-schemas?

在项目目录运行 npm install @apidevtools/openapi-schemas,或使用 pnpm add / yarn add / bun add。

@apidevtools/openapi-schemas 支持 TypeScript 吗?

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

@apidevtools/openapi-schemas 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@apidevtools/openapi-schemas 需要什么版本的 Node.js?

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

@apidevtools/openapi-schemas 可以商用吗?

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

@apidevtools/openapi-schemas 的下载量有多少?

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

@apidevtools/openapi-schemas 还在维护吗?

最新版本 2.1.0 发布于 2021/05/01(5 年前);至今共发布 7 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/03/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。