Skip to content

Commit 25393cd

Browse files
committed
OpenAPI: Fix duplicated security scheme name in requirements
1 parent 75d9cba commit 25393cd

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

.changeset/real-lizards-shine.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+
Fix duplicated security scheme name in requirements

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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,14 @@ export async function Operation({
189189

190190
if (type === 'operation' && securities.length > 0) {
191191
const securitySchemes = dereferenced.components?.securitySchemes;
192-
const names = securities.map((security) =>
193-
Object.keys(security).join(' & '),
194-
);
192+
const names = securities.map((security) => {
193+
const intersection = new Set<string>();
194+
for (const [key, value] of Object.entries(security)) {
195+
intersection.add(`${key} ${value}`);
196+
}
197+
198+
return Array.from(intersection).join(' & ');
199+
});
195200

196201
authNode = (
197202
<SelectTabs defaultValue={names[0]}>
@@ -477,13 +482,6 @@ function AuthScheme({
477482
scopes: string[];
478483
ctx: RenderContext;
479484
}) {
480-
const scopeElement =
481-
scopes.length > 0 ? (
482-
<p>
483-
Scope: <code>{scopes.join(', ')}</code>
484-
</p>
485-
) : null;
486-
487485
if (schema.type === 'http' || schema.type === 'oauth2') {
488486
return (
489487
<AuthProperty
@@ -493,33 +491,31 @@ function AuthScheme({
493491
? `Basic <token>`
494492
: 'Bearer <token>'
495493
}
494+
scopes={scopes}
496495
>
497496
{schema.description && ctx.renderMarkdown(schema.description)}
498497
<p>
499498
In: <code>header</code>
500499
</p>
501-
{scopeElement}
502500
</AuthProperty>
503501
);
504502
}
505503

506504
if (schema.type === 'apiKey') {
507505
return (
508-
<AuthProperty name={schema.name} type="<token>">
506+
<AuthProperty name={schema.name} type="<token>" scopes={scopes}>
509507
{schema.description && ctx.renderMarkdown(schema.description)}
510508
<p>
511509
In: <code>{schema.in}</code>
512-
{scopeElement}
513510
</p>
514511
</AuthProperty>
515512
);
516513
}
517514

518515
if (schema.type === 'openIdConnect') {
519516
return (
520-
<AuthProperty name="OpenID Connect" type="<token>">
517+
<AuthProperty name="OpenID Connect" type="<token>" scopes={scopes}>
521518
{schema.description && ctx.renderMarkdown(schema.description)}
522-
{scopeElement}
523519
</AuthProperty>
524520
);
525521
}
@@ -528,10 +524,12 @@ function AuthScheme({
528524
function AuthProperty({
529525
name,
530526
type,
527+
scopes = [],
531528
...props
532529
}: ComponentProps<'div'> & {
533530
name: string;
534531
type: string;
532+
scopes?: string[];
535533
}) {
536534
return (
537535
<div
@@ -545,6 +543,11 @@ function AuthProperty({
545543
</div>
546544
<div className="prose-no-margin pt-2.5 empty:hidden">
547545
{props.children}
546+
{scopes.length > 0 && (
547+
<p>
548+
Scope: <code>{scopes.join(', ')}</code>
549+
</p>
550+
)}
548551
</div>
549552
</div>
550553
);

0 commit comments

Comments
 (0)