diff --git a/src/__snapshots__/combiners/complex.test.ts.snap b/src/__snapshots__/combiners/complex.test.ts.snap
index aff298d..c9786a8 100644
--- a/src/__snapshots__/combiners/complex.test.ts.snap
+++ b/src/__snapshots__/combiners/complex.test.ts.snap
@@ -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`] = `
"
-# basic
+# complex
## Request
diff --git a/src/__snapshots__/example.test.ts.snap b/src/__snapshots__/example.test.ts.snap
new file mode 100644
index 0000000..577371f
--- /dev/null
+++ b/src/__snapshots__/example.test.ts.snap
@@ -0,0 +1,218 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`openapi project with examples renders example field 1`] = `
+"
+
+# example
+
+## Request
+
+
+
+
+
+POST {.openapi__method}
+
+
+\`\`\`
+http://localhost:8080/test
+\`\`\`
+
+
+
+
+
+
+Generated server url{.openapi__request__description}
+
+#### Body
+
+{% cut "application/json" %}
+
+
+\`\`\`json
+{
+ "name": "Example"
+}
+\`\`\`
+
+
+{% endcut %}
+
+
+## Responses
+
+
+
+## 200 OK
+
+Base 200 response
+
+#### Body
+
+{% cut "application/json" %}
+
+
+\`\`\`json
+{}
+\`\`\`
+
+
+{% endcut %}
+
+
+
+
+
+
"
+`;
+
+exports[`openapi project with examples renders example from allOf 1`] = `
+"
+
+# example
+
+## Request
+
+
+
+
+
+POST {.openapi__method}
+
+
+\`\`\`
+http://localhost:8080/test
+\`\`\`
+
+
+
+
+
+
+Generated server url{.openapi__request__description}
+
+#### Body
+
+{% cut "application/json" %}
+
+
+\`\`\`json
+{
+ "name": "string"
+}
+\`\`\`
+
+
+{% endcut %}
+
+
+#||| **Name** | **Type** | **Description** ||
+
+|| name | string | |||#
+
+## Responses
+
+
+
+## 200 OK
+
+Base 200 response
+
+#### Body
+
+{% cut "application/json" %}
+
+
+\`\`\`json
+{}
+\`\`\`
+
+
+{% endcut %}
+
+
+
+
+
+
"
+`;
+
+exports[`openapi project with examples renders example from oneOf 1`] = `
+"
+
+# example
+
+## Request
+
+
+
+
+
+POST {.openapi__method}
+
+
+\`\`\`
+http://localhost:8080/test
+\`\`\`
+
+
+
+
+
+
+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
+
+
+
+## 200 OK
+
+Base 200 response
+
+#### Body
+
+{% cut "application/json" %}
+
+
+\`\`\`json
+{}
+\`\`\`
+
+
+{% endcut %}
+
+
+
+
+
+
"
+`;
diff --git a/src/__snapshots__/required.test.ts.snap b/src/__snapshots__/required.test.ts.snap
index 7ecf58f..69d7bca 100644
--- a/src/__snapshots__/required.test.ts.snap
+++ b/src/__snapshots__/required.test.ts.snap
@@ -1,9 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`description renders correct description 1`] = `
+exports[`required renders correct required 1`] = `
"
-# description
+# required
## Request
diff --git a/src/__tests__/basic.test.ts b/src/__tests__/basic.test.ts
index c731fc8..02b999a 100644
--- a/src/__tests__/basic.test.ts
+++ b/src/__tests__/basic.test.ts
@@ -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: {
@@ -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();
});
diff --git a/src/__tests__/combiners/allOf.test.ts b/src/__tests__/combiners/allOf.test.ts
index a625e30..59248e1 100644
--- a/src/__tests__/combiners/allOf.test.ts
+++ b/src/__tests__/combiners/allOf.test.ts
@@ -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: {
@@ -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: {
@@ -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();
});
diff --git a/src/__tests__/combiners/complex.test.ts b/src/__tests__/combiners/complex.test.ts
index 0aab790..1798d9c 100644
--- a/src/__tests__/combiners/complex.test.ts
+++ b/src/__tests__/combiners/complex.test.ts
@@ -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: {
@@ -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();
});
diff --git a/src/__tests__/combiners/oneOf.test.ts b/src/__tests__/combiners/oneOf.test.ts
index a07044e..5c7978b 100644
--- a/src/__tests__/combiners/oneOf.test.ts
+++ b/src/__tests__/combiners/oneOf.test.ts
@@ -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: {
@@ -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: {
@@ -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: {
@@ -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();
});
diff --git a/src/__tests__/description.test.ts b/src/__tests__/description.test.ts
index 25b4b6c..1ae8134 100644
--- a/src/__tests__/description.test.ts
+++ b/src/__tests__/description.test.ts
@@ -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',
@@ -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();
});
diff --git a/src/__tests__/example.test.ts b/src/__tests__/example.test.ts
new file mode 100644
index 0000000..034da66
--- /dev/null
+++ b/src/__tests__/example.test.ts
@@ -0,0 +1,91 @@
+import {DocumentBuilder, run} from './__helpers__/run';
+
+const name = 'example';
+describe('openapi project with examples', () => {
+ it('renders example field', async () => {
+ const spec = new DocumentBuilder(name)
+ .request({
+ schema: {
+ example: {
+ name: 'Example',
+ },
+ type: 'object',
+ },
+ })
+ .response(200, {
+ description: 'Base 200 response',
+ schema: {
+ type: 'object',
+ },
+ })
+ .build();
+
+ const fs = await run(spec);
+
+ const page = fs.match(name);
+
+ expect(page).toMatchSnapshot();
+ });
+
+ it('renders example from oneOf', async () => {
+ const spec = new DocumentBuilder(name)
+ .request({
+ schema: {
+ type: 'object',
+ oneOf: [DocumentBuilder.ref('Cat')],
+ },
+ })
+ .response(200, {
+ description: 'Base 200 response',
+ schema: {
+ type: 'object',
+ },
+ })
+ .component('Cat', {
+ type: 'object',
+ properties: {
+ name: {
+ type: 'string',
+ },
+ },
+ })
+ .build();
+
+ const fs = await run(spec);
+
+ const page = fs.match(name);
+
+ expect(page).toMatchSnapshot();
+ });
+
+ it('renders example from allOf', async () => {
+ const spec = new DocumentBuilder(name)
+ .request({
+ schema: {
+ type: 'object',
+ allOf: [DocumentBuilder.ref('Cat')],
+ },
+ })
+ .response(200, {
+ description: 'Base 200 response',
+ schema: {
+ type: 'object',
+ },
+ })
+ .component('Cat', {
+ type: 'object',
+ properties: {
+ name: {
+ type: 'string',
+ },
+ },
+ })
+ .build();
+
+ const fs = await run(spec);
+
+ const page = fs.match(name);
+
+ expect(page).toMatchSnapshot();
+ });
+});
diff --git a/src/__tests__/required.test.ts b/src/__tests__/required.test.ts
index 86baece..faa9ad1 100644
--- a/src/__tests__/required.test.ts
+++ b/src/__tests__/required.test.ts
@@ -1,8 +1,9 @@
import {DocumentBuilder, run} from './__helpers__/run';
-describe('description', () => {
- it('renders correct description', async () => {
- const spec = new DocumentBuilder('description')
+const name = 'required';
+describe('required', () => {
+ it('renders correct required', async () => {
+ const spec = new DocumentBuilder(name)
.parameter({
name: 'a',
in: 'query',
@@ -69,10 +70,12 @@ describe('description', () => {
},
},
description: 'Cat class',
- });
- const fs = await run(spec.build());
+ })
+ .build();
+
+ const fs = await run(spec);
- const page = fs.match('description.md');
+ const page = fs.match(name);
expect(page).toMatchSnapshot();
});
diff --git a/src/includer/traverse/tables.ts b/src/includer/traverse/tables.ts
index cc93d8f..61857bb 100644
--- a/src/includer/traverse/tables.ts
+++ b/src/includer/traverse/tables.ts
@@ -213,7 +213,11 @@ function findNonNullOneOfElement(schema: OpenJSONSchema): OpenJSONSchema {
return v;
}
- return false;
+ if (merged.oneOf?.length) {
+ return false;
+ }
+
+ return v;
};
const result = isValid(schema);