-
Notifications
You must be signed in to change notification settings - Fork 4k
Rework OpenAPI Authorizations + scopes #3786
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
Merged
nolannbiron
merged 5 commits into
main
from
nolann/remove-authorization-disclosure-openapi
Nov 6, 2025
+312
−123
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,120 @@ | ||
| 'use client'; | ||
|
|
||
| import { OpenAPICopyButton } from './OpenAPICopyButton'; | ||
| import { OpenAPIDisclosureGroup } from './OpenAPIDisclosureGroup'; | ||
| import { useSelectState } from './OpenAPISelect'; | ||
| import type { OpenAPIClientContext } from './context'; | ||
| import { t } from './translate'; | ||
| import type { OpenAPISecurityScope } from './types'; | ||
| import type { OperationSecurityInfo } from './utils'; | ||
|
|
||
| /** | ||
| * Present securities authorization that can be used for this operation. | ||
| */ | ||
| export function OpenAPIRequiredScopes(props: { | ||
| securities: OperationSecurityInfo[]; | ||
| context: OpenAPIClientContext; | ||
| stateKey: string; | ||
| }) { | ||
| const { securities, stateKey, context } = props; | ||
| const { key: selectedKey } = useSelectState(stateKey, securities[0]?.key); | ||
| const selectedSecurity = securities.find((security) => security.key === selectedKey); | ||
|
|
||
| if (!selectedSecurity) { | ||
| return null; | ||
| } | ||
|
|
||
| const scopes = selectedSecurity.schemes.flatMap((scheme) => { | ||
| if (scheme.type === 'oauth2') { | ||
| return Object.entries(scheme.flows ?? {}).flatMap(([_, flow]) => | ||
| Object.entries(flow.scopes ?? {}) | ||
| ); | ||
| } | ||
|
|
||
| return scheme.scopes ?? []; | ||
| }); | ||
|
|
||
| if (!scopes.length) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <OpenAPIDisclosureGroup | ||
| className="openapi-required-scopes" | ||
| icon={context.icons.chevronRight} | ||
| stateKey="required-scopes" | ||
| defaultExpandedKeys={['required-scopes']} | ||
| groups={[ | ||
| { | ||
| key: 'required-scopes', | ||
| label: ( | ||
| <div className="openapi-required-scopes-header"> | ||
| {context.icons.lock} | ||
| <span>{t(context.translation, 'required_scopes')}</span> | ||
| </div> | ||
| ), | ||
| tabs: [ | ||
| { | ||
| key: 'scopes', | ||
| label: '', | ||
| body: <OpenAPISchemaScopes scopes={scopes} context={context} />, | ||
| }, | ||
| ], | ||
| }, | ||
| ]} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| function OpenAPISchemaScopes(props: { | ||
| scopes: OpenAPISecurityScope[]; | ||
| context: OpenAPIClientContext; | ||
| }) { | ||
| const { scopes, context } = props; | ||
|
|
||
| return ( | ||
| <div className="openapi-securities-scopes openapi-markdown"> | ||
| <div className="openapi-required-scopes-description"> | ||
| {t(context.translation, 'required_scopes_description')} | ||
| </div> | ||
| <ul> | ||
| {scopes.map((scope) => ( | ||
| <OpenAPIScopeItem key={scope[0]} scope={scope} context={context} /> | ||
| ))} | ||
| </ul> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Display a scope item. Either a key-value pair or a single string. | ||
| */ | ||
| function OpenAPIScopeItem(props: { | ||
| scope: OpenAPISecurityScope; | ||
| context: OpenAPIClientContext; | ||
| }) { | ||
| const { scope, context } = props; | ||
|
|
||
| return ( | ||
| <li> | ||
| <OpenAPIScopeItemKey name={scope[0]} context={context} /> | ||
| {scope[1] ? <span>: {scope[1]}</span> : null} | ||
| </li> | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Displays the scope name within a copyable button. | ||
| */ | ||
| function OpenAPIScopeItemKey(props: { | ||
| name: string; | ||
| context: OpenAPIClientContext; | ||
| }) { | ||
| const { name, context } = props; | ||
|
|
||
| return ( | ||
| <OpenAPICopyButton value={name} context={context} withTooltip> | ||
| <code>{name}</code> | ||
| </OpenAPICopyButton> | ||
| ); | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.