@apisyouwonthate/spectral-jsonapi

中文文档
2.2.0发布于 2026/04/22MITTypeScriptESM + CJS构建来源已验证近 30 天下载 2614

A Spectral ruleset for JSON:API, built as TypeScript.

原始使用文档
文档目录10 节
  1. ⚡️ Quick Start
  2. 🔨 Usage
  3. Use as npm package
  4. Use legacy YAML directly from GitHub
  5. Rule Opt-Outs
  6. resource-object-id-required
  7. 👥 Contributing
  8. 🎉 Thanks
  9. 📜 License
  10. 🌳 Sponsor

Spectral JSON:API Ruleset

Node.js CI

Automatically check if OpenAPI descriptions are compliant with JSON:API v1.1 using this Spectral ruleset so API teams can catch problems early in editors, CI, and pull requests.

⚡️ Quick Start

npm install --save-dev spectral-jsonapi @stoplight/spectral-cli

Create a local ruleset file:

# .spectral.yaml
extends:
  - spectral:oas
  - "@apisyouwonthate/spectral-jsonapi"

Lint your OpenAPI description:

spectral lint api/openapi.yaml

🔨 Usage

Use as npm package

Use this when the project already installs dependencies with npm.

# .spectral.yaml
extends:
  - spectral:oas
  - "@apisyouwonthate/spectral-jsonapi"

Use legacy YAML directly from GitHub

Use this when you want to consume the generated YAML ruleset without installing the package:

extends:
  - "https://raw.githubusercontent.com/apisyouwonthate/spectral-jsonapi/refs/heads/main/.spectral.yml"

Once you have the ruleset set up, you can run Spectral in the same directory as your .spectral.yml ruleset, and it will include the JSON:API rules in its check

spectral lint api/openapi.yaml

This does not include spectral:oas rules, so to get these add it to the extend list:

extends:
  - "https://raw.githubusercontent.com/apisyouwonthate/spectral-jsonapi/refs/heads/main/.spectral.yml"
  - spectral:oas

Rule Opt-Outs

resource-object-id-required

Use this opt-out only when a response schema is intentionally not a standard JSON:API resource object (for example, ephemeral computed resources without stable IDs).

Set x-jsonapi-virtual-resource: true on the resource schema to skip the resource-object-id-required warning.

components:
  schemas:
    AvailableSlotResource:
      type: object
      x-jsonapi-virtual-resource: true
      required:
        - type
        - attributes
      properties:
        type:
          type: string
          enum:
            - availableSlot
        attributes:
          $ref: "#/components/schemas/AvailableSlotAttributes"

👥 Contributing

For testing approach and contributor workflow, see CONTRIBUTING.md.

🎉 Thanks

📜 License

MIT. See LICENSE.

🌳 Sponsor

If you'd like to say thanks for this style guide, consider supporting Protect Earth, a charity co-founded by APIs You Won't Hate's co-founder Phil Sturgeon, focused on nature-based climate solutions. Phil spends most of his time planting trees and re-wetting bogs now, especially at the Warleigh Nature Reserve, so this is a great way to support his work and the planet at the same time.

版本与发布记录

@apisyouwonthate/spectral-jsonapi 共发布 6 个版本,首次发布于 2026/04/01;过去 12 个月发布了 6 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.2.0latest2026/04/226 个月前
2.1.12026/04/226 个月前
2.1.02026/04/087 个月前
1.1.02026/04/087 个月前
1.0.02026/04/087 个月前
2.0.02026/04/017 个月前

关于 @apisyouwonthate/spectral-jsonapi 的常见问题

@apisyouwonthate/spectral-jsonapi 是什么?

A Spectral ruleset for JSON:API, built as TypeScript.

如何安装 @apisyouwonthate/spectral-jsonapi?

在项目目录运行 npm install @apisyouwonthate/spectral-jsonapi,或使用 pnpm add / yarn add / bun add。

@apisyouwonthate/spectral-jsonapi 支持 TypeScript 吗?

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

@apisyouwonthate/spectral-jsonapi 支持 ESM 还是 CommonJS?

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

@apisyouwonthate/spectral-jsonapi 可以商用吗?

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

@apisyouwonthate/spectral-jsonapi 的下载量有多少?

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

@apisyouwonthate/spectral-jsonapi 还在维护吗?

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