From 49cc11d91795653ca870e9276a1e0cd617964e25 Mon Sep 17 00:00:00 2001 From: Anastasiia Derymarko Date: Tue, 31 May 2022 13:20:23 +0300 Subject: [PATCH] feat: add hideSecuritySection option allowing to disable the Security panel (#2027) --- .../SecurityRequirement.tsx | 2 +- .../__tests__/SecurityRequirement.test.tsx | 20 +++++++++++++++++++ .../DiscriminatorDropdown.test.tsx.snap | 10 ++++++++++ src/services/RedocNormalizedOptions.ts | 3 +++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/components/SecurityRequirement/SecurityRequirement.tsx b/src/components/SecurityRequirement/SecurityRequirement.tsx index 7e8642eae7..5ae43782ea 100644 --- a/src/components/SecurityRequirement/SecurityRequirement.tsx +++ b/src/components/SecurityRequirement/SecurityRequirement.tsx @@ -27,7 +27,7 @@ export function SecurityRequirements(props: SecurityRequirementsProps) { const { securities } = props; - if (!securities?.length) { + if (!securities?.length || store?.options.hideSecuritySection) { return null; } diff --git a/src/components/__tests__/SecurityRequirement.test.tsx b/src/components/__tests__/SecurityRequirement.test.tsx index 87a2e51126..8d5e57618c 100644 --- a/src/components/__tests__/SecurityRequirement.test.tsx +++ b/src/components/__tests__/SecurityRequirement.test.tsx @@ -49,4 +49,24 @@ describe('SecurityRequirement', () => { ); expect(component.html()).toMatchSnapshot(); }); + + it('should hide authDefinition', async () => { + const store = await createStore(simpleSecurityFixture, undefined, { + hideSecuritySection: true, + }); + + store.spec.contentItems.forEach((item: OperationModel) => { + if (item.security) { + const component = mount( + withTheme( + + , + , + ), + ); + expect(component.html().includes('Authorizations')).toBe(false); + expect(component.html().includes('svg')).toBe(false); + } + }); + }); }); diff --git a/src/components/__tests__/__snapshots__/DiscriminatorDropdown.test.tsx.snap b/src/components/__tests__/__snapshots__/DiscriminatorDropdown.test.tsx.snap index 03eb89d5de..3480ad6f87 100644 --- a/src/components/__tests__/__snapshots__/DiscriminatorDropdown.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/DiscriminatorDropdown.test.tsx.snap @@ -89,6 +89,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideHostname": false, "hideSchemaPattern": false, "hideSchemaTitles": false, + "hideSecuritySection": false, "hideSingleRequestSampleTab": false, "ignoreNamedSchemas": Set {}, "jsonSampleExpandLevel": 2, @@ -346,6 +347,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideHostname": false, "hideSchemaPattern": false, "hideSchemaTitles": false, + "hideSecuritySection": false, "hideSingleRequestSampleTab": false, "ignoreNamedSchemas": Set {}, "jsonSampleExpandLevel": 2, @@ -578,6 +580,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideHostname": false, "hideSchemaPattern": false, "hideSchemaTitles": false, + "hideSecuritySection": false, "hideSingleRequestSampleTab": false, "ignoreNamedSchemas": Set {}, "jsonSampleExpandLevel": 2, @@ -877,6 +880,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideHostname": false, "hideSchemaPattern": false, "hideSchemaTitles": false, + "hideSecuritySection": false, "hideSingleRequestSampleTab": false, "ignoreNamedSchemas": Set {}, "jsonSampleExpandLevel": 2, @@ -1134,6 +1138,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideHostname": false, "hideSchemaPattern": false, "hideSchemaTitles": false, + "hideSecuritySection": false, "hideSingleRequestSampleTab": false, "ignoreNamedSchemas": Set {}, "jsonSampleExpandLevel": 2, @@ -1366,6 +1371,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideHostname": false, "hideSchemaPattern": false, "hideSchemaTitles": false, + "hideSecuritySection": false, "hideSingleRequestSampleTab": false, "ignoreNamedSchemas": Set {}, "jsonSampleExpandLevel": 2, @@ -1621,6 +1627,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideHostname": false, "hideSchemaPattern": false, "hideSchemaTitles": false, + "hideSecuritySection": false, "hideSingleRequestSampleTab": false, "ignoreNamedSchemas": Set {}, "jsonSampleExpandLevel": 2, @@ -1917,6 +1924,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideHostname": false, "hideSchemaPattern": false, "hideSchemaTitles": false, + "hideSecuritySection": false, "hideSingleRequestSampleTab": false, "ignoreNamedSchemas": Set {}, "jsonSampleExpandLevel": 2, @@ -2174,6 +2182,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideHostname": false, "hideSchemaPattern": false, "hideSchemaTitles": false, + "hideSecuritySection": false, "hideSingleRequestSampleTab": false, "ignoreNamedSchemas": Set {}, "jsonSampleExpandLevel": 2, @@ -2406,6 +2415,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideHostname": false, "hideSchemaPattern": false, "hideSchemaTitles": false, + "hideSecuritySection": false, "hideSingleRequestSampleTab": false, "ignoreNamedSchemas": Set {}, "jsonSampleExpandLevel": 2, diff --git a/src/services/RedocNormalizedOptions.ts b/src/services/RedocNormalizedOptions.ts index 9eef2fd9a3..3efcbac71e 100644 --- a/src/services/RedocNormalizedOptions.ts +++ b/src/services/RedocNormalizedOptions.ts @@ -42,6 +42,7 @@ export interface RedocRawOptions { schemaExpansionLevel?: number | string | 'all'; showObjectSchemaExamples?: boolean | string; showSecuritySchemeType?: boolean; + hideSecuritySection?: boolean; unstable_ignoreMimeParameters?: boolean; @@ -245,6 +246,7 @@ export class RedocNormalizedOptions { schemaExpansionLevel: number; showObjectSchemaExamples: boolean; showSecuritySchemeType?: boolean; + hideSecuritySection?: boolean; /* tslint:disable-next-line */ unstable_ignoreMimeParameters: boolean; @@ -317,6 +319,7 @@ export class RedocNormalizedOptions { this.schemaExpansionLevel = argValueToExpandLevel(raw.schemaExpansionLevel); this.showObjectSchemaExamples = argValueToBoolean(raw.showObjectSchemaExamples); this.showSecuritySchemeType = argValueToBoolean(raw.showSecuritySchemeType); + this.hideSecuritySection = argValueToBoolean(raw.hideSecuritySection); this.unstable_ignoreMimeParameters = argValueToBoolean(raw.unstable_ignoreMimeParameters);