Skip to content

Commit abc1cf7

Browse files
committed
fix: improve docs, changeset and tests
1 parent d16bd72 commit abc1cf7

File tree

5 files changed

+38
-61
lines changed

5 files changed

+38
-61
lines changed

.changeset/loud-mails-hang.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
"@redocly/openapi-core": patch
3+
"@redocly/cli": patch
34
---
45

5-
Fixed an issue where the content of `$ref`s inside `Examples.value` was erroneously resolved during bundling and linting.
6+
Fixed an issue where the content of `$ref`s inside example values was erroneously resolved during bundling and linting.

docs/@v2/configuration/reference/resolve.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ One HTTP header is supported for each URL resolved.
2121

2222
- doNotResolveExamples
2323
- boolean
24-
- Set this option to `true` to prevent resolving `$ref` fields in `Example`. This affects both `lint` and `bundle` commands. Resolving `$ref`s in other parts of the API description is unaffected.
24+
- Set this option to `true` to prevent resolving `$ref` fields in singular `example` properties. This affects both `lint` and `bundle` commands. Resolving `$ref`s in other parts of the API description is unaffected.
2525

2626
---
2727

docs/@v2/configuration/resolve.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ properties:
1212
doNotResolveExamples:
1313
type: boolean
1414
description: >-
15-
Set this option to `true` to prevent resolving `$ref` fields in `Example`.
15+
Set this option to `true` to prevent resolving `$ref` fields in singular `example` properties.
1616
This affects both `lint` and `bundle` commands.
1717
This does not affect `$ref` resolution in other parts of the API description.
1818
default: false

packages/core/src/__tests__/bundle-examples-ref-resolution.test.ts

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -226,62 +226,4 @@ describe('Bundle Examples $ref Resolution', () => {
226226
`);
227227
});
228228
});
229-
230-
describe('Edge cases and configuration', () => {
231-
it('should work with doNotResolveExamples: true config', async () => {
232-
const testDocument = parseYamlToDocument(
233-
outdent`
234-
openapi: 3.1.0
235-
info:
236-
title: Test API
237-
version: 1.0.0
238-
paths:
239-
/test:
240-
get:
241-
responses:
242-
'200':
243-
content:
244-
application/json:
245-
examples:
246-
test-example:
247-
value:
248-
$ref: ./example-data.json
249-
`,
250-
''
251-
);
252-
253-
const config = await createConfig({
254-
resolve: {
255-
doNotResolveExamples: true,
256-
},
257-
});
258-
259-
const { bundle: result, problems } = await bundleDocument({
260-
document: testDocument,
261-
externalRefResolver: new BaseResolver(),
262-
config,
263-
types: Oas3Types,
264-
});
265-
266-
expect(problems).toHaveLength(0);
267-
expect(result.parsed).toMatchInlineSnapshot(`
268-
openapi: 3.1.0
269-
info:
270-
title: Test API
271-
version: 1.0.0
272-
paths:
273-
/test:
274-
get:
275-
responses:
276-
'200':
277-
content:
278-
application/json:
279-
examples:
280-
test-example:
281-
value:
282-
$ref: ./example-data.json
283-
components: {}
284-
`);
285-
});
286-
});
287229
});

packages/core/src/rules/oas3/__tests__/struct/referenceableScalars.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,38 @@ describe('Referenceable scalars', () => {
6969
});
7070
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
7171
});
72+
73+
it('should not report example value with $ref', async () => {
74+
const document = parseYamlToDocument(
75+
outdent`
76+
openapi: 3.2.0
77+
info:
78+
title: Test
79+
version: '1.0'
80+
paths:
81+
'/test':
82+
get:
83+
parameters:
84+
- name: test
85+
schema:
86+
type: object
87+
examples:
88+
test:
89+
value:
90+
$ref: not $ref, example
91+
`,
92+
__dirname + '/foobar.yaml'
93+
);
94+
95+
const results = await lintDocument({
96+
externalRefResolver: new BaseResolver(),
97+
document,
98+
config: await createConfig({
99+
rules: {
100+
'no-unresolved-refs': 'error',
101+
},
102+
}),
103+
});
104+
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
105+
});
72106
});

0 commit comments

Comments
 (0)