Skip to content

Commit 50d2c94

Browse files
committed
Add test for nested folder generation using tags in OpenAPI conversion
1 parent de91630 commit 50d2c94

2 files changed

Lines changed: 321 additions & 0 deletions

File tree

Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
{
2+
"openapi": "3.0.0",
3+
"info": {
4+
"title": "help me please",
5+
"version": "1.0.0",
6+
"description": "Buy or rent spacecrafts updated to new content\n\nContact Support:\n Name: Jon"
7+
},
8+
"servers": [
9+
{
10+
"url": "{{baseUrl}}"
11+
}
12+
],
13+
"paths": {
14+
"/spacecraft/{spacecraftId}/help/{helpme}/{help}/{user-id+v1+special}": {
15+
"parameters": [
16+
{
17+
"name": "spacecraftId",
18+
"in": "path",
19+
"required": true,
20+
"description": "(Required) ",
21+
"example": "asdfadsfasf",
22+
"schema": {
23+
"deprecated": false,
24+
"type": "string"
25+
}
26+
},
27+
{
28+
"name": "helpme",
29+
"in": "path",
30+
"required": true,
31+
"description": "(Required) ",
32+
"example": "{{aDSASD}}",
33+
"schema": {
34+
"deprecated": false,
35+
"type": "string"
36+
}
37+
},
38+
{
39+
"name": "help",
40+
"in": "path",
41+
"required": true,
42+
"description": "(Required) ",
43+
"example": "{{help}}",
44+
"schema": {
45+
"deprecated": false,
46+
"type": "string"
47+
}
48+
},
49+
{
50+
"name": "user-id+v1+special",
51+
"in": "path",
52+
"required": true,
53+
"example": "1",
54+
"schema": {
55+
"type": "integer"
56+
}
57+
}
58+
],
59+
"get": {
60+
"summary": "Read a spacecraft",
61+
"tags": [
62+
"spacecraft",
63+
"help"
64+
],
65+
"parameters": [
66+
{
67+
"name": "Accept",
68+
"in": "header",
69+
"required": false,
70+
"example": "application/json",
71+
"schema": {
72+
"deprecated": false
73+
}
74+
}
75+
],
76+
"responses": {
77+
"200": {
78+
"headers": {
79+
"Content-Type": {
80+
"schema": {
81+
"deprecated": false,
82+
"type": "string"
83+
},
84+
"example": "application/json"
85+
}
86+
},
87+
"description": "The spacecraft corresponding to the provided `spacecraftId`",
88+
"content": {
89+
"application/json": {
90+
"schema": {
91+
"type": "object",
92+
"properties": {
93+
"id": {
94+
"type": "string"
95+
},
96+
"name": {
97+
"type": "string"
98+
},
99+
"type": {
100+
"type": "string"
101+
},
102+
"description": {
103+
"type": "string"
104+
}
105+
}
106+
},
107+
"example": {
108+
"id": "string",
109+
"name": "string",
110+
"type": "string",
111+
"description": "string"
112+
}
113+
}
114+
}
115+
},
116+
"404": {
117+
"headers": {
118+
"Content-Type": {
119+
"schema": {
120+
"deprecated": false,
121+
"type": "string"
122+
},
123+
"example": "application/json"
124+
}
125+
},
126+
"description": "No spacecraft found for the provided `spacecraftId`",
127+
"content": {
128+
"application/json": {
129+
"schema": {
130+
"type": "object",
131+
"properties": {
132+
"message": {
133+
"type": "string"
134+
}
135+
}
136+
},
137+
"example": {
138+
"message": "string"
139+
}
140+
}
141+
}
142+
},
143+
"500": {
144+
"headers": {
145+
"Content-Type": {
146+
"schema": {
147+
"deprecated": false,
148+
"type": "string"
149+
},
150+
"example": "application/json"
151+
}
152+
},
153+
"description": "Unexpected error",
154+
"content": {
155+
"application/json": {
156+
"schema": {
157+
"type": "object",
158+
"properties": {
159+
"message": {
160+
"type": "string"
161+
}
162+
}
163+
},
164+
"example": {
165+
"message": "string"
166+
}
167+
}
168+
}
169+
}
170+
}
171+
},
172+
"post": {
173+
"summary": "Create a spacecraft",
174+
"tags": [
175+
"spacecraft"
176+
],
177+
"parameters": [
178+
{
179+
"name": "Accept",
180+
"in": "header",
181+
"required": false,
182+
"example": "application/json",
183+
"schema": {
184+
"deprecated": false
185+
}
186+
}
187+
],
188+
"responses": {
189+
"200": {
190+
"headers": {
191+
"Content-Type": {
192+
"schema": {
193+
"deprecated": false,
194+
"type": "string"
195+
},
196+
"example": "application/json"
197+
}
198+
},
199+
"description": "The spacecraft corresponding to the provided `spacecraftId`",
200+
"content": {
201+
"application/json": {
202+
"schema": {
203+
"type": "object",
204+
"properties": {
205+
"id": {
206+
"type": "string"
207+
},
208+
"name": {
209+
"type": "string"
210+
},
211+
"type": {
212+
"type": "string"
213+
},
214+
"description": {
215+
"type": "string"
216+
}
217+
}
218+
},
219+
"example": {
220+
"id": "string",
221+
"name": "string",
222+
"type": "string",
223+
"description": "string"
224+
}
225+
}
226+
}
227+
},
228+
"404": {
229+
"headers": {
230+
"Content-Type": {
231+
"schema": {
232+
"deprecated": false,
233+
"type": "string"
234+
},
235+
"example": "application/json"
236+
}
237+
},
238+
"description": "No spacecraft found for the provided `spacecraftId`",
239+
"content": {
240+
"application/json": {
241+
"schema": {
242+
"type": "object",
243+
"properties": {
244+
"message": {
245+
"type": "string"
246+
}
247+
}
248+
},
249+
"example": {
250+
"message": "string"
251+
}
252+
}
253+
}
254+
},
255+
"500": {
256+
"headers": {
257+
"Content-Type": {
258+
"schema": {
259+
"deprecated": false,
260+
"type": "string"
261+
},
262+
"example": "application/json"
263+
}
264+
},
265+
"description": "Unexpected error",
266+
"content": {
267+
"application/json": {
268+
"schema": {
269+
"type": "object",
270+
"properties": {
271+
"message": {
272+
"type": "string"
273+
}
274+
}
275+
},
276+
"example": {
277+
"message": "string"
278+
}
279+
}
280+
}
281+
}
282+
}
283+
}
284+
}
285+
}
286+
}

test/unit/convertV2.test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,6 +1842,41 @@ describe('The convert v2 Function', function() {
18421842
});
18431843
});
18441844

1845+
it('Should convert using tags as folder strategy and generated nested folder', function () {
1846+
const someOperationDeprecatedUsingTags =
1847+
path.join(__dirname, VALID_OPENAPI_PATH, '/spacecraft_nested_tags.json'),
1848+
fileData = fs.readFileSync(someOperationDeprecatedUsingTags, 'utf8');
1849+
Converter.convertV2({ type: 'string', data: fileData },
1850+
{ folderStrategy: 'tags', nestedFolderHierarchy: true },
1851+
(err, result) => {
1852+
expect(err).to.be.null;
1853+
expect(result.result).to.be.true;
1854+
expect(result.output[0].data.item.length).to.equal(1);
1855+
expect(result.output[0].data.item[0].name).to.equal('spacecraft');
1856+
expect(result.output[0].data.item[0].item.length).to.equal(2);
1857+
expect(result.output[0].data.item[0].item[0].name).to.equal('help');
1858+
expect(result.output[0].data.item[0].item[0].item.length).to.equal(1);
1859+
expect(result.output[0].data.item[0].item[0].item[0].name).to.equal('Read a spacecraft');
1860+
expect(result.output[0].data.item[0].item[0].item[0]).to.have.keys(
1861+
'event',
1862+
'id',
1863+
'name',
1864+
'protocolProfileBehavior',
1865+
'request',
1866+
'response'
1867+
);
1868+
expect(result.output[0].data.item[0].item[1].name).to.equal('Create a spacecraft');
1869+
expect(result.output[0].data.item[0].item[1]).to.have.keys(
1870+
'event',
1871+
'id',
1872+
'name',
1873+
'protocolProfileBehavior',
1874+
'request',
1875+
'response'
1876+
);
1877+
});
1878+
});
1879+
18451880
describe('[Github #57] - folderStrategy option (value: Tags) ' + tagsFolderSpec, function() {
18461881
async.series({
18471882
pathsOutput: (cb) => {

0 commit comments

Comments
 (0)