Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: incorrect rendering of security schemas #995

Merged
merged 6 commits into from
Apr 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading