Repository navigation
fix: Rebase relative refs inside external path items only once (#2418) - #2419
Open
ericschlarmann wants to merge 1 commit into
Open
ericschlarmann wants to merge 1 commit into
ericschlarmann wants to merge 1 commit into
Conversation
ExternalRefProcessor.processPathItem rebases the relative schema and
example refs of an external path item onto the root document. Afterwards
PathsProcessor.updateRefs resolves the same refs again against the path
item's file. computePreprocessedRef skips a ref only when it does not
start with a dot or starts with "./". The second resolution is therefore
a no-op for an entry document at the root, and also for path items one
directory down. It can break once the rebased ref starts with "../":
with the entry in a subdirectory and the path item two directories down,
../../domain/sub/schemas.yaml becomes ../domain/domain/sub/schemas.yaml
("Unable to load RELATIVE ref"). Before 2.1.48 the unnormalized
concatenation of computeRelativeRef left
../domain/sub/../domain/sub/schemas.yaml, which the ".." fallback in
RefUtils.readExternalRef happened to recover.
ExternalRefProcessor now records the schemas and examples it rebased,
and PathsProcessor leaves those alone. Every other ref is rebased as
before.
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.
Pull Request
Description
Fixes a regression in 2.1.48. With the root document in a subdirectory, a relative schema or example
$refinside an external path item two directories down was rebased twice.../../domain/sub/schemas.yamlbecame../domain/domain/sub/schemas.yaml, and resolving it failed withUnable to load RELATIVE ref.ExternalRefProcessor.processPathItemalready rebases these refs onto the root document.PathsProcessor.updateRefsthen resolved them again against the path item's file, andcomputePreprocessedRefonly recognizes a rebased ref when it does not start with a dot or starts with./. A rebased ref can start with../once the root document is not at the top.ExternalRefProcessornow records the schemas and examples it rebased (an identity set, scoped to the processor instancePathsProcessorowns), andPathsProcessor.updateRefsleaves those alone. Every other ref takes the same path as before, so the existingcomputeRef/computePreprocessedReftests are unchanged.Fixes: #2418
Type of Change
Checklist
Screenshots / Additional Context
New data-driven test
PathsProcessorTest.testRefInPathItemBelowSubdirectoryEntryIsRebasedOncewith resources insrc/test/resources/path-item-below-subdirectory-entry/: root documents inapi/, path items indomain/sub/. It uses one root document per case, because the first ref that fails to load stops the resolution of every later one.The seven cases that
processPathItemrebases fail on master and pass with the fix:../../domain/sub/ref,./ref,schemas.yamlref,../../shared/),On master they come out as
../domain/domain/sub/schemas.yamlor../domain/shared/schemas.yaml.Two cases that only
PathsProcessorrebases (a path-level parameter schema and a request body example) pass on both. They pin that every other ref is still rebased once.Full build
mvn teston JDK 17: all modules green.Also checked against a larger real-world multi-file spec set with three root documents, generating with openapi-generator 7.26.0 and this build swapped in: