Skip to content

Commit

Permalink
feat: add hideSecuritySection option allowing to disable the Security…
Browse files Browse the repository at this point in the history
… panel (#2027)
  • Loading branch information
anastasiia-developer authored May 31, 2022
1 parent a863302 commit 49cc11d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/SecurityRequirement/SecurityRequirement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function SecurityRequirements(props: SecurityRequirementsProps) {

const { securities } = props;

if (!securities?.length) {
if (!securities?.length || store?.options.hideSecuritySection) {
return null;
}

Expand Down
20 changes: 20 additions & 0 deletions src/components/__tests__/SecurityRequirement.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<StoreProvider value={store}>
<SecurityRequirements securities={item.security} />,
</StoreProvider>,
),
);
expect(component.html().includes('Authorizations')).toBe(false);
expect(component.html().includes('svg')).toBe(false);
}
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/services/RedocNormalizedOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface RedocRawOptions {
schemaExpansionLevel?: number | string | 'all';
showObjectSchemaExamples?: boolean | string;
showSecuritySchemeType?: boolean;
hideSecuritySection?: boolean;

unstable_ignoreMimeParameters?: boolean;

Expand Down Expand Up @@ -245,6 +246,7 @@ export class RedocNormalizedOptions {
schemaExpansionLevel: number;
showObjectSchemaExamples: boolean;
showSecuritySchemeType?: boolean;
hideSecuritySection?: boolean;

/* tslint:disable-next-line */
unstable_ignoreMimeParameters: boolean;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 49cc11d

Please sign in to comment.