-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
SecurityHeader.tsx
45 lines (42 loc) · 1.46 KB
/
SecurityHeader.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { SecurityRequirementModel } from '../../services/models/SecurityRequirement';
import {
ScopeName,
SecurityRequirementAndWrap,
SecurityRequirementOrWrap,
} from './styled.elements';
import * as React from 'react';
import { AUTH_TYPES } from '../SecuritySchemes/SecuritySchemes';
export interface SecurityRequirementProps {
security: SecurityRequirementModel;
showSecuritySchemeType?: boolean;
expanded: boolean;
}
export function SecurityHeader(props: SecurityRequirementProps) {
const { security, showSecuritySchemeType, expanded } = props;
const grouping = security.schemes.length > 1;
if (security.schemes.length === 0)
return <SecurityRequirementOrWrap $expanded={expanded}>None</SecurityRequirementOrWrap>;
return (
<SecurityRequirementOrWrap $expanded={expanded}>
{grouping && '('}
{security.schemes.map(scheme => {
return (
<SecurityRequirementAndWrap key={scheme.id}>
{showSecuritySchemeType && `${AUTH_TYPES[scheme.type] || scheme.type}: `}
<i>{scheme.displayName}</i>
{expanded && scheme.scopes.length
? [
' (',
scheme.scopes.map<React.ReactNode>(scope => (
<ScopeName key={scope}>{scope}</ScopeName>
)),
') ',
]
: null}
</SecurityRequirementAndWrap>
);
})}
{grouping && ') '}
</SecurityRequirementOrWrap>
);
}