Skip to content

Commit 950f6c3

Browse files
authored
greg/rnd 6997 fix long openapi responses label (#3518)
1 parent ea37977 commit 950f6c3

File tree

7 files changed

+51
-41
lines changed

7 files changed

+51
-41
lines changed

biome.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"packages/openapi-parser/src/fixtures/**/*",
2222
"packages/emoji-codepoints/index.ts",
2323
"packages/icons/src/data/*.json",
24-
"packages/gitbook/worker-configuration.d.ts"
24+
"packages/gitbook/worker-configuration.d.ts",
25+
"**/*.css"
2526
]
2627
},
2728
"formatter": {

packages/gitbook/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
"generate": "gitbook-icons ./public/~gitbook/static/icons custom-icons && gitbook-math ./public/~gitbook/static/math && wrangler types",
101101
"copy:icons": "gitbook-icons ./public/~gitbook/static/icons",
102102
"clean": "rm -rf ./.next && rm -rf ./public/~gitbook/static/icons && rm -rf ./public/~gitbook/static/math",
103-
"dev": "env-cmd --silent -f ../../.env.local next --turbopack",
103+
"dev": "env-cmd --silent -f ../../.env.local next",
104104
"build": "next build",
105105
"start": "next start",
106106
"build:cloudflare": "opennextjs-cloudflare build",

packages/gitbook/src/components/DocumentView/OpenAPI/style.css

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -379,21 +379,23 @@
379379
}
380380

381381
.openapi-response-tab-content {
382-
@apply flex items-baseline truncate grow shrink max-w-max basis-[60%] mr-auto;
382+
@apply flex items-baseline truncate grow shrink max-w-max basis-full mr-auto;
383383
@apply text-left text-pretty relative leading-tight text-tint select-text;
384384
}
385385

386386
.openapi-response-description.openapi-markdown {
387-
@apply text-left truncate prose-sm text-sm leading-tight text-tint select-text prose-strong:font-semibold prose-strong:text-inherit;
387+
@apply text-left prose-sm text-sm leading-tight text-tint select-text prose-strong:font-semibold prose-strong:text-inherit;
388388
}
389389

390-
.openapi-disclosure-group-trigger[aria-expanded="true"] .openapi-response-tab-content {
391-
@apply basis-full;
392-
}
393-
394-
.openapi-disclosure-group-trigger[aria-expanded="true"]
390+
.openapi-disclosure-group-trigger[aria-expanded="false"] {
395391
.openapi-response-description.openapi-markdown {
396-
@apply whitespace-normal;
392+
@apply truncate;
393+
@apply [&>*:not(:first-child)]:hidden *:truncate *:!p-0 *:!m-0;
394+
}
395+
396+
.openapi-response-tab-content {
397+
@apply basis-[60%]
398+
}
397399
}
398400

399401
.openapi-response-body {
@@ -551,6 +553,10 @@
551553
@apply text-[0.813rem] truncate text-tint font-normal;
552554
}
553555

556+
.openapi-response-examples-statuscode-label {
557+
@apply truncate;
558+
}
559+
554560
.openapi-response-examples-panel,
555561
.openapi-codesample-panel {
556562
@apply flex-1 text-sm relative focus-visible:outline-none;
@@ -583,10 +589,6 @@ body:has(.openapi-select-popover) {
583589
@apply shrink truncate flex items-center;
584590
}
585591

586-
.openapi-select > button > span.react-aria-SelectValue span:not(.openapi-statuscode) {
587-
@apply truncate;
588-
}
589-
590592
.openapi-select > button .openapi-markdown {
591593
@apply *:leading-none;
592594
}
@@ -615,7 +617,7 @@ body:has(.openapi-select-popover) {
615617

616618
.openapi-select button .openapi-markdown,
617619
.openapi-select-item .openapi-markdown {
618-
@apply text-[0.813rem] *:truncate;
620+
@apply text-[0.813rem] *:truncate *:!p-0 *:!m-0 [&>*:not(:first-child)]:hidden;
619621
}
620622

621623
.openapi-select-item-selected,

packages/gitbook/tailwind.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ function opacity() {
6262
const config: Config = {
6363
darkMode: 'class',
6464
content: [
65-
'./src/pages/**/*.{js,ts,jsx,tsx,mdx}',
66-
'./src/components/**/*.{js,ts,jsx,tsx,mdx}',
67-
'./src/app/**/*.{js,ts,jsx,tsx,mdx}',
65+
'./src/pages/**/*.{js,ts,jsx,tsx,mdx,css}',
66+
'./src/components/**/*.{js,ts,jsx,tsx,mdx,css}',
67+
'./src/app/**/*.{js,ts,jsx,tsx,mdx,css}',
6868
],
6969
theme: {
7070
extend: {

packages/react-openapi/src/OpenAPIResponseExample.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function OpenAPIResponseExample(props: {
4646
.map(([key, responseObject]) => {
4747
const description = resolveDescription(responseObject);
4848
const label = description ? (
49-
<Markdown source={description} />
49+
<Markdown key={`response-description-${key}`} source={description} />
5050
) : (
5151
getStatusCodeDefaultLabel(key, context)
5252
);

packages/react-openapi/src/OpenAPIResponseExampleContent.tsx

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,7 @@ function OpenAPIResponseExampleHeader(props: {
6060

6161
return (
6262
<span className="openapi-response-examples-statuscode-title">
63-
<span
64-
className={clsx(
65-
'openapi-statuscode',
66-
`openapi-statuscode-${getStatusCodeClassName(item.statusCode)}`,
67-
'openapi-response-examples-statuscode'
68-
)}
69-
>
70-
{item.statusCode}
71-
</span>
72-
<span>{item.label}</span>
63+
<OpenAPIResponseExampleItem item={item} />
7364
</span>
7465
);
7566
}
@@ -83,22 +74,33 @@ function OpenAPIResponseExampleHeader(props: {
8374
>
8475
{items.map((item) => (
8576
<OpenAPISelectItem key={item.key} id={item.key} value={item}>
86-
<span
87-
className={clsx(
88-
'openapi-statuscode',
89-
`openapi-statuscode-${getStatusCodeClassName(item.statusCode)}`,
90-
'openapi-response-examples-statuscode'
91-
)}
92-
>
93-
{item.statusCode}
94-
</span>
95-
<span>{item.label}</span>
77+
<OpenAPIResponseExampleItem item={item} />
9678
</OpenAPISelectItem>
9779
))}
9880
</OpenAPISelect>
9981
);
10082
}
10183

84+
function OpenAPIResponseExampleItem(props: {
85+
item: OpenAPIResponseExampleItem;
86+
}) {
87+
const { item } = props;
88+
return (
89+
<>
90+
<span
91+
className={clsx(
92+
'openapi-statuscode',
93+
`openapi-statuscode-${getStatusCodeClassName(item.statusCode)}`,
94+
'openapi-response-examples-statuscode'
95+
)}
96+
>
97+
{item.statusCode}
98+
</span>
99+
<span className="openapi-response-examples-statuscode-label">{item.label}</span>
100+
</>
101+
);
102+
}
103+
102104
function OpenAPIResponseExampleBody(props: {
103105
items: OpenAPIResponseExampleItem[];
104106
blockKey?: string;

packages/react-openapi/src/OpenAPIResponses.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import { useResponseExamplesState } from './OpenAPIResponseExampleContent';
99
import { StaticSection } from './StaticSection';
1010
import type { OpenAPIClientContext } from './context';
1111
import { t } from './translate';
12-
import { createStateKey, getStatusCodeClassName, getStatusCodeDefaultLabel } from './utils';
12+
import {
13+
createStateKey,
14+
getStatusCodeClassName,
15+
getStatusCodeDefaultLabel,
16+
resolveDescription,
17+
} from './utils';
1318

1419
/**
1520
* Display an interactive response body.
@@ -58,7 +63,7 @@ export function OpenAPIResponses(props: {
5863
}));
5964
})();
6065

61-
const description = response.description;
66+
const description = resolveDescription(response);
6267

6368
return {
6469
key: statusCode,

0 commit comments

Comments
 (0)