Skip to content

Commit

Permalink
chore: update security-requirement ui
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed Jul 14, 2018
1 parent e6ebdb7 commit 9f0252e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
28 changes: 16 additions & 12 deletions src/components/Markdown/styled.elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ import styled, {
withProps,
} from '../../styled-components';

export const linksCss = css`
a {
text-decoration: none;
color: ${props => props.theme.links.color};
&:visited {
color: ${props => props.theme.links.visited};
}
&:hover {
color: ${props => props.theme.links.hover};
}
}
`;

export const StyledMarkdownBlock = withProps<{ dense?: boolean; inline?: boolean }>(styled.div)`
font-family: ${props => props.theme.baseFont.family};
Expand Down Expand Up @@ -136,16 +151,5 @@ export const StyledMarkdownBlock = withProps<{ dense?: boolean; inline?: boolean
${extensionsHook('Markdown')};
a {
text-decoration: none;
color: ${props => props.theme.links.color};
&:visited {
color: ${props => props.theme.links.visited};
}
&:hover {
color: ${props => props.theme.links.hover};
}
}
${linksCss}
`;
26 changes: 23 additions & 3 deletions src/components/SecurityRequirement/SecuirityRequirement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import styled from '../../styled-components';

import { UnderlinedHeader } from '../../common-elements/headers';
import { SecurityRequirementModel } from '../../services/models/SecurityRequirement';
import { linksCss } from '../Markdown/styled.elements';

const ScopeName = styled.code`
font-size: ${props => props.theme.code.fontSize};
Expand All @@ -14,6 +15,25 @@ const ScopeName = styled.code`
padding: 0.2em;
display: inline-block;
line-height: 1;
&:after {
content: ',';
}
&:last-child:after {
content: none;
}
`;

const SecurityRequirementWrap = styled.span`
&:after {
content: ' OR ';
font-weight: bold;
}
&:last-child:after {
content: none;
}
${linksCss};
`;

export interface SecurityRequirementProps {
Expand All @@ -25,13 +45,13 @@ export class SecurityRequirement extends React.PureComponent<SecurityRequirement
const security = this.props.security;
return security.schemes.map((scheme, idx) => {
return (
<div key={scheme.id}>
<SecurityRequirementWrap key={scheme.id}>
<a href={'#' + scheme.sectionId}>{scheme.id}</a>
{scheme.scopes.length > 0 && ' ('}
{scheme.scopes.map(scope => <ScopeName key={scope}>{scope}</ScopeName>)}
{scheme.scopes.length > 0 && ') '}
{idx < security.schemes.length - 1 && ' and '}
</div>
{idx < security.schemes.length - 1 && ' & '}
</SecurityRequirementWrap>
);
});
}
Expand Down
7 changes: 3 additions & 4 deletions src/services/models/SecurityRequirement.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { OpenAPISecurityRequirement } from '../../types';
import { OpenAPISecurityRequirement, OpenAPISecurityScheme } from '../../types';
import { SECURITY_SCHEMES_SECTION } from '../../utils/openapi';
import { OpenAPIParser } from '../OpenAPIParser';

export interface SecurityScheme {
export interface SecurityScheme extends OpenAPISecurityScheme {
id: string;
sectionId: string;
type: string;
scopes: string[];
}

Expand All @@ -26,9 +25,9 @@ export class SecurityRequirementModel {
}

return {
...scheme,
id,
sectionId: SECURITY_SCHEMES_SECTION + id,
type: scheme.type,
scopes,
};
})
Expand Down

0 comments on commit 9f0252e

Please sign in to comment.