Skip to content

Commit

Permalink
fix: incorrect rendering of security schemas (#995)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTail authored Apr 25, 2024
1 parent ed66855 commit 3be2456
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions library/src/containers/Servers/Security.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
} from '@asyncapi/parser';

import { Href, Markdown } from '../../components';
import { useSpec } from '../../contexts';
import { ServerHelpers } from '../../helpers';

interface Props {
Expand All @@ -20,29 +19,20 @@ export const Security: React.FunctionComponent<Props> = ({
protocol = '',
header = 'Security',
}) => {
const asyncapi = useSpec();
const securitySchemes =
!asyncapi.components().isEmpty() && asyncapi.components().securitySchemes();

let renderedSecurities;
if (
!security?.length ||
!securitySchemes ||
!Object.keys(securitySchemes).length
) {
if (!security?.length) {
if (protocol === 'kafka' || protocol === 'kafka-secure') {
renderedSecurities = (
<SecurityItem protocol={protocol} securitySchema={null} />
);
}
} else {
const securities: React.ReactNodeArray = Object.values(security)
.map((requirements) => requirements.all())
.flat()
.map((requirement) => {
const requirements = requirement.all();
const key = Object.keys(requirements)[0];
const def = securitySchemes[Number(key)];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const requiredScopes: any = requirements[Number(key)];
const def = requirement.scheme();
const requiredScopes = requirement.scopes();

if (!def) {
return null;
Expand All @@ -51,7 +41,6 @@ export const Security: React.FunctionComponent<Props> = ({
<SecurityItem
protocol={protocol}
securitySchema={def}
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
requiredScopes={requiredScopes}
key={def.type()}
/>
Expand Down

0 comments on commit 3be2456

Please sign in to comment.