diff --git a/src/__snapshots__/basic.test.ts.snap b/src/__snapshots__/basic.test.ts.snap index 537dd8c..4a4d117 100644 --- a/src/__snapshots__/basic.test.ts.snap +++ b/src/__snapshots__/basic.test.ts.snap @@ -49,11 +49,31 @@ Base 200 response {% endcut %} -#||| **Name** | **Type** | **Description** || - -|| type | string | || - -|| foo | string | |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + type +| + string +| + + +|| + +|| + foo +| + string +| + + +|||# @@ -79,11 +99,31 @@ Base 200 response {% endcut %} -#||| **Name** | **Type** | **Description** || - -|| type | string | || - -|| bar | string | |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + type +| + string +| + + +|| + +|| + bar +| + string +| + + +|||# diff --git a/src/__snapshots__/combiners/allOf.test.ts.snap b/src/__snapshots__/combiners/allOf.test.ts.snap index e327ae8..39df810 100644 --- a/src/__snapshots__/combiners/allOf.test.ts.snap +++ b/src/__snapshots__/combiners/allOf.test.ts.snap @@ -42,13 +42,40 @@ Generated server url{.openapi__request__description} {% endcut %} -#||| **Name** | **Type** | **Description** || - -|| type | string | || - -|| foo | string | || - -|| name | string | |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + type +| + string +| + + +|| + +|| + foo +| + string +| + + +|| + +|| + name +| + string +| + + +|||# ## Responses @@ -74,13 +101,39 @@ Base 200 response {% endcut %} -#||| **Name** | **Type** | **Description** || - -|| name | string | Default: \`a\` || - -|| type | string | || - -|| baz | string | |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + name +| + string +| + Default: \`a\` +|| + +|| + type +| + string +| + + +|| + +|| + baz +| + string +| + + +|||# @@ -131,19 +184,52 @@ Generated server url{.openapi__request__description} {% endcut %} -#||| **Name** | **Type** | **Description** || +#||| + **Name** +| + **Type** +| + **Description** +|| -|| pet | [Cat](#cat) | Cat class |||# +|| + pet +| + [Cat](#cat) +| + Cat class + +|||# ### Cat Cat class -#||| **Name** | **Type** | **Description** || - -|| type | string | || - -|| foo | string | |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + type +| + string +| + + +|| + +|| + foo +| + string +| + + +|||# ## Responses @@ -171,9 +257,22 @@ Base 200 response {% endcut %} -#||| **Name** | **Type** | **Description** || - -|| pet | [Cat](#cat) | Cat class |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + pet +| + [Cat](#cat) +| + Cat class + +|||# diff --git a/src/__snapshots__/combiners/complex.test.ts.snap b/src/__snapshots__/combiners/complex.test.ts.snap index b9dd472..91058d1 100644 --- a/src/__snapshots__/combiners/complex.test.ts.snap +++ b/src/__snapshots__/combiners/complex.test.ts.snap @@ -43,14 +43,39 @@ Generated server url{.openapi__request__description} {% endcut %} -#||| **Name** | **Type** | **Description** || - -|| name | string | Default: \`b\` || - -|| age | any | || - -|| ...rest | oneOf | [Dog](#dog) -or [Cat](#cat) |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + name +| + string +| + Default: \`b\` +|| + +|| + age +| + any +| + + +|| + +|| + ...rest +| + oneOf +| + [Dog](#dog) +or [Cat](#cat) +|||# #### Or value from: @@ -58,21 +83,61 @@ or [Cat](#cat) |||# Dog class -#||| **Name** | **Type** | **Description** || - -|| type | string | || - -|| bar | string | |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + type +| + string +| + + +|| + +|| + bar +| + string +| + + +|||# ### Cat Cat class -#||| **Name** | **Type** | **Description** || - -|| type | string | || - -|| foo | string | |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + type +| + string +| + + +|| + +|| + foo +| + string +| + + +|||# ## Responses @@ -100,14 +165,39 @@ Base 200 response {% endcut %} -#||| **Name** | **Type** | **Description** || - -|| name | string | Default: \`b\` || - -|| age | any | || - -|| ...rest | oneOf | [Dog](#dog) -or [Cat](#cat) |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + name +| + string +| + Default: \`b\` +|| + +|| + age +| + any +| + + +|| + +|| + ...rest +| + oneOf +| + [Dog](#dog) +or [Cat](#cat) +|||# #### Or value from: diff --git a/src/__snapshots__/combiners/oneOf.test.ts.snap b/src/__snapshots__/combiners/oneOf.test.ts.snap index 0e4ae25..4fafb90 100644 --- a/src/__snapshots__/combiners/oneOf.test.ts.snap +++ b/src/__snapshots__/combiners/oneOf.test.ts.snap @@ -41,10 +41,22 @@ Generated server url{.openapi__request__description} {% endcut %} -#||| **Name** | **Type** | **Description** || - -|| ...rest | oneOf | [Dog](#dog) -or [Cat](#cat) |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + ...rest +| + oneOf +| + [Dog](#dog) +or [Cat](#cat) +|||# #### Or value from: @@ -52,21 +64,61 @@ or [Cat](#cat) |||# Dog class -#||| **Name** | **Type** | **Description** || - -|| type | string | || - -|| baz | string | |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + type +| + string +| + + +|| + +|| + baz +| + string +| + + +|||# ### Cat Cat class -#||| **Name** | **Type** | **Description** || - -|| type | string | || - -|| foo | string | |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + type +| + string +| + + +|| + +|| + foo +| + string +| + + +|||# ## Responses @@ -90,11 +142,23 @@ Cat class {% endcut %} -#||| **Name** | **Type** | **Description** || - -|| ...rest | oneOf | Base 200 response +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + ...rest +| + oneOf +| + Base 200 response [Dog](#dog) -or [Cat](#cat) |||# +or [Cat](#cat) +|||# #### Or value from: @@ -145,14 +209,40 @@ Generated server url{.openapi__request__description} {% endcut %} -#||| **Name** | **Type** | **Description** || - -|| name | string | || - -|| age | number | || - -|| ...rest | oneOf | [Dog](#dog) -or [Cat](#cat) |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + name +| + string +| + + +|| + +|| + age +| + number +| + + +|| + +|| + ...rest +| + oneOf +| + [Dog](#dog) +or [Cat](#cat) +|||# #### Or value from: @@ -160,21 +250,61 @@ or [Cat](#cat) |||# Dog class -#||| **Name** | **Type** | **Description** || - -|| type | string | || - -|| baz | string | |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + type +| + string +| + + +|| + +|| + baz +| + string +| + + +|||# ### Cat Cat class -#||| **Name** | **Type** | **Description** || - -|| type | string | || - -|| foo | string | |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + type +| + string +| + + +|| + +|| + foo +| + string +| + + +|||# ## Responses @@ -198,15 +328,41 @@ Cat class {% endcut %} -#||| **Name** | **Type** | **Description** || - -|| name | string | || - -|| age | number | || - -|| ...rest | oneOf | Base 200 response +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + name +| + string +| + + +|| + +|| + age +| + number +| + + +|| + +|| + ...rest +| + oneOf +| + Base 200 response [Dog](#dog) -or [Cat](#cat) |||# +or [Cat](#cat) +|||# #### Or value from: @@ -259,13 +415,32 @@ Generated server url{.openapi__request__description} {% endcut %} -#||| **Name** | **Type** | **Description** || - -|| pet | [Dog](#dog) -or [Cat](#cat) | || - -|| ...rest | oneOf | [Dog](#dog) -or [Cat](#cat) |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + pet +| + [Dog](#dog) +or [Cat](#cat) +| + + +|| + +|| + ...rest +| + oneOf +| + [Dog](#dog) +or [Cat](#cat) +|||# #### Or value from: @@ -273,21 +448,61 @@ or [Cat](#cat) |||# Dog class -#||| **Name** | **Type** | **Description** || - -|| type | string | || - -|| baz | string | |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + type +| + string +| + + +|| + +|| + baz +| + string +| + + +|||# ### Cat Cat class -#||| **Name** | **Type** | **Description** || - -|| type | string | || - -|| foo | string | |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + type +| + string +| + + +|| + +|| + foo +| + string +| + + +|||# ## Responses @@ -313,14 +528,33 @@ Cat class {% endcut %} -#||| **Name** | **Type** | **Description** || - -|| pet | [Dog](#dog) -or [Cat](#cat) | || - -|| ...rest | oneOf | Base 200 response +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + pet +| + [Dog](#dog) +or [Cat](#cat) +| + + +|| + +|| + ...rest +| + oneOf +| + Base 200 response [Dog](#dog) -or [Cat](#cat) |||# +or [Cat](#cat) +|||# #### Or value from: diff --git a/src/__snapshots__/description.test.ts.snap b/src/__snapshots__/description.test.ts.snap index eee5fb8..66b21fb 100644 --- a/src/__snapshots__/description.test.ts.snap +++ b/src/__snapshots__/description.test.ts.snap @@ -58,35 +58,109 @@ Generated server url{.openapi__request__description} {% endcut %} -#||| **Name** | **Type** | **Description** || - -|| pet | [Cat](#cat) | From response || - -|| petWithoutDescription | [Cat](#cat) | Cat class || - -|| refToSchemaWithDescription | [Dog](#dog) | Dog class || - -|| simpleDescription | object | Simple description |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + pet +| + [Cat](#cat) +| + From response + +|| + +|| + petWithoutDescription +| + [Cat](#cat) +| + Cat class + +|| + +|| + refToSchemaWithDescription +| + [Dog](#dog) +| + Dog class + +|| + +|| + simpleDescription +| + object +| + Simple description + +|||# ### Cat Cat class -#||| **Name** | **Type** | **Description** || - -|| type | string | || - -|| foo | string | |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + type +| + string +| + + +|| + +|| + foo +| + string +| + + +|||# ### Dog Dog class -#||| **Name** | **Type** | **Description** || - -|| type | string | || - -|| bar | string | |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + type +| + string +| + + +|| + +|| + bar +| + string +| + + +|||# diff --git a/src/__snapshots__/examples/array.test.ts.snap b/src/__snapshots__/examples/array.test.ts.snap index 8d4d736..0649d87 100644 --- a/src/__snapshots__/examples/array.test.ts.snap +++ b/src/__snapshots__/examples/array.test.ts.snap @@ -45,9 +45,22 @@ Generated server url{.openapi__request__description} {% endcut %} -#||| **Name** | **Type** | **Description** || - -|| a | object[] | |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + a +| + object[] +| + + +|||# ## Responses @@ -123,9 +136,22 @@ Generated server url{.openapi__request__description} {% endcut %} -#||| **Name** | **Type** | **Description** || +#||| + **Name** +| + **Type** +| + **Description** +|| -|| a | any[] | |||# +|| + a +| + any[] +| + + +|||# ## Responses @@ -197,10 +223,23 @@ Generated server url{.openapi__request__description} {% endcut %} -#||| **Name** | **Type** | **Description** || - -|| a | (string -or integer)[] | |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + a +| + (string +or integer)[] +| + + +|||# ## Responses @@ -349,9 +388,22 @@ Generated server url{.openapi__request__description} ### Cat -#||| **Name** | **Type** | **Description** || - -|| name | string | |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + name +| + string +| + + +|||# ## Responses @@ -428,9 +480,22 @@ Generated server url{.openapi__request__description} ### Cat -#||| **Name** | **Type** | **Description** || - -|| name | string | |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + name +| + string +| + + +|||# ## Responses diff --git a/src/__snapshots__/examples/base.test.ts.snap b/src/__snapshots__/examples/base.test.ts.snap index e967d16..71afcf6 100644 --- a/src/__snapshots__/examples/base.test.ts.snap +++ b/src/__snapshots__/examples/base.test.ts.snap @@ -107,9 +107,22 @@ Generated server url{.openapi__request__description} {% endcut %} -#||| **Name** | **Type** | **Description** || - -|| name | string | |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + name +| + string +| + + +|||# ## Responses @@ -178,17 +191,42 @@ Generated server url{.openapi__request__description} {% endcut %} -#||| **Name** | **Type** | **Description** || - -|| ...rest | oneOf | [Cat](#cat) |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + ...rest +| + oneOf +| + [Cat](#cat) +|||# #### Or value from: ### Cat -#||| **Name** | **Type** | **Description** || - -|| name | string | |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + name +| + string +| + + +|||# ## Responses diff --git a/src/__snapshots__/length.test.ts.snap b/src/__snapshots__/length.test.ts.snap index 63a8720..4e4798d 100644 --- a/src/__snapshots__/length.test.ts.snap +++ b/src/__snapshots__/length.test.ts.snap @@ -57,33 +57,98 @@ Generated server url{.openapi__request__description} {% endcut %} -#||| **Name** | **Type** | **Description** || - -|| pet | [Cat](#cat) | From response || - -|| petWithoutDescription | [Cat](#cat) | Cat class || - -|| refToSchemaWithDescription | [Dog](#dog) | Dog class |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + pet +| + [Cat](#cat) +| + From response + +|| + +|| + petWithoutDescription +| + [Cat](#cat) +| + Cat class + +|| + +|| + refToSchemaWithDescription +| + [Dog](#dog) +| + Dog class + +|||# ### Cat Cat class -#||| **Name** | **Type** | **Description** || - -|| name | string | || - -|| foo | string | Min length: \`3\` |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + name +| + string +| + + +|| + +|| + foo +| + string +| + Min length: \`3\` +|||# ### Dog Dog class -#||| **Name** | **Type** | **Description** || - -|| name | string | Pet name
Max length: \`100\` || - -|| bar | string | Min length: \`1\`
Max length: \`99\` |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + name +| + string +| + Pet name +
Max length: \`100\` +|| + +|| + bar +| + string +| + Min length: \`1\`
Max length: \`99\` +|||# diff --git a/src/__snapshots__/required.test.ts.snap b/src/__snapshots__/required.test.ts.snap index 2ee40bc..a5ffc77 100644 --- a/src/__snapshots__/required.test.ts.snap +++ b/src/__snapshots__/required.test.ts.snap @@ -41,17 +41,58 @@ Generated server url{.openapi__request__description} {% endcut %} -#||| **Name** | **Type** | **Description** || - -|| a* | number | || - -|| b* | number | || - -|| c | number | || - -|| d* | number | || - -|| e | number | |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + a* +| + number +| + + +|| + +|| + b* +| + number +| + + +|| + +|| + c +| + number +| + + +|| + +|| + d* +| + number +| + + +|| + +|| + e +| + number +| + + +|||# ## Responses @@ -77,11 +118,31 @@ Cat class {% endcut %} -#||| **Name** | **Type** | **Description** || - -|| type | string | || - -|| foo | string | |||# +#||| + **Name** +| + **Type** +| + **Description** +|| + +|| + type +| + string +| + + +|| + +|| + foo +| + string +| + + +|||# diff --git a/src/includer/traverse/tables.ts b/src/includer/traverse/tables.ts index dd5172c..19f83f7 100644 --- a/src/includer/traverse/tables.ts +++ b/src/includer/traverse/tables.ts @@ -188,14 +188,17 @@ export function prepareTableRowData( } function prepareComplexDescription(baseDescription: string, value: OpenJSONSchema): string { - let description = baseDescription; + let description = baseDescription + EOL; + const enumValues = value.enum?.map((s) => `\`${s}\``).join(', '); + if (typeof enumValues !== 'undefined') { description = concatNewLine( description, `Enum: ${enumValues}`, ); } + if (typeof value.default !== 'undefined') { description = concatNewLine( description, @@ -216,6 +219,7 @@ function prepareComplexDescription(baseDescription: string, value: OpenJSONSchem `Min length: \`${value.minLength}\``, ); } + if (typeof value.maxLength !== 'undefined') { description = concatNewLine( description, diff --git a/src/includer/ui/common.ts b/src/includer/ui/common.ts index 6351403..f6ccdcf 100644 --- a/src/includer/ui/common.ts +++ b/src/includer/ui/common.ts @@ -61,8 +61,11 @@ function table(data: any[][]) { const [names, ...rest] = data; /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ - const colgen = (col: any) => - Array.isArray(col) ? `${EOL}${table(col)}${EOL}` : escapeTableColContent(` ${col} `); + const colgen = (col: any) => { + const content = Array.isArray(col) ? table(col) : escapeTableColContent(` ${col} `); + + return `${EOL}${content}${EOL}` + } /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ const rowgen = (row: any) => `||${row.map(colgen).join('|')}||`;