Skip to content

Commit b8c4ea8

Browse files
committed
feat: show sets of required scopes correctly
It is possible to define alternative required scopes for an operation and in the security header of the operation it is rendered correctly. However, in the "Required scopes" part it looks like that all these scopes are required. With these changes, the "Required scopes" part shows the required scopes per set. See: OAI/OpenAPI-Specification#3001 (comment)
1 parent 4d15a1f commit b8c4ea8

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/components/SecurityRequirement/RequiredScopesRow.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
import * as React from 'react';
22

3-
export const RequiredScopesRow = ({ scopes }: { scopes: string[] }): JSX.Element | null => {
4-
if (!scopes.length) return null;
3+
export const RequiredScopesRow = ({ scopeSets }: { scopeSets: string[][] }): JSX.Element | null => {
4+
if (!scopeSets.length) return null;
55

66
return (
77
<div>
88
<b>Required scopes: </b>
9-
{scopes.map((scope, idx) => {
9+
{scopeSets.map((scopeSet, ssIdx) => {
1010
return (
11-
<React.Fragment key={idx}>
12-
<code>{scope}</code>{' '}
11+
<React.Fragment key={ssIdx}>
12+
{scopeSet.map((scope, idx) => {
13+
return (
14+
<React.Fragment key={idx}>
15+
<code>{scope}</code>{' '}
16+
</React.Fragment>
17+
);
18+
})}
19+
{ssIdx + 1 < scopeSets.length && ' OR '}
1320
</React.Fragment>
1421
);
1522
})}

src/components/SecurityRequirement/SecurityRequirement.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function SecurityRequirements(props: SecurityRequirementsProps) {
6565
key={scheme.id}
6666
scheme={scheme}
6767
RequiredScopes={
68-
<RequiredScopesRow scopes={getRequiredScopes(scheme.id, securities)} />
68+
<RequiredScopesRow scopeSets={getRequiredScopeSets(scheme.id, securities)} />
6969
}
7070
/>
7171
</SecurityDetailsStyle>
@@ -83,17 +83,17 @@ const LockIcon = () => (
8383
</svg>
8484
);
8585

86-
function getRequiredScopes(id: string, securities: SecurityRequirementModel[]): string[] {
87-
const allScopes: string[] = [];
86+
function getRequiredScopeSets(id: string, securities: SecurityRequirementModel[]): string[][] {
87+
const allScopes: string[][] = [];
8888
let securitiesLength = securities.length;
8989

9090
while (securitiesLength--) {
9191
const security = securities[securitiesLength];
9292
let schemesLength = security.schemes.length;
9393
while (schemesLength--) {
9494
const scheme = security.schemes[schemesLength];
95-
if (scheme.id === id && Array.isArray(scheme.scopes)) {
96-
allScopes.push(...scheme.scopes);
95+
if (scheme.id === id && Array.isArray(scheme.scopes) && scheme.scopes.length) {
96+
allScopes.push(scheme.scopes);
9797
}
9898
}
9999
}

0 commit comments

Comments
 (0)