-
-
-POST {.openapi__method}
+
+
+POST {.openapi__method}
\`\`\`
http://localhost:8080/test
\`\`\`
+
+
+
+Generated server url
+
-Generated server url{.openapi__request__description}
+
### Body
@@ -94,6 +99,8 @@ Generated server url{.openapi__request__description}
|||#
+
+
## Responses
@@ -102,6 +109,8 @@ Generated server url{.openapi__request__description}
Cat class
+
+
### Body
{% cut "application/json" %}
@@ -144,6 +153,8 @@ Cat class
|||#
+
+
diff --git a/src/includer/traverse/tables.ts b/src/includer/traverse/tables.ts
index e86c5b2..c4d67d5 100644
--- a/src/includer/traverse/tables.ts
+++ b/src/includer/traverse/tables.ts
@@ -1,17 +1,11 @@
import RefsService from '../services/refs';
import stringify from 'json-stringify-safe';
-import {anchor, table, tableParameterName, title} from '../ui';
+import {anchor, table, tableParameterName} from '../ui';
import {concatNewLine} from '../utils';
import {EOL} from '../constants';
import {OpenJSONSchema, OpenJSONSchemaDefinition} from '../models';
-import {
- collectRefs,
- descriptionForOneOfElement,
- extractOneOfElements,
- inferType,
- typeToText,
-} from './types';
+import {collectRefs, extractOneOfElements, inferType, typeToText} from './types';
type TableRow = [string, string, string];
@@ -20,7 +14,6 @@ export type TableRef = string;
type TableFromSchemaResult = {
content: string;
tableRefs: TableRef[];
- oneOfRefs?: TableRef[];
};
export function tableFromSchema(schema: OpenJSONSchema): TableFromSchemaResult {
@@ -47,20 +40,7 @@ export function tableFromSchema(schema: OpenJSONSchema): TableFromSchemaResult {
}
const {rows, refs} = prepareObjectSchemaTable(schema);
- let content = rows.length ? table([['Name', 'Type', 'Description'], ...rows]) : '';
-
- if (schema.oneOf?.length) {
- const oneOfElements = extractOneOfElements(schema);
- const oneOfElementsRefs = oneOfElements
- .map((value) => value && RefsService.find(value))
- .filter(Boolean) as string[];
-
- content += EOL + title(4)('Or value from:') + EOL;
-
- refs.push(...oneOfElementsRefs);
-
- return {content, tableRefs: refs, oneOfRefs: oneOfElementsRefs};
- }
+ const content = rows.length ? table([['Name', 'Type', 'Description'], ...rows]) : '';
return {content, tableRefs: refs};
}
@@ -107,10 +87,22 @@ function prepareObjectSchemaTable(schema: OpenJSONSchema): PrepareObjectSchemaTa
}
});
- if (schema.oneOf?.length) {
- const restElementsDescription = descriptionForOneOfElement(schema, true);
+ if (merged.oneOf?.length) {
+ const oneOfElements = extractOneOfElements(schema);
+ const oneOfElementsRefs = oneOfElements.map(
+ (value) =>
+ [value, value && RefsService.find(value)] as [OpenJSONSchema, string | undefined],
+ );
+
+ oneOfElementsRefs.forEach(([value, ref]) => {
+ if (!ref) {
+ return;
+ }
+
+ result.rows.push(['oneOf', anchor(ref), value.description || '']);
- result.rows.push(['...rest', 'oneOf', restElementsDescription]);
+ result.refs.push(ref);
+ });
}
return result;
diff --git a/src/includer/ui/common.ts b/src/includer/ui/common.ts
index d35cd2d..42a151d 100644
--- a/src/includer/ui/common.ts
+++ b/src/includer/ui/common.ts
@@ -9,7 +9,7 @@ import {
HTML_COMMENTS_OPEN_DIRECTIVE,
} from '../constants';
-import {TitleDepth} from '../models';
+import {Server, TitleDepth} from '../models';
const openapiBlock = bem('openapi');
@@ -52,8 +52,12 @@ function code(text: string, type = '') {
return EOL + ['```' + appliedType, text, '```'].join(EOL) + EOL;
}
-function method(text: string) {
- return `${text.toUpperCase()} {.openapi__method}`;
+function method(text: string, path: string, server: Server) {
+ let result = `${text.toUpperCase()} {.openapi__method}`;
+
+ result += ` ${code(server.url + '/' + path)}` + EOL;
+
+ return result;
}
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
diff --git a/src/includer/ui/endpoint.ts b/src/includer/ui/endpoint.ts
index 25409d5..15d9b85 100644
--- a/src/includer/ui/endpoint.ts
+++ b/src/includer/ui/endpoint.ts
@@ -29,7 +29,6 @@ import {
Responses,
Schema,
Security,
- Server,
} from '../models';
import {concatNewLine} from '../utils';
@@ -133,29 +132,30 @@ function sandbox({
function request(data: Endpoint) {
const {path, method: type, servers} = data;
- let description: string | undefined;
- const url = block(servers.map(({url}) => code(url + '/' + path)));
+ const requests = servers.map((server, index) => {
+ const args = [`--method: var(--dc-openapi-methods-${type})`];
- const requestTableRow = [method(type), `${url}`];
+ if (index !== servers.length) {
+ args.push('margin-bottom: 12px');
+ }
- if (servers.every((server: Server) => server.description)) {
- description = block(servers.map(({description}) => description));
- }
+ return block([
+ `
`,
+ `
`,
+ method(type, path, server),
+ '
',
+ server.description || '',
+ '
',
+ ]);
+ });
- const requestTable = block([
- '
',
- `
`,
- ...requestTableRow,
+ const result = [
+ title(2)(REQUEST_SECTION_NAME),
+ '
',
+ ...requests,
'
',
- '
',
- ]);
-
- const result = [title(2)(REQUEST_SECTION_NAME), requestTable];
-
- if (description) {
- result.push(`${description}{.openapi__request__description}`);
- }
+ ];
return block(result);
}
@@ -233,7 +233,13 @@ function openapiBody(pagePrintedRefs: Set
, obj?: Schema) {
const {content, tableRefs} = tableFromSchema(schema);
const parsedSchema = prepareSampleObject(schema);
- result = [...result, cut(code(stringify(parsedSchema, null, 4), 'json'), type), content];
+ result = [
+ '',
+ ...result,
+ cut(code(stringify(parsedSchema, null, 4), 'json'), type),
+ content,
+ '
',
+ ];
result.push(...printAllTables(pagePrintedRefs, tableRefs));
@@ -244,6 +250,21 @@ function isPrimitive(type: OpenJSONSchema['type']) {
return PRIMITIVE_JSON6_SCHEMA_TYPES.has(type);
}
+function entity(ref: string, schema: OpenJSONSchema) {
+ const schemaTable = tableFromSchema(schema);
+ const titleLevel = schema._runtime ? 4 : 3;
+
+ const markup = block([
+ '',
+ title(titleLevel)(ref),
+ schema._emptyDescription ? '' : schema.description,
+ schemaTable.content,
+ '
',
+ ]);
+
+ return {markup, refs: schemaTable.tableRefs};
+}
+
function printAllTables(pagePrintedRefs: Set, tableRefs: TableRef[]): string[] {
const result = [];
@@ -264,18 +285,12 @@ function printAllTables(pagePrintedRefs: Set, tableRefs: TableRef[]): st
continue;
}
- const schemaTable = tableFromSchema(schema);
- const titleLevel = schema._runtime ? 4 : 3;
-
- result.push(
- block([
- title(titleLevel)(tableRef),
- schema._emptyDescription ? '' : schema.description,
- schemaTable.content,
- ]),
- );
- tableRefs.push(...schemaTable.tableRefs);
pagePrintedRefs.add(tableRef);
+
+ const {refs, markup} = entity(tableRef, schema);
+
+ result.push(markup);
+ tableRefs.push(...refs);
}
return result;
}
diff --git a/src/runtime/components/FileInputArray.tsx b/src/runtime/components/FileInputArray.tsx
index 9dfd027..ccffbc9 100644
--- a/src/runtime/components/FileInputArray.tsx
+++ b/src/runtime/components/FileInputArray.tsx
@@ -6,7 +6,7 @@ const isFile = (item: undefined | File): item is File => item !== undefined;
type Props = {
onChange(value: File[]): void;
-}
+};
type IndexedFiles = Record;
@@ -19,7 +19,7 @@ export const FileInputArray: React.FC = ({onChange}) => {
(event) => {
setInputs((oldState) => {
const file = event.target.files?.[0];
- const nextState = {...oldState, [idWithChange]: file }
+ const nextState = {...oldState, [idWithChange]: file};
onChange(Object.values(nextState).filter(isFile));
@@ -30,7 +30,7 @@ export const FileInputArray: React.FC = ({onChange}) => {
);
const onAdd = useCallback(() => {
- setInputs((prevState) => ({...prevState, [ref.current++]: undefined }));
+ setInputs((prevState) => ({...prevState, [ref.current++]: undefined}));
}, [setInputs, ref]);
const createOnRemove = useCallback(
@@ -71,4 +71,3 @@ export const FileInputArray: React.FC = ({onChange}) => {
);
};
-
diff --git a/src/runtime/index.scss b/src/runtime/index.scss
index 0b79767..07f492f 100644
--- a/src/runtime/index.scss
+++ b/src/runtime/index.scss
@@ -24,11 +24,22 @@
text-decoration: line-through;
}
+ & > &__request__wrapper:not(:last-child) {
+ margin-bottom: 0;
+ }
+
+ & &__requests {
+ display: flex;
+ flex-direction: column;
+ align-items: flex-start;
+ }
+
& &__request {
display: inline-flex;
align-items: center;
overflow-y: scroll;
max-width: 100%;
+ margin-bottom: 5px;
&__wrapper {
position: relative;
@@ -68,7 +79,7 @@
opacity: 0;
transition: opacity 100ms;
position: absolute;
- right: -8px;
+ right: 10px;
top: 10px;
}