From 587d1641a0b512a697f0e8e5d97fc284046d8188 Mon Sep 17 00:00:00 2001 From: v8tenko Date: Thu, 29 Feb 2024 13:48:41 +0300 Subject: [PATCH] feat: support multiple servers, change oneOf render --- .github/workflows/preview.yml | 23 --- src/__snapshots__/basic.test.ts.snap | 21 ++- .../combiners/allOf.test.ts.snap | 46 +++-- .../combiners/complex.test.ts.snap | 55 ++++-- .../combiners/oneOf.test.ts.snap | 168 +++++++++++++----- src/__snapshots__/description.test.ts.snap | 25 ++- src/__snapshots__/examples/array.test.ts.snap | 134 ++++++++++---- src/__snapshots__/examples/base.test.ts.snap | 71 ++++++-- src/__snapshots__/length.test.ts.snap | 25 ++- src/__snapshots__/required.test.ts.snap | 21 ++- src/includer/traverse/tables.ts | 44 ++--- src/includer/ui/common.ts | 10 +- src/includer/ui/endpoint.ts | 77 ++++---- src/runtime/components/FileInputArray.tsx | 7 +- src/runtime/index.scss | 13 +- 15 files changed, 519 insertions(+), 221 deletions(-) delete mode 100644 .github/workflows/preview.yml diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml deleted file mode 100644 index 21e367e..0000000 --- a/.github/workflows/preview.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: OpenAPI preview - -on: - pull_request: - -jobs: - preview: - permissions: - contents: write - pull-requests: write - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - repository: "v8tenko/diplodoc-playground" - - name: Use Node.js 14 - uses: actions/setup-node@v3 - with: - node-version: 18 - - name: Diplodoc build action - uses: v8tenko/diplodoc-playground@v2.3 - with: - token: ${{secrets.GITHUB_TOKEN}} diff --git a/src/__snapshots__/basic.test.ts.snap b/src/__snapshots__/basic.test.ts.snap index 4a4d117..693fb62 100644 --- a/src/__snapshots__/basic.test.ts.snap +++ b/src/__snapshots__/basic.test.ts.snap @@ -7,23 +7,26 @@ exports[`basic openapi project renders description 1`] = ` ## Request -
+
-
- -POST {.openapi__method} +
+
+POST {.openapi__method} \`\`\` http://localhost:8080/test \`\`\` +
+Generated server url +
-Generated server url{.openapi__request__description} +
## Responses @@ -33,6 +36,8 @@ Generated server url{.openapi__request__description} Base 200 response +
+ ### Body {% cut "application/json" %} @@ -77,12 +82,16 @@ Base 200 response
+
+
## 404 Not Found Base 200 response +
+ ### Body {% cut "application/json" %} @@ -125,6 +134,8 @@ Base 200 response |||# +
+
diff --git a/src/__snapshots__/combiners/allOf.test.ts.snap b/src/__snapshots__/combiners/allOf.test.ts.snap index 39df810..155c952 100644 --- a/src/__snapshots__/combiners/allOf.test.ts.snap +++ b/src/__snapshots__/combiners/allOf.test.ts.snap @@ -7,23 +7,28 @@ exports[`allOf operator support renders simple allOf 1`] = ` ## Request -
+
-
- -POST {.openapi__method} +
+
+POST {.openapi__method} \`\`\` http://localhost:8080/test \`\`\` + +
+ +Generated server url +
-Generated server url{.openapi__request__description} +
### Body @@ -77,6 +82,8 @@ Generated server url{.openapi__request__description} |||# +
+ ## Responses
@@ -85,6 +92,8 @@ Generated server url{.openapi__request__description} Base 200 response +
+ ### Body {% cut "application/json" %} @@ -135,6 +144,8 @@ Base 200 response |||# +
+
@@ -148,23 +159,28 @@ exports[`allOf operator support renders single allOf 1`] = ` ## Request -
- -
+
-POST {.openapi__method} +
+
+POST {.openapi__method} \`\`\` http://localhost:8080/test \`\`\` + +
+ +Generated server url +
-Generated server url{.openapi__request__description} +
### Body @@ -201,6 +217,10 @@ Generated server url{.openapi__request__description} |||# +
+ +
+ ### Cat Cat class @@ -231,6 +251,8 @@ Cat class |||# +
+ ## Responses
@@ -239,6 +261,8 @@ Cat class Base 200 response +
+ ### Body {% cut "application/json" %} @@ -274,6 +298,8 @@ Base 200 response |||# +
+
diff --git a/src/__snapshots__/combiners/complex.test.ts.snap b/src/__snapshots__/combiners/complex.test.ts.snap index 05eb432..0709941 100644 --- a/src/__snapshots__/combiners/complex.test.ts.snap +++ b/src/__snapshots__/combiners/complex.test.ts.snap @@ -7,23 +7,28 @@ exports[`operators complex test renders ok 1`] = ` ## Request -
+
-
- -POST {.openapi__method} +
+
+POST {.openapi__method} \`\`\` http://localhost:8080/test \`\`\` + +
+ +Generated server url +
-Generated server url{.openapi__request__description} +
### Body @@ -71,15 +76,24 @@ Generated server url{.openapi__request__description} || || - ...rest -| oneOf | [Dog](#dog) -or [Cat](#cat) +| + Dog class +|| + +|| + oneOf +| + [Cat](#cat) +| + Cat class |||# -#### Or value from: +
+ +
### Dog @@ -111,6 +125,10 @@ Dog class |||# +
+ +
+ ### Cat Cat class @@ -141,6 +159,8 @@ Cat class |||# +
+ ## Responses
@@ -149,6 +169,8 @@ Cat class Base 200 response +
+ ### Body {% cut "application/json" %} @@ -195,15 +217,22 @@ Base 200 response || || - ...rest -| oneOf | [Dog](#dog) -or [Cat](#cat) +| + Dog class +|| + +|| + oneOf +| + [Cat](#cat) +| + Cat class |||# -#### Or value from: +
diff --git a/src/__snapshots__/combiners/oneOf.test.ts.snap b/src/__snapshots__/combiners/oneOf.test.ts.snap index 5a3799b..9fdefa5 100644 --- a/src/__snapshots__/combiners/oneOf.test.ts.snap +++ b/src/__snapshots__/combiners/oneOf.test.ts.snap @@ -7,23 +7,28 @@ exports[`oneOf operator support renders empty 1`] = ` ## Request -
+
-
- -POST {.openapi__method} +
+
+POST {.openapi__method} \`\`\` http://localhost:8080/test \`\`\` + +
+ +Generated server url +
-Generated server url{.openapi__request__description} +
### Body @@ -50,15 +55,24 @@ Generated server url{.openapi__request__description} || || - ...rest -| oneOf | [Dog](#dog) -or [Cat](#cat) +| + Dog class +|| + +|| + oneOf +| + [Cat](#cat) +| + Cat class |||# -#### Or value from: +
+ +
### Dog @@ -90,6 +104,10 @@ Dog class |||# +
+ +
+ ### Cat Cat class @@ -120,12 +138,16 @@ Cat class |||# +
+ ## Responses
## 200 OK +
+ ### Body {% cut "application/json" %} @@ -151,16 +173,22 @@ Cat class || || - ...rest + oneOf | + [Dog](#dog) +| + Dog class +|| + +|| oneOf | - Base 200 response -[Dog](#dog) -or [Cat](#cat) + [Cat](#cat) +| + Cat class |||# -#### Or value from: +
@@ -175,23 +203,28 @@ exports[`oneOf operator support renders filled 1`] = ` ## Request -
- -
+
-POST {.openapi__method} +
+
+POST {.openapi__method} \`\`\` http://localhost:8080/test \`\`\` + +
+ +Generated server url +
-Generated server url{.openapi__request__description} +
### Body @@ -238,15 +271,24 @@ Generated server url{.openapi__request__description} || || - ...rest -| oneOf | [Dog](#dog) -or [Cat](#cat) +| + Dog class +|| + +|| + oneOf +| + [Cat](#cat) +| + Cat class |||# -#### Or value from: +
+ +
### Dog @@ -278,6 +320,10 @@ Dog class |||# +
+ +
+ ### Cat Cat class @@ -308,12 +354,16 @@ Cat class |||# +
+ ## Responses
## 200 OK +
+ ### Body {% cut "application/json" %} @@ -359,16 +409,22 @@ Cat class || || - ...rest + oneOf +| + [Dog](#dog) | + Dog class +|| + +|| oneOf | - Base 200 response -[Dog](#dog) -or [Cat](#cat) + [Cat](#cat) +| + Cat class |||# -#### Or value from: +
@@ -383,23 +439,28 @@ exports[`oneOf operator support renders parameter 1`] = ` ## Request -
+
-
- -POST {.openapi__method} +
+
+POST {.openapi__method} \`\`\` http://localhost:8080/test \`\`\` +
+Generated server url +
-Generated server url{.openapi__request__description} +
+ +
### Body @@ -440,15 +501,24 @@ or [Cat](#cat) || || - ...rest -| oneOf | [Dog](#dog) -or [Cat](#cat) +| + Dog class +|| + +|| + oneOf +| + [Cat](#cat) +| + Cat class |||# -#### Or value from: +
+ +
### Dog @@ -480,6 +550,10 @@ Dog class |||# +
+ +
+ ### Cat Cat class @@ -510,12 +584,16 @@ Cat class |||# +
+ ## Responses
## 200 OK +
+ ### Body {% cut "application/json" %} @@ -555,16 +633,22 @@ or [Cat](#cat) || || - ...rest + oneOf | + [Dog](#dog) +| + Dog class +|| + +|| oneOf | - Base 200 response -[Dog](#dog) -or [Cat](#cat) + [Cat](#cat) +| + Cat class |||# -#### Or value from: +
diff --git a/src/__snapshots__/description.test.ts.snap b/src/__snapshots__/description.test.ts.snap index 66b21fb..96b5ed6 100644 --- a/src/__snapshots__/description.test.ts.snap +++ b/src/__snapshots__/description.test.ts.snap @@ -7,23 +7,26 @@ exports[`description renders correct description 1`] = ` ## Request -
+
-
- -POST {.openapi__method} +
+
+POST {.openapi__method} \`\`\` http://localhost:8080/test \`\`\` +
+Generated server url +
-Generated server url{.openapi__request__description} +
## Responses @@ -31,6 +34,8 @@ Generated server url{.openapi__request__description} ## 200 OK +
+ ### Body {% cut "application/json" %} @@ -102,6 +107,10 @@ Generated server url{.openapi__request__description} |||# +
+ +
+ ### Cat Cat class @@ -132,6 +141,10 @@ Cat class |||# +
+ +
+ ### Dog Dog class @@ -162,6 +175,8 @@ Dog class |||# +
+
diff --git a/src/__snapshots__/examples/array.test.ts.snap b/src/__snapshots__/examples/array.test.ts.snap index 0649d87..00263f6 100644 --- a/src/__snapshots__/examples/array.test.ts.snap +++ b/src/__snapshots__/examples/array.test.ts.snap @@ -7,23 +7,28 @@ exports[`openapi project with examples renders array + allOf example 1`] = ` ## Request -
+
-
- -POST {.openapi__method} +
+
+POST {.openapi__method} \`\`\` http://localhost:8080/test \`\`\` + +
+ +Generated server url +
-Generated server url{.openapi__request__description} +
### Body @@ -62,6 +67,8 @@ Generated server url{.openapi__request__description} |||# +
+ ## Responses
@@ -70,6 +77,8 @@ Generated server url{.openapi__request__description} Base 200 response +
+ ### Body {% cut "application/json" %} @@ -83,6 +92,8 @@ Base 200 response {% endcut %} +
+
@@ -96,23 +107,28 @@ exports[`openapi project with examples renders array + oneOf + allOf example 1`] ## Request -
- -
+
-POST {.openapi__method} +
+
+POST {.openapi__method} \`\`\` http://localhost:8080/test \`\`\` + +
+ +Generated server url +
-Generated server url{.openapi__request__description} +
### Body @@ -153,6 +169,8 @@ Generated server url{.openapi__request__description} |||# +
+ ## Responses
@@ -161,6 +179,8 @@ Generated server url{.openapi__request__description} Base 200 response +
+ ### Body {% cut "application/json" %} @@ -174,6 +194,8 @@ Base 200 response {% endcut %} +
+
@@ -187,23 +209,28 @@ exports[`openapi project with examples renders array + oneOf example 1`] = ` ## Request -
- -
+
-POST {.openapi__method} +
+
+POST {.openapi__method} \`\`\` http://localhost:8080/test \`\`\` + +
+ +Generated server url +
-Generated server url{.openapi__request__description} +
### Body @@ -241,6 +268,8 @@ or integer)[] |||# +
+ ## Responses
@@ -249,6 +278,8 @@ or integer)[] Base 200 response +
+ ### Body {% cut "application/json" %} @@ -262,6 +293,8 @@ Base 200 response {% endcut %} +
+
@@ -275,23 +308,28 @@ exports[`openapi project with examples renders example field 1`] = ` ## Request -
- -
+
-POST {.openapi__method} +
+
+POST {.openapi__method} \`\`\` http://localhost:8080/test \`\`\` + +
+ +Generated server url +
-Generated server url{.openapi__request__description} +
### Body @@ -315,6 +353,8 @@ Generated server url{.openapi__request__description} any[] +
+ ## Responses
@@ -323,6 +363,8 @@ any[] Base 200 response +
+ ### Body {% cut "application/json" %} @@ -336,6 +378,8 @@ Base 200 response {% endcut %} +
+
@@ -349,23 +393,28 @@ exports[`openapi project with examples renders infered example 1`] = ` ## Request -
+
-
- -POST {.openapi__method} +
+
+POST {.openapi__method} \`\`\` http://localhost:8080/test \`\`\` + +
+ +Generated server url +
-Generated server url{.openapi__request__description} +
### Body @@ -386,6 +435,10 @@ Generated server url{.openapi__request__description} [Cat](#cat)[] +
+ +
+ ### Cat #||| @@ -405,6 +458,8 @@ Generated server url{.openapi__request__description} |||# +
+ ## Responses
@@ -413,6 +468,8 @@ Generated server url{.openapi__request__description} Base 200 response +
+ ### Body {% cut "application/json" %} @@ -426,6 +483,8 @@ Base 200 response {% endcut %} +
+
@@ -439,23 +498,28 @@ exports[`openapi project with examples renders nested arrays exmaple 1`] = ` ## Request -
- -
+
-POST {.openapi__method} +
+
+POST {.openapi__method} \`\`\` http://localhost:8080/test \`\`\` + +
+ +Generated server url +
-Generated server url{.openapi__request__description} +
### Body @@ -478,6 +542,10 @@ Generated server url{.openapi__request__description} [Cat](#cat)[][] +
+ +
+ ### Cat #||| @@ -497,6 +565,8 @@ Generated server url{.openapi__request__description} |||# +
+ ## Responses
@@ -505,6 +575,8 @@ Generated server url{.openapi__request__description} Base 200 response +
+ ### Body {% cut "application/json" %} @@ -518,6 +590,8 @@ Base 200 response {% endcut %} +
+
diff --git a/src/__snapshots__/examples/base.test.ts.snap b/src/__snapshots__/examples/base.test.ts.snap index 71afcf6..e407e5e 100644 --- a/src/__snapshots__/examples/base.test.ts.snap +++ b/src/__snapshots__/examples/base.test.ts.snap @@ -7,23 +7,28 @@ exports[`openapi project with examples renders example field 1`] = ` ## Request -
+
-
- -POST {.openapi__method} +
+
+POST {.openapi__method} \`\`\` http://localhost:8080/test \`\`\` + +
+ +Generated server url +
-Generated server url{.openapi__request__description} +
### Body @@ -40,6 +45,8 @@ Generated server url{.openapi__request__description} {% endcut %} +
+ ## Responses
@@ -48,6 +55,8 @@ Generated server url{.openapi__request__description} Base 200 response +
+ ### Body {% cut "application/json" %} @@ -61,6 +70,8 @@ Base 200 response {% endcut %} +
+
@@ -74,23 +85,28 @@ exports[`openapi project with examples renders example from allOf 1`] = ` ## Request -
- -
+
-POST {.openapi__method} +
+
+POST {.openapi__method} \`\`\` http://localhost:8080/test \`\`\` + +
+ +Generated server url +
-Generated server url{.openapi__request__description} +
### Body @@ -124,6 +140,8 @@ Generated server url{.openapi__request__description} |||# +
+ ## Responses
@@ -132,6 +150,8 @@ Generated server url{.openapi__request__description} Base 200 response +
+ ### Body {% cut "application/json" %} @@ -145,6 +165,8 @@ Base 200 response {% endcut %} +
+
@@ -158,23 +180,28 @@ exports[`openapi project with examples renders example from oneOf 1`] = ` ## Request -
+
-
- -POST {.openapi__method} +
+
+POST {.openapi__method} \`\`\` http://localhost:8080/test \`\`\` + +
+ +Generated server url +
-Generated server url{.openapi__request__description} +
### Body @@ -200,14 +227,16 @@ Generated server url{.openapi__request__description} || || - ...rest -| oneOf | [Cat](#cat) +| + |||# -#### Or value from: +
+ +
### Cat @@ -228,6 +257,8 @@ Generated server url{.openapi__request__description} |||# +
+ ## Responses
@@ -236,6 +267,8 @@ Generated server url{.openapi__request__description} Base 200 response +
+ ### Body {% cut "application/json" %} @@ -249,6 +282,8 @@ Base 200 response {% endcut %} +
+
diff --git a/src/__snapshots__/length.test.ts.snap b/src/__snapshots__/length.test.ts.snap index 4e4798d..c1bc0e4 100644 --- a/src/__snapshots__/length.test.ts.snap +++ b/src/__snapshots__/length.test.ts.snap @@ -7,23 +7,26 @@ exports[`length renders correct length limits 1`] = ` ## Request -
+
-
- -POST {.openapi__method} +
+
+POST {.openapi__method} \`\`\` http://localhost:8080/test \`\`\` +
+Generated server url +
-Generated server url{.openapi__request__description} +
## Responses @@ -31,6 +34,8 @@ Generated server url{.openapi__request__description} ## 200 OK +
+ ### Body {% cut "application/json" %} @@ -92,6 +97,10 @@ Generated server url{.openapi__request__description} |||# +
+ +
+ ### Cat Cat class @@ -121,6 +130,10 @@ Cat class Min length: \`3\` |||# +
+ +
+ ### Dog Dog class @@ -150,6 +163,8 @@ Dog class Min length: \`1\`
Max length: \`99\` |||# +
+
diff --git a/src/__snapshots__/required.test.ts.snap b/src/__snapshots__/required.test.ts.snap index a5ffc77..a064426 100644 --- a/src/__snapshots__/required.test.ts.snap +++ b/src/__snapshots__/required.test.ts.snap @@ -7,23 +7,28 @@ exports[`required renders correct required 1`] = ` ## Request -
+
-
- -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; }