Skip to content

Commit f96c481

Browse files
committed
fix: wrong display when combining multiple auth requirements
fies #577
1 parent 0045958 commit f96c481

File tree

1 file changed

+38
-13
lines changed

1 file changed

+38
-13
lines changed

src/components/SecurityRequirement/SecurityRequirement.tsx

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,61 @@ const ScopeName = styled.code`
2424
}
2525
`;
2626

27-
const SecurityRequirementWrap = styled.span`
27+
const SecurityRequirementAndWrap = styled.span`
2828
&:after {
29-
content: ' OR ';
29+
content: ' AND ';
3030
font-weight: bold;
3131
}
32+
3233
&:last-child:after {
3334
content: none;
3435
}
3536
3637
${linksCss};
3738
`;
3839

40+
const SecurityRequirementOrWrap = styled.span`
41+
&:before {
42+
content: '( ';
43+
font-weight: bold;
44+
}
45+
&:after {
46+
content: ' ) OR ';
47+
font-weight: bold;
48+
}
49+
&:last-child:after {
50+
content: ' )';
51+
}
52+
53+
&:only-child:before,
54+
&:only-child:after {
55+
content: none;
56+
}
57+
58+
${linksCss};
59+
`;
60+
3961
export interface SecurityRequirementProps {
4062
security: SecurityRequirementModel;
4163
}
4264

4365
export class SecurityRequirement extends React.PureComponent<SecurityRequirementProps> {
4466
render() {
4567
const security = this.props.security;
46-
return security.schemes.map((scheme, idx) => {
47-
return (
48-
<SecurityRequirementWrap key={scheme.id}>
49-
<a href={'#' + scheme.sectionId}>{scheme.id}</a>
50-
{scheme.scopes.length > 0 && ' ('}
51-
{scheme.scopes.map(scope => <ScopeName key={scope}>{scope}</ScopeName>)}
52-
{scheme.scopes.length > 0 && ') '}
53-
{idx < security.schemes.length - 1 && ' & '}
54-
</SecurityRequirementWrap>
55-
);
56-
});
68+
return (
69+
<SecurityRequirementOrWrap>
70+
{security.schemes.map(scheme => {
71+
return (
72+
<SecurityRequirementAndWrap key={scheme.id}>
73+
<a href={'#' + scheme.sectionId}>{scheme.id}</a>
74+
{scheme.scopes.length > 0 && ' ('}
75+
{scheme.scopes.map(scope => <ScopeName key={scope}>{scope}</ScopeName>)}
76+
{scheme.scopes.length > 0 && ') '}
77+
</SecurityRequirementAndWrap>
78+
);
79+
})}
80+
</SecurityRequirementOrWrap>
81+
);
5782
}
5883
}
5984

0 commit comments

Comments
 (0)