Skip to content

Commit 06355bd

Browse files
committed
tests: update self-file reference normalization tests and fixtures for OAS2 and AsyncAPI 3
1 parent 1ec6e22 commit 06355bd

File tree

11 files changed

+136
-177
lines changed

11 files changed

+136
-177
lines changed
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
apis:
22
main:
33
root: ./openapi.yaml
4-
5-
extends:
6-
- recommended

packages/core/src/__tests__/__snapshots__/bundle.test.ts.snap

Lines changed: 57 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -104,40 +104,6 @@ components: {}
104104
105105
`;
106106

107-
exports[`bundle > should dereference even if self-file explicit $ref is used 1`] = `
108-
openapi: 3.0.0
109-
info:
110-
title: Self-file ref normalization
111-
version: 1.0.0
112-
license:
113-
name: MIT
114-
servers:
115-
- url: https://api.example.org
116-
security: []
117-
paths:
118-
/test:
119-
get:
120-
summary: Test
121-
operationId: getTest
122-
parameters:
123-
- name: myParam
124-
in: query
125-
schema: &ref_0
126-
type: string
127-
responses:
128-
'200':
129-
description: OK
130-
'400':
131-
description: Bad Request
132-
components:
133-
parameters:
134-
myParam:
135-
name: myParam
136-
in: query
137-
schema: *ref_0
138-
139-
`;
140-
141107
exports[`bundle > should dereferenced correctly when used with dereference 1`] = `
142108
openapi: 3.0.0
143109
paths:
@@ -158,66 +124,54 @@ components:
158124
159125
`;
160126

161-
exports[`bundle > should normalize self-file explicit $ref in oas2 1`] = `
162-
swagger: '2.0'
127+
exports[`bundle > should normalize self-file explicit $ref in nested referenced file 1`] = `
128+
openapi: 3.0.0
163129
info:
164-
title: OAS2 self-file ref
165-
version: '1.0'
166-
license:
167-
name: MIT
168-
host: example.com
169-
schemes:
170-
- https
171-
security: []
130+
title: OAS3 root with external ref to file with self-refs
131+
version: 1.0.0
172132
paths:
173133
/test:
174134
get:
175-
summary: Test
176-
operationId: getTest
177135
parameters:
178-
- $ref: '#/parameters/p1'
179-
responses:
180-
'200':
181-
description: OK
182-
'400':
183-
description: Bad Request
184-
parameters:
185-
p1:
186-
name: p1
187-
in: query
188-
type: string
136+
- $ref: '#/components/parameters/testParam'
137+
components:
138+
schemas:
139+
NestedSchema:
140+
type: object
141+
properties:
142+
value:
143+
type: string
144+
TestSchema:
145+
type: object
146+
properties:
147+
id:
148+
type: string
149+
nested:
150+
$ref: '#/components/schemas/NestedSchema'
151+
parameters:
152+
testParam:
153+
name: testParam
154+
in: query
155+
schema:
156+
$ref: '#/components/schemas/TestSchema'
189157
190158
`;
191159

192-
exports[`bundle > should normalize self-file explicit $ref to internal pointer 1`] = `
193-
openapi: 3.0.0
160+
exports[`bundle > should normalize self-file explicit $ref in oas2 1`] = `
161+
swagger: '2.0'
194162
info:
195-
title: Self-file ref normalization
196-
version: 1.0.0
197-
license:
198-
name: MIT
199-
servers:
200-
- url: https://api.example.org
201-
security: []
163+
title: OAS2 self-file ref
164+
version: '1.0'
202165
paths:
203166
/test:
204167
get:
205-
summary: Test
206-
operationId: getTest
207168
parameters:
208-
- $ref: '#/components/parameters/myParam'
209-
responses:
210-
'200':
211-
description: OK
212-
'400':
213-
description: Bad Request
214-
components:
215-
parameters:
216-
myParam:
217-
name: myParam
218-
in: query
219-
schema:
220-
type: string
169+
- $ref: '#/parameters/testParam'
170+
parameters:
171+
testParam:
172+
name: testParam
173+
in: query
174+
type: string
221175
222176
`;
223177

@@ -381,32 +335,42 @@ info:
381335
title: AsyncAPI 2 self-file ref
382336
version: 1.0.0
383337
channels:
384-
c:
338+
user/test:
385339
subscribe:
386340
message:
387341
payload:
388-
$ref: '#/components/schemas/A'
342+
$ref: '#/components/schemas/TestPayload'
389343
components:
390344
schemas:
391-
A:
345+
TestPayload:
392346
type: string
393347
394348
`;
395349

396-
exports[`bundle async > should normalize self-file explicit $ref in asyncapi 3 1`] = `
350+
exports[`bundle async > should normalize self-file explicit $ref in nested referenced file for async3 1`] = `
397351
asyncapi: 3.0.0
398352
info:
399-
title: AsyncAPI 3 self-file ref
353+
title: AsyncAPI 3 root with external ref to file with self-refs
400354
version: 1.0.0
401355
channels:
402-
test:
356+
userTest:
403357
messages:
404-
M1:
405-
$ref: '#/components/messages/M'
358+
TestMessage:
359+
payload:
360+
$ref: '#/components/schemas/TestPayload'
406361
components:
407-
messages:
408-
M:
409-
payload:
410-
type: string
362+
schemas:
363+
NestedSchema:
364+
type: object
365+
properties:
366+
value:
367+
type: string
368+
TestPayload:
369+
type: object
370+
properties:
371+
id:
372+
type: string
373+
nested:
374+
$ref: '#/components/schemas/NestedSchema'
411375
412376
`;

packages/core/src/__tests__/bundle.test.ts

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -274,39 +274,26 @@ describe('bundle', () => {
274274
`);
275275
});
276276

277-
it('should normalize self-file explicit $ref to internal pointer', async () => {
278-
const config = await createConfig({});
279-
277+
it('should normalize self-file explicit $ref in oas2', async () => {
280278
const { bundle: res, problems } = await bundle({
281-
config,
282-
ref: path.join(__dirname, 'fixtures/self-file-refs/oas3.yaml'),
279+
config: await createConfig({}),
280+
ref: path.join(__dirname, 'fixtures/self-file-refs/oas2.yaml'),
283281
});
284-
285282
expect(problems).toHaveLength(0);
286283
expect(res.parsed).toMatchSnapshot();
287284
});
288285

289-
it('should dereference even if self-file explicit $ref is used', async () => {
286+
it('should normalize self-file explicit $ref in nested referenced file', async () => {
290287
const config = await createConfig({});
291288

292289
const { bundle: res, problems } = await bundle({
293290
config,
294-
ref: path.join(__dirname, 'fixtures/self-file-refs/oas3.yaml'),
295-
dereference: true,
291+
ref: path.join(__dirname, 'fixtures/self-file-refs/oas3-root.yaml'),
296292
});
297293

298294
expect(problems).toHaveLength(0);
299295
expect(res.parsed).toMatchSnapshot();
300296
});
301-
302-
it('should normalize self-file explicit $ref in oas2', async () => {
303-
const { bundle: res, problems } = await bundle({
304-
config: await createConfig({}),
305-
ref: path.join(__dirname, 'fixtures/self-file-refs/oas2.yaml'),
306-
});
307-
expect(problems).toHaveLength(0);
308-
expect(res.parsed).toMatchSnapshot();
309-
});
310297
});
311298

312299
describe('bundleFromString', () => {
@@ -477,10 +464,10 @@ describe('bundle async', () => {
477464
expect(res.parsed).toMatchSnapshot();
478465
});
479466

480-
it('should normalize self-file explicit $ref in asyncapi 3', async () => {
467+
it('should normalize self-file explicit $ref in nested referenced file for async3', async () => {
481468
const { bundle: res, problems } = await bundle({
482469
config: await createConfig({}),
483-
ref: path.join(__dirname, 'fixtures/self-file-refs/async3.yaml'),
470+
ref: path.join(__dirname, 'fixtures/self-file-refs/async3-root.yaml'),
484471
});
485472

486473
expect(problems).toHaveLength(0);

packages/core/src/__tests__/fixtures/self-file-refs/async2.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ info:
33
title: AsyncAPI 2 self-file ref
44
version: '1.0.0'
55
channels:
6-
c:
6+
user/test:
77
subscribe:
88
message:
99
payload:
10-
$ref: 'async2.yaml#/components/schemas/A'
10+
$ref: 'async2.yaml#/components/schemas/TestPayload'
1111
components:
1212
schemas:
13-
A:
13+
TestPayload:
1414
type: string
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
asyncapi: 3.0.0
2+
info:
3+
title: AsyncAPI 3 nested file with self-refs
4+
version: '1.0.0'
5+
channels: {}
6+
components:
7+
messages:
8+
TestMessage:
9+
payload:
10+
$ref: 'async3-nested.yaml#/components/schemas/TestPayload'
11+
schemas:
12+
TestPayload:
13+
type: object
14+
properties:
15+
id:
16+
type: string
17+
nested:
18+
$ref: 'async3-nested.yaml#/components/schemas/NestedSchema'
19+
NestedSchema:
20+
type: object
21+
properties:
22+
value:
23+
type: string
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
asyncapi: 3.0.0
2+
info:
3+
title: AsyncAPI 3 root with external ref to file with self-refs
4+
version: '1.0.0'
5+
channels:
6+
userTest:
7+
messages:
8+
TestMessage:
9+
$ref: './async3-nested.yaml#/components/messages/TestMessage'

packages/core/src/__tests__/fixtures/self-file-refs/async3.yaml

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/core/src/__tests__/fixtures/self-file-refs/oas2.yaml

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,13 @@ swagger: '2.0'
22
info:
33
title: OAS2 self-file ref
44
version: '1.0'
5-
license:
6-
name: MIT
7-
host: example.com
8-
schemes:
9-
- https
10-
security: []
115
paths:
126
/test:
137
get:
14-
summary: Test
15-
operationId: getTest
168
parameters:
17-
- $ref: 'oas2.yaml#/parameters/p1'
18-
responses:
19-
200:
20-
description: OK
21-
400:
22-
description: Bad Request
9+
- $ref: 'oas2.yaml#/parameters/testParam'
2310
parameters:
24-
p1:
25-
name: p1
11+
testParam:
12+
name: testParam
2613
in: query
2714
type: string
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
openapi: 3.0.0
2+
info:
3+
title: OAS3 nested file with self-refs
4+
version: 1.0.0
5+
paths: {}
6+
components:
7+
parameters:
8+
testParam:
9+
name: testParam
10+
in: query
11+
schema:
12+
$ref: 'oas3-nested.yaml#/components/schemas/TestSchema'
13+
schemas:
14+
TestSchema:
15+
type: object
16+
properties:
17+
id:
18+
type: string
19+
nested:
20+
$ref: 'oas3-nested.yaml#/components/schemas/NestedSchema'
21+
NestedSchema:
22+
type: object
23+
properties:
24+
value:
25+
type: string
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
openapi: 3.0.0
2+
info:
3+
title: OAS3 root with external ref to file with self-refs
4+
version: 1.0.0
5+
paths:
6+
/test:
7+
get:
8+
parameters:
9+
- $ref: './oas3-nested.yaml#/components/parameters/testParam'

0 commit comments

Comments
 (0)