fix: Optional authentication not rendered properly (#2117) (#2134)

This commit is contained in:
Grzegorz Zalewski 2022-08-17 15:02:12 +02:00 committed by GitHub
parent c60c6f5891
commit efd5e09c90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -17,6 +17,8 @@ export function SecurityHeader(props: SecurityRequirementProps) {
const { security, showSecuritySchemeType, expanded } = props; const { security, showSecuritySchemeType, expanded } = props;
const grouping = security.schemes.length > 1; const grouping = security.schemes.length > 1;
if (security.schemes.length === 0)
return <SecurityRequirementOrWrap expanded={expanded}>None</SecurityRequirementOrWrap>;
return ( return (
<SecurityRequirementOrWrap expanded={expanded}> <SecurityRequirementOrWrap expanded={expanded}>
{grouping && '('} {grouping && '('}

View File

@ -9,6 +9,7 @@ import {
SecuritySchemesModel, SecuritySchemesModel,
} from '../../services'; } from '../../services';
import { StoreProvider } from '../StoreBuilder'; import { StoreProvider } from '../StoreBuilder';
import { SecurityRequirementModel } from '../../services/models/SecurityRequirement';
import { SecurityRequirements } from '../SecurityRequirement/SecurityRequirement'; import { SecurityRequirements } from '../SecurityRequirement/SecurityRequirement';
import { withTheme } from '../testProviders'; import { withTheme } from '../testProviders';
import { SecurityDefs } from '../SecuritySchemes/SecuritySchemes'; import { SecurityDefs } from '../SecuritySchemes/SecuritySchemes';
@ -50,6 +51,20 @@ describe('SecurityRequirement', () => {
expect(component.html()).toMatchSnapshot(); 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 () => { it('should hide authDefinition', async () => {
const store = await createStore(simpleSecurityFixture, undefined, { const store = await createStore(simpleSecurityFixture, undefined, {
hideSecuritySection: true, hideSecuritySection: true,