From efd5e09c907b36a3999f4c9c3165b6b2bdc1d536 Mon Sep 17 00:00:00 2001 From: Grzegorz Zalewski <12560152+zalewskigrzegorz@users.noreply.github.com> Date: Wed, 17 Aug 2022 15:02:12 +0200 Subject: [PATCH] fix: Optional authentication not rendered properly (#2117) (#2134) --- .../SecurityRequirement/SecurityHeader.tsx | 2 ++ .../__tests__/SecurityRequirement.test.tsx | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/components/SecurityRequirement/SecurityHeader.tsx b/src/components/SecurityRequirement/SecurityHeader.tsx index c542b51c..12047db1 100644 --- a/src/components/SecurityRequirement/SecurityHeader.tsx +++ b/src/components/SecurityRequirement/SecurityHeader.tsx @@ -17,6 +17,8 @@ export function SecurityHeader(props: SecurityRequirementProps) { const { security, showSecuritySchemeType, expanded } = props; const grouping = security.schemes.length > 1; + if (security.schemes.length === 0) + return None; return ( {grouping && '('} diff --git a/src/components/__tests__/SecurityRequirement.test.tsx b/src/components/__tests__/SecurityRequirement.test.tsx index 8d5e5761..ad17b81b 100644 --- a/src/components/__tests__/SecurityRequirement.test.tsx +++ b/src/components/__tests__/SecurityRequirement.test.tsx @@ -9,6 +9,7 @@ import { SecuritySchemesModel, } from '../../services'; import { StoreProvider } from '../StoreBuilder'; +import { SecurityRequirementModel } from '../../services/models/SecurityRequirement'; import { SecurityRequirements } from '../SecurityRequirement/SecurityRequirement'; import { withTheme } from '../testProviders'; import { SecurityDefs } from '../SecuritySchemes/SecuritySchemes'; @@ -50,6 +51,20 @@ describe('SecurityRequirement', () => { expect(component.html()).toMatchSnapshot(); }); + it("should render 'None' when empty object in security open api", () => { + const options = new RedocNormalizedOptions({}); + const parser = new OpenAPIParser( + { openapi: '3.0', info: { title: 'test', version: '0' }, paths: {} }, + undefined, + options, + ); + const securityRequirement = [new SecurityRequirementModel({}, parser)]; + const component = mount( + withTheme(), + ); + expect(component.find('span').at(0).text()).toEqual('None'); + }); + it('should hide authDefinition', async () => { const store = await createStore(simpleSecurityFixture, undefined, { hideSecuritySection: true,