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 e5eacec
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 24 deletions.
5 changes: 4 additions & 1 deletion src/__snapshots__/combiners/allOf.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ Base 200 response
|
**Type:** string
<span class="openapi-description-annotation">Default:</span> \`a\`
*Default:*{.openapi-description-annotation} \`a\`
||
||
Expand Down
10 changes: 8 additions & 2 deletions src/__snapshots__/combiners/complex.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ Generated server url
|
**Type:** string
<span class="openapi-description-annotation">Default:</span> \`b\`
*Default:*{.openapi-description-annotation} \`b\`
||
||
Expand Down Expand Up @@ -187,7 +190,10 @@ Base 200 response
|
**Type:** string
<span class="openapi-description-annotation">Default:</span> \`b\`
*Default:*{.openapi-description-annotation} \`b\`
||
||
Expand Down
27 changes: 22 additions & 5 deletions src/__snapshots__/constraints/default.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ Generated server url
|
**Type:** number&lt;int32&gt;
Amount of search results to show<br><span class="openapi-description-annotation">Default:</span> \`10\`
Amount of search results to show<br>
*Default:*{.openapi-description-annotation} \`10\`
|||#
## Responses
Expand Down Expand Up @@ -134,31 +137,45 @@ Generated server url
|
**Type:** number
<span class="openapi-description-annotation">Default:</span> \`7\`
*Default:*{.openapi-description-annotation} \`7\`
||
||
name
|
**Type:** string
<span class="openapi-description-annotation">Default:</span> \`Anonymous\`
*Default:*{.openapi-description-annotation} \`Anonymous\`
||
||
role
|
**Type:** string
Role for the user being created<br><span class="openapi-description-annotation">Default:</span> \`basic\`<br><span class="openapi-description-annotation">Enum:</span> \`basic\`, \`admin\`
Role for the user being created
*Default:*{.openapi-description-annotation} \`basic\`
*Enum:*{.openapi-description-annotation} \`basic\`, \`admin\`
||
||
tags
|
**Type:** string[]
<span class="openapi-description-annotation">Default:</span> \`blah\`
*Default:*{.openapi-description-annotation} \`blah\`
|||#
</div>
Expand Down
17 changes: 14 additions & 3 deletions src/__snapshots__/constraints/length.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ Cat class
|
**Type:** string
<span class="openapi-description-annotation">Min length:</span> \`3\`
*Min length:*{.openapi-description-annotation} \`3\`
||
||
Expand Down Expand Up @@ -139,15 +142,23 @@ Dog class
|
**Type:** string
<span class="openapi-description-annotation">Min length:</span> \`1\`<br><span class="openapi-description-annotation">Max length:</span> \`99\`
*Min length:*{.openapi-description-annotation} \`1\`
*Max length:*{.openapi-description-annotation} \`99\`
||
||
name
|
**Type:** string
Pet name<br><span class="openapi-description-annotation">Max length:</span> \`100\`
Pet name
*Max length:*{.openapi-description-annotation} \`100\`
|||#
</div>
Expand Down
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 e5eacec

Please sign in to comment.