Skip to content

Commit

Permalink
fix: example
Browse files Browse the repository at this point in the history
  • Loading branch information
v8tenko committed Nov 27, 2023
1 parent a782071 commit 5a7beb0
Show file tree
Hide file tree
Showing 11 changed files with 353 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/__snapshots__/combiners/complex.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`basic openapi project renders description 1`] = `
exports[`operators complex test renders ok 1`] = `
"<div class="openapi">
# basic
# complex
## Request
Expand Down
218 changes: 218 additions & 0 deletions src/__snapshots__/example.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`openapi project with examples renders example field 1`] = `
"<div class="openapi">
# example
## Request
<div class="openapi__request__wrapper">
<div class="openapi__request" style="--method: var(--dc-openapi-methods-post)">
POST {.openapi__method}
\`\`\`
http://localhost:8080/test
\`\`\`
</div>
</div>
Generated server url{.openapi__request__description}
#### Body
{% cut "application/json" %}
\`\`\`json
{
"name": "Example"
}
\`\`\`
{% endcut %}
## Responses
<div class="openapi__response__code__200">
## 200 OK
Base 200 response
#### Body
{% cut "application/json" %}
\`\`\`json
{}
\`\`\`
{% endcut %}
</div>
<!-- markdownlint-disable-file -->
</div>"
`;

exports[`openapi project with examples renders example from allOf 1`] = `
"<div class="openapi">
# example
## Request
<div class="openapi__request__wrapper">
<div class="openapi__request" style="--method: var(--dc-openapi-methods-post)">
POST {.openapi__method}
\`\`\`
http://localhost:8080/test
\`\`\`
</div>
</div>
Generated server url{.openapi__request__description}
#### Body
{% cut "application/json" %}
\`\`\`json
{
"name": "string"
}
\`\`\`
{% endcut %}
#||| **Name** | **Type** | **Description** ||
|| name | string | |||#
## Responses
<div class="openapi__response__code__200">
## 200 OK
Base 200 response
#### Body
{% cut "application/json" %}
\`\`\`json
{}
\`\`\`
{% endcut %}
</div>
<!-- markdownlint-disable-file -->
</div>"
`;

exports[`openapi project with examples renders example from oneOf 1`] = `
"<div class="openapi">
# example
## Request
<div class="openapi__request__wrapper">
<div class="openapi__request" style="--method: var(--dc-openapi-methods-post)">
POST {.openapi__method}
\`\`\`
http://localhost:8080/test
\`\`\`
</div>
</div>
Generated server url{.openapi__request__description}
#### Body
{% cut "application/json" %}
\`\`\`json
{
"name": "string"
}
\`\`\`
{% endcut %}
#||| **Name** | **Type** | **Description** ||
|| ...rest | oneOf | [Cat](#cat) |||#
#### Or value from:
### Cat
#||| **Name** | **Type** | **Description** ||
|| name | string | |||#
## Responses
<div class="openapi__response__code__200">
## 200 OK
Base 200 response
#### Body
{% cut "application/json" %}
\`\`\`json
{}
\`\`\`
{% endcut %}
</div>
<!-- markdownlint-disable-file -->
</div>"
`;
4 changes: 2 additions & 2 deletions src/__snapshots__/required.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`description renders correct description 1`] = `
exports[`required renders correct required 1`] = `
"<div class="openapi">
# description
# required
## Request
Expand Down
5 changes: 3 additions & 2 deletions src/__tests__/basic.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {DocumentBuilder, run} from './__helpers__/run';

const name = 'basic';
describe('basic openapi project', () => {
it('renders description', async () => {
const spec = new DocumentBuilder('basic')
const spec = new DocumentBuilder(name)
.response(200, {
description: 'Base 200 response',
schema: {
Expand Down Expand Up @@ -35,7 +36,7 @@ describe('basic openapi project', () => {

const fs = await run(spec);

const page = fs.match('basic');
const page = fs.match(name);

expect(page).toMatchSnapshot();
});
Expand Down
9 changes: 5 additions & 4 deletions src/__tests__/combiners/allOf.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {DocumentBuilder, run} from '../__helpers__/run';

const name = 'allOf';
describe('allOf operator support', () => {
it('renders simple allOf', async () => {
const spec = new DocumentBuilder('allOf')
const spec = new DocumentBuilder(name)
.component('Cat', {
type: 'object',
properties: {
Expand Down Expand Up @@ -60,13 +61,13 @@ describe('allOf operator support', () => {

const fs = await run(spec);

const page = fs.match('allOf');
const page = fs.match(name);

expect(page).toMatchSnapshot();
});

it('renders single allOf', async () => {
const spec = new DocumentBuilder('allOf')
const spec = new DocumentBuilder(name)
.component('Cat', {
type: 'object',
properties: {
Expand Down Expand Up @@ -117,7 +118,7 @@ describe('allOf operator support', () => {

const fs = await run(spec);

const page = fs.match('allOf');
const page = fs.match(name);

expect(page).toMatchSnapshot();
});
Expand Down
9 changes: 5 additions & 4 deletions src/__tests__/combiners/complex.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {DocumentBuilder, run} from '../__helpers__/run';

describe('basic openapi project', () => {
it('renders description', async () => {
const spec = new DocumentBuilder('basic')
const name = 'complex';
describe('operators complex test', () => {
it('renders ok', async () => {
const spec = new DocumentBuilder(name)
.component('Cat', {
type: 'object',
properties: {
Expand Down Expand Up @@ -102,7 +103,7 @@ describe('basic openapi project', () => {

const fs = await run(spec);

const page = fs.match('basic');
const page = fs.match(name);

expect(page).toMatchSnapshot();
});
Expand Down
13 changes: 7 additions & 6 deletions src/__tests__/combiners/oneOf.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {DocumentBuilder, run} from '../__helpers__/run';

const name = 'oneOf';
describe('oneOf operator support', () => {
it('renders empty', async () => {
const spec = new DocumentBuilder('oneOf')
const spec = new DocumentBuilder(name)
.component('Cat', {
type: 'object',
properties: {
Expand Down Expand Up @@ -42,13 +43,13 @@ describe('oneOf operator support', () => {

const fs = await run(spec);

const page = fs.match('oneOf');
const page = fs.match(name);

expect(page).toMatchSnapshot();
});

it('renders filled', async () => {
const spec = new DocumentBuilder('oneOf')
const spec = new DocumentBuilder(name)
.component('Cat', {
type: 'object',
properties: {
Expand Down Expand Up @@ -104,13 +105,13 @@ describe('oneOf operator support', () => {

const fs = await run(spec);

const page = fs.match('oneOf');
const page = fs.match(name);

expect(page).toMatchSnapshot();
});

it('renders parameter', async () => {
const spec = new DocumentBuilder('oneOf')
const spec = new DocumentBuilder(name)
.component('Cat', {
type: 'object',
properties: {
Expand Down Expand Up @@ -160,7 +161,7 @@ describe('oneOf operator support', () => {

const fs = await run(spec);

const page = fs.match('oneOf');
const page = fs.match(name);

expect(page).toMatchSnapshot();
});
Expand Down
10 changes: 6 additions & 4 deletions src/__tests__/description.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {DocumentBuilder, run} from './__helpers__/run';

const name = 'description';
describe('description', () => {
it('renders correct description', async () => {
const spec = new DocumentBuilder('description')
const spec = new DocumentBuilder(name)
.component('Pet', {
allOf: [DocumentBuilder.ref('Cat', 'From allOf in Pet')],
description: 'From pet',
Expand Down Expand Up @@ -49,11 +50,12 @@ describe('description', () => {
},
},
},
});
})
.build();

const fs = await run(spec.build());
const fs = await run(spec);

const page = fs.match('description.md');
const page = fs.match(name);

expect(page).toMatchSnapshot();
});
Expand Down
Loading

0 comments on commit 5a7beb0

Please sign in to comment.