From e5eacecc0509ca4719964ee529b746784bb06772 Mon Sep 17 00:00:00 2001 From: 3y3 <3y3@ya.ru> Date: Thu, 11 Jul 2024 04:29:44 +0300 Subject: [PATCH] fix: Fix complex descriptions (with constraints) --- .../combiners/allOf.test.ts.snap | 5 +++- .../combiners/complex.test.ts.snap | 10 +++++-- .../constraints/default.test.ts.snap | 27 +++++++++++++++---- .../constraints/length.test.ts.snap | 17 +++++++++--- src/includer/traverse/description.ts | 16 +++++------ src/runtime/index.scss | 7 ++--- 6 files changed, 58 insertions(+), 24 deletions(-) diff --git a/src/__snapshots__/combiners/allOf.test.ts.snap b/src/__snapshots__/combiners/allOf.test.ts.snap index 9693f19..b471119 100644 --- a/src/__snapshots__/combiners/allOf.test.ts.snap +++ b/src/__snapshots__/combiners/allOf.test.ts.snap @@ -116,7 +116,10 @@ Base 200 response | **Type:** string -Default: \`a\` + + +*Default:*{.openapi-description-annotation} \`a\` + || || diff --git a/src/__snapshots__/combiners/complex.test.ts.snap b/src/__snapshots__/combiners/complex.test.ts.snap index 599c727..696bcbc 100644 --- a/src/__snapshots__/combiners/complex.test.ts.snap +++ b/src/__snapshots__/combiners/complex.test.ts.snap @@ -67,7 +67,10 @@ Generated server url | **Type:** string -Default: \`b\` + + +*Default:*{.openapi-description-annotation} \`b\` + || || @@ -187,7 +190,10 @@ Base 200 response | **Type:** string -Default: \`b\` + + +*Default:*{.openapi-description-annotation} \`b\` + || || diff --git a/src/__snapshots__/constraints/default.test.ts.snap b/src/__snapshots__/constraints/default.test.ts.snap index d2907af..7a9378c 100644 --- a/src/__snapshots__/constraints/default.test.ts.snap +++ b/src/__snapshots__/constraints/default.test.ts.snap @@ -41,7 +41,10 @@ Generated server url | **Type:** number<int32> -Amount of search results to show
Default: \`10\` +Amount of search results to show
+ +*Default:*{.openapi-description-annotation} \`10\` + |||# ## Responses @@ -134,7 +137,10 @@ Generated server url | **Type:** number -Default: \`7\` + + +*Default:*{.openapi-description-annotation} \`7\` + || || @@ -142,7 +148,10 @@ Generated server url | **Type:** string -Default: \`Anonymous\` + + +*Default:*{.openapi-description-annotation} \`Anonymous\` + || || @@ -150,7 +159,12 @@ Generated server url | **Type:** string -Role for the user being created
Default: \`basic\`
Enum: \`basic\`, \`admin\` +Role for the user being created + +*Default:*{.openapi-description-annotation} \`basic\` + +*Enum:*{.openapi-description-annotation} \`basic\`, \`admin\` + || || @@ -158,7 +172,10 @@ Role for the user being created
| **Type:** string[] -Default: \`blah\` + + +*Default:*{.openapi-description-annotation} \`blah\` + |||# diff --git a/src/__snapshots__/constraints/length.test.ts.snap b/src/__snapshots__/constraints/length.test.ts.snap index 0e80f86..b5806c5 100644 --- a/src/__snapshots__/constraints/length.test.ts.snap +++ b/src/__snapshots__/constraints/length.test.ts.snap @@ -111,7 +111,10 @@ Cat class | **Type:** string -Min length: \`3\` + + +*Min length:*{.openapi-description-annotation} \`3\` + || || @@ -139,7 +142,12 @@ Dog class | **Type:** string -Min length: \`1\`
Max length: \`99\` + + +*Min length:*{.openapi-description-annotation} \`1\` + +*Max length:*{.openapi-description-annotation} \`99\` + || || @@ -147,7 +155,10 @@ Dog class | **Type:** string -Pet name
Max length: \`100\` +Pet name + +*Max length:*{.openapi-description-annotation} \`100\` + |||# diff --git a/src/includer/traverse/description.ts b/src/includer/traverse/description.ts index c110d97..9d2d847 100644 --- a/src/includer/traverse/description.ts +++ b/src/includer/traverse/description.ts @@ -1,5 +1,4 @@ import {OpenJSONSchema} from '../models'; -import {concatNewLine} from '../utils'; type Field = { key: keyof OpenJSONSchema; @@ -92,17 +91,14 @@ function concatConstraint( constraintLabel: string, notWrapValueIntoCode = false, ) { - if (typeof constraint !== 'undefined') { - return concatNewLine( - description, - `${constraintLabel} ${prepareConstraintValue( - constraint, - notWrapValueIntoCode, - )}`, - ); + if (typeof constraint === 'undefined') { + return description; } - return description; + constraint = prepareConstraintValue(constraint, notWrapValueIntoCode); + description = description.replace(/\n$/, ''); + + return `${description}\n\n*${constraintLabel}*{.openapi-description-annotation} ${constraint}\n`; } function prepareConstraintValue(value: unknown, notWrapValueIntoCode: boolean) { diff --git a/src/runtime/index.scss b/src/runtime/index.scss index 9c50786..6e8e9d5 100644 --- a/src/runtime/index.scss +++ b/src/runtime/index.scss @@ -13,9 +13,10 @@ --dc-openapi-highlight: rgb(233, 174, 86); .openapi-description-annotation { - color: gray; + font-style: normal; + color: var(--g-color-text-hint); } - + &__required { color: var(--g-color-text-danger); } @@ -48,7 +49,7 @@ &__wrapper { position: relative; max-width: 100%; - display: inline-block; + display: inline-block; } & * {