fix(openapi): resolve x-fern-examples $ref relative to spec file#10420
Merged
fix(openapi): resolve x-fern-examples $ref relative to spec file#10420
Conversation
- Add documentBaseDir field to AbstractConverterContext to track OpenAPI file location - Update FernExamplesExtension to accept optional baseDir parameter - Implement synchronous file resolution for $ref in code samples - Resolve $ref paths relative to OpenAPI file directory instead of process.cwd() - Add E2E test fixture for x-fern-examples file-linking functionality This fixes the issue where x-fern-examples with $ref to external code sample files were resolved relative to the current working directory instead of the OpenAPI file's directory, causing file resolution to fail. Co-Authored-By: judah@buildwithfern.com <jsklan.development@gmail.com>
- Add baseDir parameter to AsyncAPI FernExamplesExtension Args interface - Import dirname from @fern-api/fs-utils in OSSWorkspace.ts This fixes compilation errors from the previous commit. Co-Authored-By: judah@buildwithfern.com <jsklan.development@gmail.com>
… file This fixes the openapi-ir-parser code path to resolve $ref in x-fern-examples code samples relative to the OpenAPI spec file directory instead of process.cwd(). The openapi-ir-parser package has its own validation logic for x-fern-examples that was not resolving $ref objects. This adds the same resolution logic that was added to the openapi-to-ir package, using context.source.file to get the directory path. Co-Authored-By: judah@buildwithfern.com <jsklan.development@gmail.com>
The test fixture was using 'request' to specify query parameters for a GET endpoint, but the Fern validator expects GET endpoints without a body to use 'query-parameters' instead of 'request' in examples. This was a pre-existing issue in the original PR #10297 that was causing the validation error 'Unexpected request in example'. Co-Authored-By: judah@buildwithfern.com <jsklan.development@gmail.com>
Co-Authored-By: judah@buildwithfern.com <jsklan.development@gmail.com>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
fern-support
approved these changes
Nov 7, 2025
jsklan
approved these changes
Nov 7, 2025
tjb9dc
approved these changes
Nov 7, 2025
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.
Description
Refs #10297
Fixes x-fern-examples $ref resolution to resolve file paths relative to the OpenAPI spec file directory instead of
process.cwd().Devin session: https://app.devin.ai/sessions/79313c8ac0114e65992c36847cb98eec
Requested by: judah@buildwithfern.com (@jsklan)
Changes Made
documentBaseDirparameter toAbstractConverterContextto track the OpenAPI file's base directory$refresolution inopenapi-to-irpackage'sFernExamplesExtension:isCodeReference,maybeResolveCodeReference,resolveCodeSamples$refbefore validation usingreadFileSync$refresolution inopenapi-ir-parserpackage'sgetExamplesFromExtension:context.source.fileto determine base directory viadirname()OSSWorkspace.tsto passdocumentBaseDir: dirname(absoluteFilepathToSpec)when creating OpenAPIConverterContextquery-parametersinstead ofrequestfor GET endpoint (pre-existing validation error)Testing
x-fern-examples.test.tsend-to-end testpnpm -C packages/cli/ete-tests test x-fern-examples.test.tsImportant Review Notes
Dual Implementation
This fix was required in two separate code paths:
openapi-to-irpackage (newer conversion pipeline)openapi-ir-parserpackage (older conversion pipeline that's still used)Both implementations use identical logic for consistency. Please verify both are correct.
Test Fixture Modification
Changed the test fixture from using
request: { limit: 10 }toquery-parameters: { limit: 10 }for the GET endpoint. This was necessary because:query-parametersnotrequestin examplesError Handling Behavior
When a
$refcannot be resolved (file doesn't exist or can't be read), the code sample is silently dropped from the example. This matches the pattern where validation errors are collected but don't block parsing. However, this means incorrect file paths won't produce clear error messages.File I/O
Uses synchronous
readFileSyncto avoid making the entire conversion pipeline async. This is consistent with other file operations during the parsing phase but could block for large code sample files.Human Review Checklist
openapi-to-irandopenapi-ir-parserimplementations work correctlyrequesttoquery-parametersis correct../../code_samples/example.phpfromfern/openapi/openapi.yml