Skip to content

Commit 90d6ec2

Browse files
committed
chore: Add tests
1 parent d21c3ba commit 90d6ec2

File tree

2 files changed

+142
-0
lines changed

2 files changed

+142
-0
lines changed

src/__snapshots__/examples/base.test.ts.snap

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,5 +285,116 @@ Base 200 response
285285
286286
287287
288+
[*Deprecated]: No longer supported, please use an alternative and newer version."
289+
`;
290+
291+
exports[`openapi project with examples renders example from ref 1`] = `
292+
"<div class="openapi">
293+
294+
# example
295+
296+
## Request
297+
298+
<div class="openapi__requests">
299+
300+
<div class="openapi__request__wrapper" style="--method: var(--dc-openapi-methods-post);margin-bottom: 12px">
301+
302+
<div class="openapi__request">
303+
304+
POST {.openapi__method}
305+
\`\`\`text translate=no
306+
http://localhost:8080/test
307+
\`\`\`
308+
309+
310+
311+
</div>
312+
313+
Generated server url
314+
315+
</div>
316+
317+
</div>
318+
319+
## Responses
320+
321+
<div class="openapi__response__code__200">
322+
323+
## 200 OK
324+
325+
Base 200 response
326+
327+
<div class="openapi-entity">
328+
329+
### Body
330+
331+
{% cut "application/json" %}
332+
333+
334+
\`\`\`json translate=no
335+
{
336+
"title": {
337+
"en_US": "Nestle milk chocolate-caramel",
338+
"ru_RU": "Nestle молочный шоколад-карамель",
339+
"es_ES": "Nestlé chocolate con leche y caramelo"
340+
}
341+
}
342+
\`\`\`
343+
344+
345+
{% endcut %}
346+
347+
348+
#|||
349+
**Name**
350+
|
351+
**Description**
352+
||
353+
354+
||
355+
title {.openapi-table-parameter-name}
356+
|
357+
**Type:** [Cat](#cat)
358+
359+
Test description
360+
361+
*Example:*{.openapi-description-annotation}
362+
\`\`\`
363+
{
364+
"en_US": "Nestle milk chocolate-caramel",
365+
"ru_RU": "Nestle молочный шоколад-карамель",
366+
"es_ES": "Nestlé chocolate con leche y caramelo"
367+
}
368+
\`\`\`
369+
370+
|||#
371+
372+
</div>
373+
374+
<div class="openapi-entity">
375+
376+
### Cat
377+
378+
#|||
379+
**Name**
380+
|
381+
**Description**
382+
||
383+
384+
||
385+
...rest {.openapi-table-parameter-name}
386+
|
387+
**Type:** string
388+
|||#
389+
390+
</div>
391+
392+
</div>
393+
<!-- markdownlint-disable-file -->
394+
395+
</div>
396+
397+
398+
288399
[*Deprecated]: No longer supported, please use an alternative and newer version."
289400
`;

src/__tests__/examples/base.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,37 @@ describe('openapi project with examples', () => {
2727
expect(page).toMatchSnapshot();
2828
});
2929

30+
it('renders example from ref', async () => {
31+
const spec = new DocumentBuilder(name)
32+
.response(200, {
33+
description: 'Base 200 response',
34+
schema: {
35+
type: 'object',
36+
properties: {
37+
title: DocumentBuilder.ref('Cat', 'Test description'),
38+
},
39+
},
40+
})
41+
.component('Cat', {
42+
type: 'object',
43+
additionalProperties: {
44+
type: 'string',
45+
},
46+
example: {
47+
en_US: 'Nestle milk chocolate-caramel',
48+
ru_RU: 'Nestle молочный шоколад-карамель',
49+
es_ES: 'Nestlé chocolate con leche y caramelo',
50+
},
51+
})
52+
.build();
53+
54+
const fs = await run(spec);
55+
56+
const page = fs.match(name);
57+
58+
expect(page).toMatchSnapshot();
59+
});
60+
3061
it('renders example from oneOf', async () => {
3162
const spec = new DocumentBuilder(name)
3263
.request({

0 commit comments

Comments
 (0)