You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Redocly为每个API端点生成独立API规范文档

I have an API with 73 endpoints. I used Redocly to split the openapi.json file into separate Paths and Components folders. Now I want to generate a corresponding API specification document based on each individual Path file. The bundle command doesn't meet my needs because it relies on the original openapi.json file to build a new document from the split files. The join command merges multiple openapi.json documents into one, which also doesn't fit. I don't want to manually parse the Path files and build the documents myself—are there any overlooked commands that can achieve this?

Answer

Redocly's built-in bundle and join commands don't directly support generating standalone API specs from individual split Path files, and there's no hidden command for this exact use case. But you can avoid manual parsing with these two workarounds:

1. Custom Script + Redocly bundle

Put together a simple script (Node.js works well here) to automate the process:

  • Grab core global fields (openapi version, info, servers, etc.) from your original openapi.json.
  • Loop through each file in your paths folder. For each one:
    • Create a temporary JSON file that combines those global fields with just the single Path entry.
    • Ensure the temp file references your existing components folder—Redocly's bundle will automatically resolve any component references needed for that Path.
  • Run redocly bundle temp-file.json -o [path-name]-spec.json for each temp file to get a complete, standalone spec for that endpoint.

2. Path Filtering via Redocly Config

Use a temporary config file to narrow down the bundle output to a single Path:

  • Create a temp-redocly.yaml file with these settings (disables unused component warnings and targets your specific Path):
    lint:
      rules:
        no-unused-components: off
    paths:
      /your-target-endpoint-path: {}
    
  • Run redocly bundle openapi.json --config temp-redocly.yaml -o [path-name]-spec.json. The result will be a spec containing only the chosen Path and its required components.

内容的提问来源于stack exchange,提问作者USMC6072

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 16:40:05