Skip to content

Commit

Permalink
fix: Fix complex descriptions (with constraints)
Browse files Browse the repository at this point in the history
  • Loading branch information
3y3 committed Jul 11, 2024
1 parent f2490f0 commit 545f9c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
16 changes: 6 additions & 10 deletions src/includer/traverse/description.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {OpenJSONSchema} from '../models';
import {concatNewLine} from '../utils';

type Field = {
key: keyof OpenJSONSchema;
Expand Down Expand Up @@ -92,17 +91,14 @@ function concatConstraint(
constraintLabel: string,
notWrapValueIntoCode = false,
) {
if (typeof constraint !== 'undefined') {
return concatNewLine(
description,
`<span class="openapi-description-annotation">${constraintLabel}</span> ${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) {
Expand Down
7 changes: 4 additions & 3 deletions src/runtime/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -48,7 +49,7 @@
&__wrapper {
position: relative;
max-width: 100%;
display: inline-block;
display: inline-block;
}

& * {
Expand Down

0 comments on commit 545f9c4

Please sign in to comment.