Skip to content

Commit b0ffbb9

Browse files
committed
Added test scenarios for yaml output
1 parent da3d42c commit b0ffbb9

File tree

3 files changed

+175
-0
lines changed

3 files changed

+175
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
openapi: 3.0.0
2+
info:
3+
version: 1.0.0
4+
title: Sample API
5+
description: Buy or rent spacecrafts
6+
paths:
7+
'/spacecrafts/{spacecraftId}':
8+
parameters:
9+
- name: spacecraftId
10+
description: The unique identifier of the spacecraft
11+
in: path
12+
required: true
13+
schema:
14+
$ref: >-
15+
#/components/schemas/https_localhost8080_SpacecraftId.yaml-_SpacecraftId
16+
get:
17+
summary: Read a spacecraft
18+
responses:
19+
'200':
20+
description: The spacecraft corresponding to the provided `spacecraftId`
21+
content:
22+
application/json:
23+
schema:
24+
$ref: '#/components/schemas/Spacecraft'
25+
components:
26+
schemas:
27+
SpacecraftId:
28+
description: The unique identifier of a spacecraft
29+
type: string
30+
Spacecraft:
31+
type: object
32+
required:
33+
- variant
34+
- fuelFlowRate
35+
- type
36+
properties:
37+
id:
38+
description: THE ID
39+
type: string
40+
variant:
41+
description: The identifier of a spacecraft
42+
type: string
43+
https_localhost8080_SpacecraftId.yaml-_SpacecraftId:
44+
description: The unique identifier of a spacecraft
45+
type: string
46+
securitySchemes:
47+
ApiKey:
48+
type: apiKey
49+
in: header
50+
name: X-Api-Key
51+
security:
52+
- ApiKey: []
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
openapi: 3.0.0
3+
info:
4+
version: 1.0.0
5+
title: Sample API
6+
description: Buy or rent spacecrafts
7+
paths:
8+
"/spacecrafts/{spacecraftId}":
9+
parameters:
10+
- name: spacecraftId
11+
description: The unique identifier of the spacecraft
12+
in: path
13+
required: true
14+
schema:
15+
"$ref": https://localhost:8080/SpacecraftId.yaml#/SpacecraftId
16+
get:
17+
summary: Read a spacecraft
18+
responses:
19+
'200':
20+
description: The spacecraft corresponding to the provided `spacecraftId`
21+
content:
22+
application/json:
23+
schema:
24+
"$ref": "#/components/schemas/Spacecraft"
25+
components:
26+
schemas:
27+
SpacecraftId:
28+
description: The unique identifier of a spacecraft
29+
type: string
30+
Spacecraft:
31+
type: object
32+
required:
33+
- variant
34+
- fuelFlowRate
35+
- type
36+
properties:
37+
id:
38+
description: THE ID
39+
type: string
40+
variant:
41+
description: The identifier of a spacecraft
42+
type: string
43+
securitySchemes:
44+
ApiKey:
45+
type: apiKey
46+
in: header
47+
name: X-Api-Key
48+
security:
49+
- ApiKey: []

test/unit/bundle.test.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2835,6 +2835,80 @@ describe('bundle files method - 3.0', function () {
28352835
expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected);
28362836
});
28372837

2838+
it('Should return bundled file as yaml with yaml content remote refs - remote_url_refs', async function () {
2839+
let contentRootFile = fs.readFileSync(remoteURLRefExamples + '/yaml/root.yaml', 'utf8'),
2840+
spacecraftId = fs.readFileSync(remoteURLRefExamples + '/yaml/SpacecraftId.yaml', 'utf8'),
2841+
2842+
remoteRefResolver = async (refURL) => {
2843+
if (refURL.includes('SpacecraftId')) {
2844+
return spacecraftId;
2845+
}
2846+
},
2847+
expected = fs.readFileSync(remoteURLRefExamples + '/yaml/expected.yaml', 'utf8'),
2848+
input = {
2849+
type: 'multiFile',
2850+
specificationVersion: '3.0',
2851+
rootFiles: [
2852+
{
2853+
path: 'root.json'
2854+
}
2855+
],
2856+
data: [
2857+
{
2858+
path: 'root.json',
2859+
content: contentRootFile
2860+
}
2861+
],
2862+
options: {},
2863+
bundleFormat: 'YAML',
2864+
remoteRefResolver
2865+
};
2866+
2867+
const res = await Converter.bundle(input);
2868+
2869+
expect(res).to.not.be.empty;
2870+
expect(res.result).to.be.true;
2871+
expect(res.output.specification.version).to.equal('3.0');
2872+
expect(res.output.data[0].bundledContent).to.be.equal(expected);
2873+
});
2874+
2875+
it('Should return bundled file as json with yaml content refs and root file - remote_url_refs', async function () {
2876+
let contentRootFile = fs.readFileSync(remoteURLRefExamples + '/yaml/root.yaml', 'utf8'),
2877+
spacecraftId = fs.readFileSync(remoteURLRefExamples + '/yaml/SpacecraftId.yaml', 'utf8'),
2878+
2879+
remoteRefResolver = async (refURL) => {
2880+
if (refURL.includes('SpacecraftId')) {
2881+
return spacecraftId;
2882+
}
2883+
},
2884+
expected = fs.readFileSync(remoteURLRefExamples + '/yaml/expected.json', 'utf8'),
2885+
input = {
2886+
type: 'multiFile',
2887+
specificationVersion: '3.0',
2888+
rootFiles: [
2889+
{
2890+
path: 'root.json'
2891+
}
2892+
],
2893+
data: [
2894+
{
2895+
path: 'root.json',
2896+
content: contentRootFile
2897+
}
2898+
],
2899+
options: {},
2900+
bundleFormat: 'JSON',
2901+
remoteRefResolver
2902+
};
2903+
2904+
const res = await Converter.bundle(input);
2905+
2906+
expect(res).to.not.be.empty;
2907+
expect(res.result).to.be.true;
2908+
expect(res.output.specification.version).to.equal('3.0');
2909+
expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected);
2910+
});
2911+
28382912
it('Should return bundled file as json without resolving the reference if resolver threw err - remote_url_refs',
28392913
async function () {
28402914
let contentRootFile = fs.readFileSync(remoteURLRefExamples + '/root_3.json', 'utf8'),

0 commit comments

Comments
 (0)