Skip to content

Commit

Permalink
fix: overide behaviour of fixing externalValue without modifying
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVarchuk committed Oct 3, 2024
1 parent 5f52ff9 commit 42ad933
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .changeset/little-pears-sniff.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"@redocly/cli": patch
---

Fixed an issue where the bundle command did not resolve relative links in `externalValue`.
Fixed an issue where the bundle command did not resolve links in `externalValue`.
8 changes: 8 additions & 0 deletions packages/core/src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,14 @@ function makeBundleVisitor(
}
},
},
Example: {
leave(node: any, ctx: UserContext, resolved: any) {

Check failure on line 383 in packages/core/src/bundle.ts

View workflow job for this annotation

GitHub Actions / code-style-check

'resolved' is defined but never used. Allowed unused args must match /^_/u
if (node.externalValue && node.value === undefined) {
node.value = ctx.resolve({ $ref: node.externalValue }).node;
delete node.externalValue;
}
},
},
Root: {
enter(root: any, ctx: any) {
rootLocation = ctx.location;
Expand Down
30 changes: 22 additions & 8 deletions packages/core/src/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,6 @@ export async function resolveDocument(opts: {
return;
}

// handle externalValue with relative reference in examples object
if (node.externalValue) {
node.value = {
$ref: node.externalValue,
};
delete node.externalValue;
}

for (const propName of Object.keys(node)) {
let propValue = node[propName];
let propType = type.properties[propName];
Expand Down Expand Up @@ -343,6 +335,28 @@ export async function resolveDocument(opts: {
});
resolvePromises.push(promise);
}

// handle externalValue with relative reference in examples object
if (node.externalValue) {
const promise = followRef(
rootNodeDocument,
{ $ref: node.externalValue },
{
prev: null,
node,
}
).then((resolvedRef) => {
if (resolvedRef.resolved) {
resolveRefsInParallel(
resolvedRef.node,
resolvedRef.document,
resolvedRef.nodePointer!,
type
);
}
});
resolvePromises.push(promise);
}
}

async function followRef(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a: foo
b: 100
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ describe('no-invalid-media-type-examples', () => {
type: number
examples:
first:
externalValue: "https://example.com/example.json"
externalValue: ./fixtures/external-value.yaml
`,
'foobar.yaml'
);
Expand Down

0 comments on commit 42ad933

Please sign in to comment.