Repository navigation
fix: handle unresolvable $refs gracefully in parser parseRef() - #4087
Conversation
When $RefParser.bundle() skips an unresolvable external $ref, the raw $ref string remains in the bundled spec. The shared parser's parseRef() previously called resolveRef() without error handling, causing hard failures on those same refs. This wraps all six resolveRef() calls across the 2.0.x, 3.0.x, and 3.1.x parsers in try/catch, logging a console.warn and continuing instead of throwing.
|
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 6c21d81 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@pullfrog wouldn't it be better if we caught any such issues before we even get to parser? Instead of having to deal with the same problem later, why not remove any unresolvable refs from the spec? |
|
Refactored the fix per your suggestion: instead of catching unresolvable ref errors in All 526 shared package tests pass, typecheck is clean. See #4087 Task list (8/8 completed)
|
@hey-api/codegen-core
@hey-api/json-schema-ref-parser
@hey-api/nuxt
@hey-api/openapi-ts
@hey-api/shared
@hey-api/spec-types
@hey-api/types
@hey-api/vite-plugin
commit: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4087 +/- ##
==========================================
- Coverage 38.79% 38.54% -0.26%
==========================================
Files 630 633 +3
Lines 21896 22028 +132
Branches 6481 6525 +44
==========================================
- Hits 8495 8491 -4
- Misses 10844 10938 +94
- Partials 2557 2599 +42
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…of catching in parseRef()
|
@pullfrog this is already better. Any reason not to clean the spec in json-schema-ref-parser? |
|
Analyzed whether to clean unresolvable refs in Recommendation: keep it in Task list (4/4 completed)
|
|
@pullfrog yes, move it, why not? We still get the warning and we skip one unnecessary walk in the later stage... |
|
Moved the unresolvable Removed Task list (6/6 completed)
|
…) instead of post-bundle walk
|
Yes, this PR fixes #4084. The change in What happens when After deletion, the schema becomes Is that still valid OpenAPI? Technically yes — an empty/opaque schema is valid and represents "accept anything". Semantically it's a loss compared to what the spec author intended, but the reference was already unresolvable, so the intent can't be honored either way. Generating The only thing to be aware of: if the unresolvable ref lives in a component schema, that component will still be registered and other parts of the spec that reference it (via a resolvable Task list (4/4 completed)
|

When
$RefParser.bundle()skips an unresolvable external$ref, the raw$refstring remains in the bundled spec. This causes hard failures later whenparseRef()callsresolveRef()against those unresolvable refs.Instead of catching these errors in
parseRef()with try/catch, this PR adds aremoveUnresolvableRefs()pass intransformOpenApiSpecthat walks the entire spec before transforms and removes any$refproperty that cannot be resolved. This way unresolvable refs are cleaned up upstream, andparseRef()never encounters them.Fixes #4084
DeepSeek Pro(free via Pullfrog for OSS) | 𝕏