fix: incorrect relative path generation in $ref during OpenAPI document splitting#175
Merged
thim81 merged 1 commit intothim81:mainfrom Sep 3, 2025
Merged
fix: incorrect relative path generation in $ref during OpenAPI document splitting#175thim81 merged 1 commit intothim81:mainfrom
thim81 merged 1 commit intothim81:mainfrom
Conversation
Fixes issue where split OpenAPI documents could not be bundled back
due to incorrect relative path generation in component $ref references.
**Problem:**
When splitting an OpenAPI document, components that reference other
components (e.g., User schema referencing NotificationPreferences)
would generate incorrect relative paths. This caused bundling to fail
with errors like:
"Cannot resolve: components/schemas/schemas/NotificationPreferences.json"
**Root Cause:**
In writeComponents(), the convertComponentsToRef() function was passed
'components' as currentFileDir instead of the full path 'components/{type}'.
This caused relative path calculation to be incorrect.
**Fix:**
Changed utils/split.js line 63 to pass the correct directory path:
- Before: convertComponentsToRef(..., 'components')
- After: convertComponentsToRef(..., path.join('components', componentType))
**Result:**
- Split documents now generate correct relative paths
- Bundling works correctly for all component references
- All existing tests continue to pass
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
Owner
|
Thanks for reporting the issue. The PR looks good. I'll add a test case so that we can monitor any regression in the future. |
Owner
|
FYI: We just released openapi-format 1.28.0 which includes your PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem Description
When using the
openapiSplit()function to split an OpenAPI document into multiple files, component references in$refwould generate incorrect relative paths, causingparseFile()to fail during bundling.Example error:
Note the duplicate
schemasdirectory.Root Cause
In
utils/split.js(line 63), thewriteComponents()function passed an incorrectcurrentFileDirparameter toconvertComponentsToRef():Before (incorrect):
User.jsonincomponents/schemas/referencingNotificationPreferences.jsonwould yield:"NotificationPreferences.json""schemas/NotificationPreferences.json"components/schemas/schemas/NotificationPreferences.json(extraschemasin the path).Solution
After (fixed):
components/schemas), producing correct relative paths.Test Results
$refresolved)Testing Steps
Impact
Summary
This PR resolves a critical bug with
$refresolution after splitting OpenAPI documents, improving reliability and ensuring smooth end-to-end workflows.1