Skip to content

Commit 91e04f1

Browse files
committed
test(reference): unit tests for resolving references for Server Variable in AsyncAPI3
1 parent a00cd10 commit 91e04f1

File tree

5 files changed

+115
-0
lines changed

5 files changed

+115
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[
2+
{
3+
"asyncapi": "3.0.0",
4+
"components": {
5+
"serverVariables": {
6+
"variable1": {
7+
"enum": ["a", "b", "c"]
8+
},
9+
"variable2": {
10+
"enum": ["a", "b", "c"]
11+
}
12+
}
13+
}
14+
}
15+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"asyncapi": "3.0.0",
3+
"components": {
4+
"serverVariables": {
5+
"variable1": {
6+
"enum": ["a", "b", "c"]
7+
},
8+
"variable2": {
9+
"$ref": "#/components/serverVariables/variable1"
10+
}
11+
}
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[
2+
{
3+
"asyncapi": "3.0.0",
4+
"components": {
5+
"servers": {
6+
"server1": {
7+
"host": "http://example.com",
8+
"protocol": "protocol",
9+
"variables": {
10+
"variable1": {
11+
"enum": ["a", "b", "c"]
12+
},
13+
"variable2": {
14+
"enum": ["a", "b", "c"]
15+
}
16+
}
17+
}
18+
}
19+
}
20+
}
21+
]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"asyncapi": "3.0.0",
3+
"components": {
4+
"servers": {
5+
"server1": {
6+
"host": "http://example.com",
7+
"protocol": "protocol",
8+
"variables": {
9+
"variable1": {
10+
"enum": ["a", "b", "c"]
11+
},
12+
"variable2": {
13+
"$ref": "#/components/servers/server1/variables/variable1"
14+
}
15+
}
16+
}
17+
}
18+
}
19+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import path from 'node:path';
2+
import { assert } from 'chai';
3+
import { toValue } from '@swagger-api/apidom-core';
4+
import { mediaTypes } from '@swagger-api/apidom-ns-asyncapi-3';
5+
import { fileURLToPath } from 'node:url';
6+
7+
import { loadJsonFile } from '../../../../helpers.ts';
8+
import { dereference } from '../../../../../src/index.ts';
9+
10+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
11+
const rootFixturePath = path.join(__dirname, 'fixtures');
12+
13+
describe('dereference', function () {
14+
context('strategies', function () {
15+
context('asyncapi-3', function () {
16+
context('ServerVariable Object', function () {
17+
context('given in server/variables field', function () {
18+
const fixturePath = path.join(rootFixturePath, 'server-variables');
19+
20+
specify('should dereference', async function () {
21+
const rootFilePath = path.join(fixturePath, 'root.json');
22+
const actual = await dereference(rootFilePath, {
23+
parse: { mediaType: mediaTypes.latest('json') },
24+
});
25+
const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json'));
26+
27+
assert.deepEqual(toValue(actual), expected);
28+
});
29+
});
30+
31+
context('given in components/serverVariables field', function () {
32+
const fixturePath = path.join(rootFixturePath, 'components-server-variables');
33+
34+
specify('should dereference', async function () {
35+
const rootFilePath = path.join(fixturePath, 'root.json');
36+
const actual = await dereference(rootFilePath, {
37+
parse: { mediaType: mediaTypes.latest('json') },
38+
});
39+
const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json'));
40+
41+
assert.deepEqual(toValue(actual), expected);
42+
});
43+
});
44+
});
45+
});
46+
});
47+
});

0 commit comments

Comments
 (0)