swagger-cli(내부의 swagger-parser)는 dereference() 단계에서 순환 참조(circular $ref)를 완전히 해소하려다 오류가 발생할 수 있습니다. 순환 참조를 지원하거나 번들링 단계에서 순환을 유지해주는 대안 라이브러리를 소개합니다.
dereference()
@apidevtools/json-schema-ref-parser
bundle()
$ref
async function bundleSpec() { const parser = new $RefParser(); // bundle: 순환 참조를 보존하며 외부 파일을 하나로 묶음 const bundled = await parser.bundle('openapi.yaml'); console.log(bundled); } bundleSpec(); ``` (APIDevTools/json-schema-ref-parser - GitHub, json-schema-ref-parser - npm)
@stoplight/json-schema-ref-parser
경량 json-ref-parser
json-ref-parser
Redocly CLI (@redocly/cli)
@redocly/cli
redocly bundle api.yaml -o bundled.yaml
가장 널리 쓰이고 문서화도 잘 되어 있는 @apidevtools/json-schema-ref-parser를 사용해 보시는 것을 추천드립니다. bundle()으로 묶으면 순환 참조를 유지하며 하나의 객체로 다룰 수 있어, swagger-cli에서 겪던 순환 오류를 피할 수 있습니다.