-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
feat: remove auth section #2022
Merged
+650
−336
Merged
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
99ea5c5
feat: remove auth section
anastasiia-developer ba9666f
test: covered with tests
anastasiia-developer ba27ad4
fix: style
anastasiia-developer ce61960
test: update-snapshot
anastasiia-developer 5ccef30
test: update-snapshot
anastasiia-developer effbf97
Merge branch 'feat/remove_auth_section' of github.com:Redocly/redoc i…
anastasiia-developer 88a5864
test: move spec to fixtures
anastasiia-developer 03dd023
feat: remove noAutoAuth
anastasiia-developer 28dbb5c
fix: add Security Scheme Type
anastasiia-developer a1d4a0e
fix: updateOnHistory
anastasiia-developer 3565a60
test: update snapshotp
anastasiia-developer d6bbfdd
fix: delete noAutoAuth
anastasiia-developer eea2147
fix: Update src/services/OpenAPIParser.ts
anastasiia-developer 9830790
fix: style security Header
anastasiia-developer e5e488b
Merge branch 'feat/remove_auth_section' of github.com:Redocly/redoc i…
anastasiia-developer ab42c66
fix: OAuthFlow convert to functional component
anastasiia-developer 9812532
Merge branch 'master' into feat/remove_auth_section
anastasiia-developer 403c5cd
fix: use React memo for OAuthFlow
anastasiia-developer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import * as React from 'react'; | ||
import { OpenAPISecurityScheme } from '../../types'; | ||
import { SecurityRow } from './styled.elements'; | ||
import { SeeMore } from '../SeeMore/SeeMore'; | ||
import { Markdown } from '../Markdown/Markdown'; | ||
|
||
export interface OAuthFlowProps { | ||
type: string; | ||
flow: OpenAPISecurityScheme['flows'][keyof OpenAPISecurityScheme['flows']]; | ||
RequiredScopes?: JSX.Element; | ||
} | ||
|
||
export class OAuthFlow extends React.PureComponent<OAuthFlowProps> { | ||
render() { | ||
const { type, flow, RequiredScopes } = this.props; | ||
const scopesNames = Object.keys(flow?.scopes || {}); | ||
return ( | ||
<> | ||
<SecurityRow> | ||
<b>Flow type: </b> | ||
<code>{type} </code> | ||
</SecurityRow> | ||
{(type === 'implicit' || type === 'authorizationCode') && ( | ||
<SecurityRow> | ||
<strong> Authorization URL: </strong> | ||
<code> | ||
<a target="_blank" rel="noopener noreferrer" href={(flow as any).authorizationUrl}> | ||
{(flow as any).authorizationUrl} | ||
</a> | ||
</code> | ||
</SecurityRow> | ||
)} | ||
{(type === 'password' || type === 'clientCredentials' || type === 'authorizationCode') && ( | ||
<SecurityRow> | ||
<b> Token URL: </b> | ||
<code>{(flow as any).tokenUrl}</code> | ||
</SecurityRow> | ||
)} | ||
{flow!.refreshUrl && ( | ||
<SecurityRow> | ||
<strong> Refresh URL: </strong> | ||
{flow!.refreshUrl} | ||
</SecurityRow> | ||
)} | ||
{!!scopesNames.length && ( | ||
<> | ||
{RequiredScopes || null} | ||
<SecurityRow> | ||
<b> Scopes: </b> | ||
</SecurityRow> | ||
<SeeMore height="4em"> | ||
<ul> | ||
{scopesNames.map(scope => ( | ||
<li key={scope}> | ||
<code>{scope}</code> -{' '} | ||
<Markdown | ||
className={'redoc-markdown'} | ||
inline={true} | ||
source={flow!.scopes[scope] || ''} | ||
/> | ||
</li> | ||
))} | ||
</ul> | ||
</SeeMore> | ||
</> | ||
)} | ||
</> | ||
); | ||
} | ||
} |
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,18 @@ | ||
import * as React from 'react'; | ||
|
||
export const RequiredScopesRow = ({ scopes }: { scopes: string[] }): JSX.Element | null => { | ||
if (!scopes.length) return null; | ||
|
||
return ( | ||
<div> | ||
<b>Required scopes: </b> | ||
{scopes.map((scope, idx) => { | ||
return ( | ||
<React.Fragment key={idx}> | ||
<code>{scope}</code>{' '} | ||
</React.Fragment> | ||
); | ||
})} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import * as React from 'react'; | ||
import { SecuritySchemeModel } from '../../services'; | ||
import { titleize } from '../../utils'; | ||
import { StyledMarkdownBlock } from '../Markdown/styled.elements'; | ||
import { SecurityRow } from './styled.elements'; | ||
import { OAuthFlow } from './OAuthFlow'; | ||
|
||
interface SecuritySchemaProps { | ||
RequiredScopes?: JSX.Element; | ||
scheme: SecuritySchemeModel; | ||
} | ||
export function SecurityDetails(props: SecuritySchemaProps) { | ||
const { RequiredScopes, scheme } = props; | ||
|
||
return ( | ||
<StyledMarkdownBlock> | ||
{scheme.apiKey ? ( | ||
<> | ||
<SecurityRow> | ||
<b>{titleize(scheme.apiKey.in || '')} parameter name: </b> | ||
<code>{scheme.apiKey.name}</code> | ||
</SecurityRow> | ||
{RequiredScopes} | ||
</> | ||
) : scheme.http ? ( | ||
<> | ||
<SecurityRow> | ||
<b>HTTP Authorization Scheme: </b> | ||
<code>{scheme.http.scheme}</code> | ||
</SecurityRow> | ||
<SecurityRow> | ||
{scheme.http.scheme === 'bearer' && scheme.http.bearerFormat && ( | ||
<> | ||
<b>Bearer format: </b> | ||
<code>{scheme.http.bearerFormat}</code> | ||
</> | ||
)} | ||
</SecurityRow> | ||
{RequiredScopes} | ||
</> | ||
) : scheme.openId ? ( | ||
<> | ||
<SecurityRow> | ||
<b>Connect URL: </b> | ||
<code> | ||
<a target="_blank" rel="noopener noreferrer" href={scheme.openId.connectUrl}> | ||
{scheme.openId.connectUrl} | ||
</a> | ||
</code> | ||
</SecurityRow> | ||
{RequiredScopes} | ||
</> | ||
) : scheme.flows ? ( | ||
Object.keys(scheme.flows).map(type => ( | ||
<OAuthFlow | ||
key={type} | ||
type={type} | ||
RequiredScopes={RequiredScopes} | ||
flow={scheme.flows[type]} | ||
/> | ||
)) | ||
) : null} | ||
</StyledMarkdownBlock> | ||
); | ||
} |
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,43 @@ | ||
import { SecurityRequirementModel } from '../../services/models/SecurityRequirement'; | ||
import { | ||
ScopeName, | ||
SecurityRequirementAndWrap, | ||
SecurityRequirementOrWrap, | ||
} from './styled.elements'; | ||
import * as React from 'react'; | ||
import { AUTH_TYPES } from '../SecuritySchemes/SecuritySchemes'; | ||
|
||
export interface SecurityRequirementProps { | ||
security: SecurityRequirementModel; | ||
showSecuritySchemeType?: boolean; | ||
expanded: boolean; | ||
} | ||
|
||
export function SecurityHeader(props: SecurityRequirementProps) { | ||
const { security, showSecuritySchemeType, expanded } = props; | ||
|
||
const grouping = security.schemes.length > 1; | ||
return ( | ||
<SecurityRequirementOrWrap expanded={expanded}> | ||
{grouping && '('} | ||
{security.schemes.map(scheme => { | ||
return ( | ||
<SecurityRequirementAndWrap key={scheme.id}> | ||
{showSecuritySchemeType && `${AUTH_TYPES[scheme.type] || scheme.type}: `} | ||
<i>{scheme.displayName}</i> | ||
{expanded && scheme.scopes.length | ||
? [ | ||
' (', | ||
scheme.scopes.map<React.ReactNode>(scope => ( | ||
<ScopeName key={scope}>{scope}</ScopeName> | ||
)), | ||
') ', | ||
] | ||
: null} | ||
</SecurityRequirementAndWrap> | ||
); | ||
})} | ||
{grouping && ') '} | ||
</SecurityRequirementOrWrap> | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great to use functional component here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anastasiia-developer Previously it was a
PureComponent
after refactoring it to the function component we need to keep the performance in the rendering perspective. So we might use Reactmemo
HOC here, what do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, we might
I'm going to add that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done