feat: add hideSecuritySection option allowing to disable the Security panel (#2027)

This commit is contained in:
Anastasiia Derymarko 2022-05-31 13:20:23 +03:00 committed by GitHub
parent a863302cc8
commit 49cc11d917
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 1 deletions

View File

@ -27,7 +27,7 @@ export function SecurityRequirements(props: SecurityRequirementsProps) {
const { securities } = props; const { securities } = props;
if (!securities?.length) { if (!securities?.length || store?.options.hideSecuritySection) {
return null; return null;
} }

View File

@ -49,4 +49,24 @@ describe('SecurityRequirement', () => {
); );
expect(component.html()).toMatchSnapshot(); 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(
<StoreProvider value={store}>
<SecurityRequirements securities={item.security} />,
</StoreProvider>,
),
);
expect(component.html().includes('Authorizations')).toBe(false);
expect(component.html().includes('svg')).toBe(false);
}
});
});
}); });

View File

@ -89,6 +89,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"hideHostname": false, "hideHostname": false,
"hideSchemaPattern": false, "hideSchemaPattern": false,
"hideSchemaTitles": false, "hideSchemaTitles": false,
"hideSecuritySection": false,
"hideSingleRequestSampleTab": false, "hideSingleRequestSampleTab": false,
"ignoreNamedSchemas": Set {}, "ignoreNamedSchemas": Set {},
"jsonSampleExpandLevel": 2, "jsonSampleExpandLevel": 2,
@ -346,6 +347,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"hideHostname": false, "hideHostname": false,
"hideSchemaPattern": false, "hideSchemaPattern": false,
"hideSchemaTitles": false, "hideSchemaTitles": false,
"hideSecuritySection": false,
"hideSingleRequestSampleTab": false, "hideSingleRequestSampleTab": false,
"ignoreNamedSchemas": Set {}, "ignoreNamedSchemas": Set {},
"jsonSampleExpandLevel": 2, "jsonSampleExpandLevel": 2,
@ -578,6 +580,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"hideHostname": false, "hideHostname": false,
"hideSchemaPattern": false, "hideSchemaPattern": false,
"hideSchemaTitles": false, "hideSchemaTitles": false,
"hideSecuritySection": false,
"hideSingleRequestSampleTab": false, "hideSingleRequestSampleTab": false,
"ignoreNamedSchemas": Set {}, "ignoreNamedSchemas": Set {},
"jsonSampleExpandLevel": 2, "jsonSampleExpandLevel": 2,
@ -877,6 +880,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"hideHostname": false, "hideHostname": false,
"hideSchemaPattern": false, "hideSchemaPattern": false,
"hideSchemaTitles": false, "hideSchemaTitles": false,
"hideSecuritySection": false,
"hideSingleRequestSampleTab": false, "hideSingleRequestSampleTab": false,
"ignoreNamedSchemas": Set {}, "ignoreNamedSchemas": Set {},
"jsonSampleExpandLevel": 2, "jsonSampleExpandLevel": 2,
@ -1134,6 +1138,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"hideHostname": false, "hideHostname": false,
"hideSchemaPattern": false, "hideSchemaPattern": false,
"hideSchemaTitles": false, "hideSchemaTitles": false,
"hideSecuritySection": false,
"hideSingleRequestSampleTab": false, "hideSingleRequestSampleTab": false,
"ignoreNamedSchemas": Set {}, "ignoreNamedSchemas": Set {},
"jsonSampleExpandLevel": 2, "jsonSampleExpandLevel": 2,
@ -1366,6 +1371,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"hideHostname": false, "hideHostname": false,
"hideSchemaPattern": false, "hideSchemaPattern": false,
"hideSchemaTitles": false, "hideSchemaTitles": false,
"hideSecuritySection": false,
"hideSingleRequestSampleTab": false, "hideSingleRequestSampleTab": false,
"ignoreNamedSchemas": Set {}, "ignoreNamedSchemas": Set {},
"jsonSampleExpandLevel": 2, "jsonSampleExpandLevel": 2,
@ -1621,6 +1627,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"hideHostname": false, "hideHostname": false,
"hideSchemaPattern": false, "hideSchemaPattern": false,
"hideSchemaTitles": false, "hideSchemaTitles": false,
"hideSecuritySection": false,
"hideSingleRequestSampleTab": false, "hideSingleRequestSampleTab": false,
"ignoreNamedSchemas": Set {}, "ignoreNamedSchemas": Set {},
"jsonSampleExpandLevel": 2, "jsonSampleExpandLevel": 2,
@ -1917,6 +1924,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"hideHostname": false, "hideHostname": false,
"hideSchemaPattern": false, "hideSchemaPattern": false,
"hideSchemaTitles": false, "hideSchemaTitles": false,
"hideSecuritySection": false,
"hideSingleRequestSampleTab": false, "hideSingleRequestSampleTab": false,
"ignoreNamedSchemas": Set {}, "ignoreNamedSchemas": Set {},
"jsonSampleExpandLevel": 2, "jsonSampleExpandLevel": 2,
@ -2174,6 +2182,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"hideHostname": false, "hideHostname": false,
"hideSchemaPattern": false, "hideSchemaPattern": false,
"hideSchemaTitles": false, "hideSchemaTitles": false,
"hideSecuritySection": false,
"hideSingleRequestSampleTab": false, "hideSingleRequestSampleTab": false,
"ignoreNamedSchemas": Set {}, "ignoreNamedSchemas": Set {},
"jsonSampleExpandLevel": 2, "jsonSampleExpandLevel": 2,
@ -2406,6 +2415,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
"hideHostname": false, "hideHostname": false,
"hideSchemaPattern": false, "hideSchemaPattern": false,
"hideSchemaTitles": false, "hideSchemaTitles": false,
"hideSecuritySection": false,
"hideSingleRequestSampleTab": false, "hideSingleRequestSampleTab": false,
"ignoreNamedSchemas": Set {}, "ignoreNamedSchemas": Set {},
"jsonSampleExpandLevel": 2, "jsonSampleExpandLevel": 2,

View File

@ -42,6 +42,7 @@ export interface RedocRawOptions {
schemaExpansionLevel?: number | string | 'all'; schemaExpansionLevel?: number | string | 'all';
showObjectSchemaExamples?: boolean | string; showObjectSchemaExamples?: boolean | string;
showSecuritySchemeType?: boolean; showSecuritySchemeType?: boolean;
hideSecuritySection?: boolean;
unstable_ignoreMimeParameters?: boolean; unstable_ignoreMimeParameters?: boolean;
@ -245,6 +246,7 @@ export class RedocNormalizedOptions {
schemaExpansionLevel: number; schemaExpansionLevel: number;
showObjectSchemaExamples: boolean; showObjectSchemaExamples: boolean;
showSecuritySchemeType?: boolean; showSecuritySchemeType?: boolean;
hideSecuritySection?: boolean;
/* tslint:disable-next-line */ /* tslint:disable-next-line */
unstable_ignoreMimeParameters: boolean; unstable_ignoreMimeParameters: boolean;
@ -317,6 +319,7 @@ export class RedocNormalizedOptions {
this.schemaExpansionLevel = argValueToExpandLevel(raw.schemaExpansionLevel); this.schemaExpansionLevel = argValueToExpandLevel(raw.schemaExpansionLevel);
this.showObjectSchemaExamples = argValueToBoolean(raw.showObjectSchemaExamples); this.showObjectSchemaExamples = argValueToBoolean(raw.showObjectSchemaExamples);
this.showSecuritySchemeType = argValueToBoolean(raw.showSecuritySchemeType); this.showSecuritySchemeType = argValueToBoolean(raw.showSecuritySchemeType);
this.hideSecuritySection = argValueToBoolean(raw.hideSecuritySection);
this.unstable_ignoreMimeParameters = argValueToBoolean(raw.unstable_ignoreMimeParameters); this.unstable_ignoreMimeParameters = argValueToBoolean(raw.unstable_ignoreMimeParameters);