Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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