@buildwithlayer/openapi-zod-spec

中文文档
1.0.1发布于 2025/05/22MITESM + CJS近 30 天下载 6797

A Zod Schema for OpenAPI Schemas v3.X.X

原始使用文档
文档目录9 节
  1. Prerequisites
  2. Table of contents
  3. Installation
  4. Usage
  5. Loading an OpenAPI Spec
  6. Upgrading an OpenAPI Spec
  7. Contributing
  8. Versioning
  9. License

npm version code style: prettier

OpenAPI Zod Spec

This is a simple Zod Schema for Open API specs version 3.X.X.

Prerequisites

This project requires NodeJS (version 18 or later) and NPM. Node and NPM are really easy to install. To make sure you have them available on your machine, try running the following command.

$ npm -v && node -v
10.2.4
v20.11.0

Table of contents

Installation

BEFORE YOU INSTALL: please read the prerequisites

To install and set up the library, run:

$ npm install @buildwithlayer/openapi-zod-spec

Or if you prefer using Yarn:

$ yarn add @buildwithlayer/openapi-zod-spec

Usage

Loading an OpenAPI Spec

From JSON:

import {OpenAPISpec} from '@buildwithlayer/openapi-zod-spec/index.js';
import {rawSpec} from './openapi.json';

const spec = OpenAPISpec.parse(rawSpec);

From YAML:

import {OpenAPISpec} from '@buildwithlayer/openapi-zod-spec/index.js';
import fs from 'fs';
import yaml from 'js-yaml';

const pathToYamlFile = './path/to/openapi.yml';
const fileContents = fs.readFileSync(pathToYamlFile, 'utf-8');
const rawSpec = yaml.load(fileContents);
const spec = OpenAPISpec.parse(rawSpec);

Upgrading an OpenAPI Spec

import {OpenAPISpec, upgrade} from '@buildwithlayer/openapi-zod-spec/index.js';
import {oldSpec} from './openapi.json';

const upgradedSpec = upgrade(OpenAPISpec.parse(oldSpec));

Contributing

These instructions will be updated soon.

Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests to us.

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Add your changes: git add .
  4. Commit your changes: git commit -am 'Add some feature'
  5. Push to the branch: git push origin my-new-feature
  6. Submit a pull request :sunglasses:

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

MIT License © Andrea SonnY

版本与发布记录

@buildwithlayer/openapi-zod-spec 共发布 3 个版本,首次发布于 2025/05/06;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.1latest2025/05/221.5 年前
1.0.02025/05/221.5 年前
0.1.02025/05/061.5 年前

关于 @buildwithlayer/openapi-zod-spec 的常见问题

@buildwithlayer/openapi-zod-spec 是什么?

A Zod Schema for OpenAPI Schemas v3.X.X

如何安装 @buildwithlayer/openapi-zod-spec?

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

@buildwithlayer/openapi-zod-spec 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/buildwithlayer__openapi-zod-spec 是否存在。

@buildwithlayer/openapi-zod-spec 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@buildwithlayer/openapi-zod-spec 需要什么版本的 Node.js?

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

@buildwithlayer/openapi-zod-spec 可以商用吗?

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

@buildwithlayer/openapi-zod-spec 的下载量有多少?

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

@buildwithlayer/openapi-zod-spec 还在维护吗?

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