-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial display security requirements
- Loading branch information
1 parent
9be4071
commit 50e2a58
Showing
11 changed files
with
131 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/components/SecurityRequirement/SecuirityRequirement.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import * as React from 'react'; | ||
import styled from '../../styled-components'; | ||
import { transparentizeHex } from '../../utils/styled'; | ||
|
||
import { SecurityRequirementModel } from '../../services/models/SecurityRequirement'; | ||
import { UnderlinedHeader } from '../../common-elements/headers'; | ||
|
||
const ScopeName = styled.code` | ||
font-size: ${props => props.theme.code.fontSize}; | ||
font-family: ${props => props.theme.code.fontFamily}; | ||
border: 1px solid ${props => transparentizeHex(props.theme.colors.text, 0.15)}; | ||
margin: 0 3px; | ||
padding: 0.2em; | ||
display: inline-block; | ||
line-height: 1; | ||
`; | ||
|
||
export interface SecurityRequirementProps { | ||
security: SecurityRequirementModel; | ||
} | ||
|
||
export class SecurityRequirement extends React.PureComponent<SecurityRequirementProps> { | ||
render() { | ||
const security = this.props.security; | ||
return security.schemes.map((scheme, idx) => { | ||
return ( | ||
<div 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> | ||
); | ||
}); | ||
} | ||
} | ||
|
||
const AuthHeaderColumn = styled.div` | ||
display: inline-block; | ||
width: calc(100% - ${props => props.theme.schemaView.defaultDetailsWidth}); | ||
`; | ||
|
||
const SecuritiesColumn = styled.div` | ||
width: ${props => props.theme.schemaView.defaultDetailsWidth}; | ||
display: inline-block; | ||
`; | ||
|
||
const AuthHeader = styled(UnderlinedHeader)` | ||
display: inline-block; | ||
`; | ||
|
||
export interface SecurityRequirementsProps { | ||
securities: SecurityRequirementModel[]; | ||
} | ||
|
||
export class SecurityRequirements extends React.PureComponent<SecurityRequirementsProps> { | ||
render() { | ||
const securities = this.props.securities; | ||
if (!securities.length) return null; | ||
return ( | ||
<div> | ||
<AuthHeaderColumn> | ||
<AuthHeader>Authorizations: </AuthHeader> | ||
</AuthHeaderColumn> | ||
<SecuritiesColumn> | ||
{securities.map((security, idx) => <SecurityRequirement key={idx} security={security} />)} | ||
</SecuritiesColumn> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { OpenAPISecurityRequirement } from '../../types'; | ||
import { OpenAPIParser } from '../OpenAPIParser'; | ||
import { SECURITY_SCHEMES_SECTION } from '../../utils/openapi'; | ||
|
||
export class SecurityRequirementModel { | ||
schemes: { | ||
id: string; | ||
sectionId: string; | ||
type: string; | ||
scopes: string[]; | ||
}[]; | ||
|
||
constructor(requirement: OpenAPISecurityRequirement, parser: OpenAPIParser) { | ||
const schemes = (parser.spec.components && parser.spec.components.securitySchemes) || {}; | ||
|
||
this.schemes = Object.keys(requirement || {}).map(id => { | ||
const scheme = parser.deref(schemes[id]); | ||
const scopes = requirement[id] || []; | ||
return { | ||
id, | ||
sectionId: SECURITY_SCHEMES_SECTION + id, | ||
type: scheme.type, | ||
scopes, | ||
}; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters