Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
082d968
fix: can't resolve ref error when using
AlbinaBlazhko17 Nov 4, 2025
fc7f396
feat: add test for the specific case
AlbinaBlazhko17 Nov 4, 2025
982edb9
feat: add changeset
AlbinaBlazhko17 Nov 4, 2025
b6843a8
chore: add comment
AlbinaBlazhko17 Nov 4, 2025
1a8fea3
chore: remove comment
AlbinaBlazhko17 Nov 4, 2025
673289f
Update .changeset/happy-chairs-drop.md
AlbinaBlazhko17 Nov 4, 2025
d03375a
Update .changeset/happy-chairs-drop.md
JLekawa Nov 4, 2025
06df369
chore: add docs for the bundle command
AlbinaBlazhko17 Nov 5, 2025
842eba1
docs: change naming
AlbinaBlazhko17 Nov 5, 2025
d7d1092
fix: add to param name and change snapshot
AlbinaBlazhko17 Nov 5, 2025
e4acbe3
chore: change order
AlbinaBlazhko17 Nov 5, 2025
3a43128
feat: implement new fix to cover parameters + other components
AlbinaBlazhko17 Nov 6, 2025
1219167
Revert "feat: implement new fix to cover parameters + other components"
AlbinaBlazhko17 Nov 6, 2025
5159619
feat: implement new fix to cover parameters + other components
AlbinaBlazhko17 Nov 6, 2025
9744269
feat: implement new fix to cover parameters + other components
AlbinaBlazhko17 Nov 6, 2025
bc4d481
Update .changeset/happy-chairs-drop.md
AlbinaBlazhko17 Nov 6, 2025
40dfc66
feat: implement proper logic for decorator and bundle-visitor
AlbinaBlazhko17 Nov 11, 2025
1c4dc8a
refactor: resolveBundledComponent location
AlbinaBlazhko17 Nov 11, 2025
803c12c
fix: change in all places to make ref id from the root document
AlbinaBlazhko17 Nov 12, 2025
878586c
chore: remove changes in decorator due to proper resolve
AlbinaBlazhko17 Nov 12, 2025
bb9e3e7
fix: ajv instance resolve ref and unit test snapshots
AlbinaBlazhko17 Nov 12, 2025
2379a4e
chore: revert previous fix
AlbinaBlazhko17 Nov 14, 2025
5d4f009
chore: revert tests
AlbinaBlazhko17 Nov 14, 2025
fac1645
feat: add wrapper for resolve function with a default value
AlbinaBlazhko17 Nov 17, 2025
7b0d730
refactor: override of the default arguments in resolve function
AlbinaBlazhko17 Nov 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/happy-chairs-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@redocly/openapi-core": patch
---

Fixed an issue where the `remove-unused-compoents` decorator threw a `Can't resolve $ref` error. This issue occurred when `components.parameters` had a `$ref` to `components.schemas`.
2 changes: 1 addition & 1 deletion docs/@v2/commands/bundle.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Redocly CLI can help you combine separate API description files (such as if you
The `bundle` command pulls the relevant parts of an API description into a single file output in JSON or YAML format.

The `bundle` command differs from the [`join`](./join.md) command.
The `bundle` command takes a root OpenAPI file as input and follows the `$ref` mentions to include all the referenced components into a single output file.
The `bundle` command takes a root OpenAPI file as input and follows the `$ref` mentions to include all the referenced components into a single output file. All components are automatically resolved and included without requiring explicit specification.
The `join` command can combine multiple OpenAPI files into a single unified API description file.

The `bundle` command first executes preprocessors, then rules, then decorators.
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/bundle/bundle-visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export function makeBundleVisitor(
replaceRef(node, resolved, ctx);
} else {
node.$ref = saveComponent(componentType, resolved, ctx);
resolveBundledComponent(node, resolved, ctx);
resolveBundledComponent(node, resolved);
}
}
},
Expand Down Expand Up @@ -186,8 +186,8 @@ export function makeBundleVisitor(
};
}

function resolveBundledComponent(node: OasRef, resolved: ResolveResult<any>, ctx: UserContext) {
const newRefId = makeRefId(ctx.location.source.absoluteRef, node.$ref);
function resolveBundledComponent(node: OasRef, resolved: ResolveResult<any>) {
const newRefId = makeRefId(rootDocument.source.absoluteRef, node.$ref);
resolvedRefMap.set(newRefId, {
document: rootDocument,
isRemote: false,
Expand Down
17 changes: 17 additions & 0 deletions tests/e2e/bundle/parameters-reference-to-schemas/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
openapi: 3.0.0
info:
title: Sample API
version: 1.0.0
paths:
/users:
get:
operationId: getUsers
summary: Get a list of users
parameters:
- $ref: parameters.yaml#/Param
responses:
'200':
description: A list of users
content:
application/json:
schema: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Param:
in: query
required: true
schema:
$ref: schemas.yaml#/Schema
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apis:
test-api:
root: openapi.yaml

decorators:
remove-unused-components: on
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Schema:
type: string
30 changes: 30 additions & 0 deletions tests/e2e/bundle/parameters-reference-to-schemas/snapshot.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
openapi: 3.0.0
info:
title: Sample API
version: 1.0.0
paths:
/users:
get:
operationId: getUsers
summary: Get a list of users
parameters:
- $ref: '#/components/parameters/Param'
responses:
'200':
description: A list of users
content:
application/json:
schema: {}
components:
schemas:
Schema:
type: string
parameters:
Param:
in: query
required: true
schema:
$ref: '#/components/schemas/Schema'

bundling openapi.yaml using configuration for api 'test-api'...
📦 Created a bundle for openapi.yaml at stdout <test>ms.
10 changes: 10 additions & 0 deletions tests/e2e/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,16 @@ describe('E2E', () => {
});
});

describe('bundle with parameter, which has reference to schemas', () => {
it('should correctly bundle the api and not remove components', async () => {
const testPath = join(__dirname, `bundle/parameters-reference-to-schemas`);
const args = getParams(indexEntryPoint, ['bundle', '--config=redocly.yaml']);

const result = getCommandOutput(args, { testPath });
await expect(cleanupOutput(result)).toMatchFileSnapshot(join(testPath, 'snapshot.txt'));
});
});

describe('miscellaneous', () => {
const folderPath = join(__dirname, 'miscellaneous');

Expand Down
Loading