From e2b6a51e1b47b75f738986e7afe4b284a6ea9cd0 Mon Sep 17 00:00:00 2001 From: Robin Tail Date: Mon, 22 Apr 2024 21:51:14 +0200 Subject: [PATCH 1/5] Fix: correctly display security scheme by reference. --- library/src/containers/Servers/Security.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/library/src/containers/Servers/Security.tsx b/library/src/containers/Servers/Security.tsx index ad125cd0..11f8f48b 100644 --- a/library/src/containers/Servers/Security.tsx +++ b/library/src/containers/Servers/Security.tsx @@ -39,9 +39,8 @@ export const Security: React.FunctionComponent = ({ const securities: React.ReactNodeArray = Object.values(security) .map(requirement => { const requirements = requirement.all(); - const key = Object.keys(requirements)[0]; - const def = securitySchemes[Number(key)]; - const requiredScopes: any = requirements[Number(key)]; + const def = requirements[0].scheme(); + const requiredScopes = requirements[0].scopes(); if (!def) { return null; From 2578b82d5ddefcbb5b0d0aef53b47e129bdb4644 Mon Sep 17 00:00:00 2001 From: Robin Tail Date: Mon, 22 Apr 2024 22:06:36 +0200 Subject: [PATCH 2/5] Fix for security schemas written inline (case 3). --- library/src/containers/Servers/Security.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/library/src/containers/Servers/Security.tsx b/library/src/containers/Servers/Security.tsx index 11f8f48b..3f1d2033 100644 --- a/library/src/containers/Servers/Security.tsx +++ b/library/src/containers/Servers/Security.tsx @@ -30,11 +30,16 @@ export const Security: React.FunctionComponent = ({ !securitySchemes || !Object.keys(securitySchemes).length ) { - if (protocol === 'kafka' || protocol === 'kafka-secure') { - renderedSecurities = ( - - ); - } + renderedSecurities = ( + + ); } else { const securities: React.ReactNodeArray = Object.values(security) .map(requirement => { From a4b2c8df39f3330ca101c2402d62cf0c279c4bc5 Mon Sep 17 00:00:00 2001 From: Robin Tail Date: Mon, 22 Apr 2024 22:15:46 +0200 Subject: [PATCH 3/5] Handle possibly zero length. --- library/src/containers/Servers/Security.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/src/containers/Servers/Security.tsx b/library/src/containers/Servers/Security.tsx index 3f1d2033..051d2f29 100644 --- a/library/src/containers/Servers/Security.tsx +++ b/library/src/containers/Servers/Security.tsx @@ -36,7 +36,7 @@ export const Security: React.FunctionComponent = ({ securitySchema={ ['kafka', 'kafka-secure'].includes(protocol) ? null - : security[0].all()[0].scheme() + : security[0]?.all()[0].scheme() } /> ); From 4473af02967df9f450e39b8eefbb69b3990085e5 Mon Sep 17 00:00:00 2001 From: Robin Tail Date: Mon, 22 Apr 2024 22:29:13 +0200 Subject: [PATCH 4/5] Ref: also handling multiple schemas. --- library/src/containers/Servers/Security.tsx | 35 +++++++-------------- 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/library/src/containers/Servers/Security.tsx b/library/src/containers/Servers/Security.tsx index 051d2f29..51d25341 100644 --- a/library/src/containers/Servers/Security.tsx +++ b/library/src/containers/Servers/Security.tsx @@ -6,7 +6,6 @@ import { } from '@asyncapi/parser'; import { Href, Markdown } from '../../components'; -import { useSpec } from '../../contexts'; import { ServerHelpers } from '../../helpers'; interface Props { @@ -20,32 +19,20 @@ export const Security: React.FunctionComponent = ({ protocol = '', header = 'Security', }) => { - const asyncapi = useSpec(); - const securitySchemes = - !asyncapi.components().isEmpty() && asyncapi.components().securitySchemes(); - let renderedSecurities; - if ( - !security?.length || - !securitySchemes || - !Object.keys(securitySchemes).length - ) { - renderedSecurities = ( - - ); + if (!security?.length) { + if (protocol === 'kafka' || protocol === 'kafka-secure') { + renderedSecurities = ( + + ); + } } else { const securities: React.ReactNodeArray = Object.values(security) - .map(requirement => { - const requirements = requirement.all(); - const def = requirements[0].scheme(); - const requiredScopes = requirements[0].scopes(); + .map(requirement => requirement.all()) + .flat() + .map(requirements => { + const def = requirements.scheme(); + const requiredScopes = requirements.scopes(); if (!def) { return null; From 9a29e133d398f439780d01dbaacd3724e6a152b2 Mon Sep 17 00:00:00 2001 From: Robin Tail Date: Mon, 22 Apr 2024 22:58:49 +0200 Subject: [PATCH 5/5] Minor: naming: plural and singular. --- library/src/containers/Servers/Security.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/src/containers/Servers/Security.tsx b/library/src/containers/Servers/Security.tsx index 51d25341..b404fb0c 100644 --- a/library/src/containers/Servers/Security.tsx +++ b/library/src/containers/Servers/Security.tsx @@ -28,11 +28,11 @@ export const Security: React.FunctionComponent = ({ } } else { const securities: React.ReactNodeArray = Object.values(security) - .map(requirement => requirement.all()) + .map(requirements => requirements.all()) .flat() - .map(requirements => { - const def = requirements.scheme(); - const requiredScopes = requirements.scopes(); + .map(requirement => { + const def = requirement.scheme(); + const requiredScopes = requirement.scopes(); if (!def) { return null;