Skip to content

Commit 5ac448a

Browse files
committed
OpenAPI: fix response rendering
1 parent 2e01720 commit 5ac448a

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

.changeset/plain-wasps-notice.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'fumadocs-openapi': patch
3+
---
4+
5+
Improve response rendering

apps/docs/lib/get-sponsors.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ export const revalidate = 60 * 30;
2121

2222
export async function getSponsors(owner: string): Promise<Sponsor[]> {
2323
if (!process.env.GITHUB_TOKEN) {
24-
throw new Error('GITHUB_TOKEN environment variable is required');
24+
console.warn(
25+
'GITHUB_TOKEN environment variable is required for fetching sponsors.',
26+
);
27+
return [];
2528
}
2629

2730
const octokit = new Octokit({

packages/openapi/src/ui/operation/index.tsx

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,12 @@ export async function Operation({
128128

129129
<Accordions type="multiple">
130130
{statuses.map((status) => (
131-
<AccordionItem key={status} value={status}>
132-
<ResponseAccordion status={status} operation={method} ctx={ctx} />
133-
</AccordionItem>
131+
<ResponseAccordion
132+
key={status}
133+
status={status}
134+
operation={method}
135+
ctx={ctx}
136+
/>
134137
))}
135138
</Accordions>
136139
</>
@@ -329,29 +332,28 @@ async function ResponseAccordion({
329332
const response = operation.responses![status];
330333
const { generateTypeScriptSchema } = ctx;
331334
const contentTypes = response.content ? Object.entries(response.content) : [];
335+
let wrapper = (children: ReactNode) => children;
336+
let selectorNode: ReactNode = null;
332337

333-
if (contentTypes.length === 0) {
334-
return (
335-
response.description && (
336-
<div className="prose-no-margin">
337-
{ctx.renderMarkdown(response.description)}
338-
</div>
339-
)
338+
if (contentTypes.length > 0) {
339+
const [defaultValue] = contentTypes[0];
340+
selectorNode =
341+
contentTypes.length === 1 ? (
342+
<p className="text-sm text-fd-muted-foreground">{defaultValue}</p>
343+
) : (
344+
<SelectTabTrigger items={contentTypes.map(([key]) => key)} />
345+
);
346+
wrapper = (children) => (
347+
<SelectTabs defaultValue={defaultValue}>{children}</SelectTabs>
340348
);
341349
}
342350

343-
const [defaultValue] = contentTypes[0];
344-
return (
345-
<SelectTabs defaultValue={defaultValue}>
351+
return wrapper(
352+
<AccordionItem value={status}>
346353
<AccordionHeader>
347354
<AccordionTrigger className="font-mono">{status}</AccordionTrigger>
348-
{contentTypes.length > 1 ? (
349-
<SelectTabTrigger items={contentTypes.map(([key]) => key)} />
350-
) : (
351-
<p className="text-sm text-fd-muted-foreground">{defaultValue}</p>
352-
)}
355+
{selectorNode}
353356
</AccordionHeader>
354-
355357
<AccordionContent className="ps-4.5">
356358
{response.description && (
357359
<div className="prose-no-margin">
@@ -386,7 +388,7 @@ async function ResponseAccordion({
386388
);
387389
})}
388390
</AccordionContent>
389-
</SelectTabs>
391+
</AccordionItem>,
390392
);
391393
}
392394

0 commit comments

Comments
 (0)