Skip to content

Commit 511befd

Browse files
committed
fix: do not resolve $ref in examples.value
1 parent a75ef9d commit 511befd

13 files changed

Lines changed: 496 additions & 5 deletions

File tree

.changeset/loud-mails-hang.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@redocly/openapi-core": patch
3+
---
4+
5+
Do not resolve `$ref` inside `Examples.value` during bundling and linting
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"id": 123,
3+
"name": "Test User"
4+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
openapi: 3.2.0
2+
info:
3+
title: Test API
4+
version: 1.0.0
5+
paths:
6+
/test:
7+
get:
8+
summary: Test endpoint
9+
responses:
10+
'200':
11+
description: Successful response
12+
content:
13+
application/json:
14+
schema:
15+
type: object
16+
properties:
17+
id:
18+
type: integer
19+
name:
20+
type: string
21+
active:
22+
type: boolean
23+
example:
24+
$ref: example.json
25+
examples:
26+
Test:
27+
summary: Example with $ref in value (should NOT resolve)
28+
value:
29+
$ref: example.json
30+
31+
TestNested:
32+
summary: Example with nested $ref in value (should NOT resolve)
33+
value:
34+
user:
35+
$ref: example.json
36+
status: active
37+
38+
TestExternal:
39+
summary: Example with externalValue (should resolve)
40+
externalValue: example.json
41+
42+
TestDataValue:
43+
summary: Example with $ref in dataValue (should NOT resolve)
44+
dataValue:
45+
$ref: example.json
46+
47+
TestSerialized:
48+
summary: Example with serializedValue
49+
serializedValue: '{"id": 123, "name": "Test"}'
50+
51+
TestEmpty:
52+
summary: Example with empty value
53+
value: {}
54+
55+
TestPrimitive:
56+
summary: Example with primitive values
57+
value:
58+
string: 'hello'
59+
number: 42
60+
boolean: true
61+
null: null
62+
array: [1, 2, 3]
63+
object:
64+
nested: true
65+
66+
TestMultipleRefs:
67+
summary: Example with multiple $ref in value
68+
value:
69+
$ref: example.json
70+
fallback:
71+
$ref: example.json
72+
static: 'constant'
73+
74+
components:
75+
examples:
76+
UserExample:
77+
summary: User example with $ref in value
78+
value:
79+
$ref: example.json
80+
81+
UserExternal:
82+
summary: User example with externalValue
83+
externalValue: example.json
84+
85+
UserDataValue:
86+
summary: User example with dataValue
87+
dataValue:
88+
$ref: example.json
89+
90+
UserSerialized:
91+
summary: User example with serializedValue
92+
serializedValue: '{"id": 456, "name": "User"}'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
apis:
2+
main:
3+
root: openapi.yaml
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
openapi: 3.2.0
2+
info:
3+
title: Test API
4+
version: 1.0.0
5+
paths:
6+
/test:
7+
get:
8+
summary: Test endpoint
9+
responses:
10+
'200':
11+
description: Successful response
12+
content:
13+
application/json:
14+
schema:
15+
type: object
16+
properties:
17+
id:
18+
type: integer
19+
name:
20+
type: string
21+
active:
22+
type: boolean
23+
example:
24+
id: 123
25+
name: Test User
26+
examples:
27+
Test:
28+
summary: Example with $ref in value (should NOT resolve)
29+
value:
30+
$ref: example.json
31+
TestNested:
32+
summary: Example with nested $ref in value (should NOT resolve)
33+
value:
34+
user:
35+
$ref: example.json
36+
status: active
37+
TestExternal:
38+
summary: Example with externalValue (should resolve)
39+
value:
40+
id: 123
41+
name: Test User
42+
TestDataValue:
43+
summary: Example with $ref in dataValue (should NOT resolve)
44+
dataValue:
45+
$ref: example.json
46+
TestSerialized:
47+
summary: Example with serializedValue
48+
serializedValue: '{"id": 123, "name": "Test"}'
49+
TestEmpty:
50+
summary: Example with empty value
51+
value: {}
52+
TestPrimitive:
53+
summary: Example with primitive values
54+
value:
55+
string: hello
56+
number: 42
57+
boolean: true
58+
'null': null
59+
array:
60+
- 1
61+
- 2
62+
- 3
63+
object:
64+
nested: true
65+
TestMultipleRefs:
66+
summary: Example with multiple $ref in value
67+
value:
68+
$ref: example.json
69+
fallback:
70+
$ref: example.json
71+
static: constant
72+
components:
73+
examples:
74+
UserExample:
75+
summary: User example with $ref in value
76+
value:
77+
$ref: example.json
78+
UserExternal:
79+
summary: User example with externalValue
80+
value:
81+
id: 123
82+
name: Test User
83+
UserDataValue:
84+
summary: User example with dataValue
85+
dataValue:
86+
$ref: example.json
87+
UserSerialized:
88+
summary: User example with serializedValue
89+
serializedValue: '{"id": 456, "name": "User"}'
90+
91+
bundling openapi.yaml using configuration for api 'main'...
92+
📦 Created a bundle for openapi.yaml at stdout <test>ms.

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-
- When running `lint`, set this option to `true` to avoid resolving `$ref` fields in examples. Resolving `$ref`s in other parts of the API is unaffected.
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.
2525

2626
---
2727

docs/@v2/configuration/resolve.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ properties:
1212
doNotResolveExamples:
1313
type: boolean
1414
description: >-
15-
You can stop `lint` from resolving `$refs` in examples by setting this configuration option to `true`.
15+
Set this option to `true` to prevent resolving `$ref` fields in `Example`.
16+
This affects both `lint` and `bundle` commands.
1617
This does not affect `$ref` resolution in other parts of the API description.
1718
default: false
1819
http:

0 commit comments

Comments
 (0)