Skip to content

Commit

Permalink
fix: Optional authentication not rendered properly (Redocly#2117)
Browse files Browse the repository at this point in the history
  • Loading branch information
zalewskigrzegorz committed Aug 16, 2022
1 parent c24b31b commit 697d556
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/components/SecurityRequirement/SecurityHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <SecurityRequirementOrWrap expanded={expanded}>None</SecurityRequirementOrWrap>;
return (
<SecurityRequirementOrWrap expanded={expanded}>
{grouping && '('}
Expand Down
15 changes: 15 additions & 0 deletions src/components/__tests__/SecurityRequirement.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(<SecurityRequirements securities={securityRequirement} key={1} />),
);
expect(component.find('span').at(0).text()).toEqual('None');
});

it('should hide authDefinition', async () => {
const store = await createStore(simpleSecurityFixture, undefined, {
hideSecuritySection: true,
Expand Down

0 comments on commit 697d556

Please sign in to comment.