Skip to content

Commit 5a55bc5

Browse files
mastersbCopilot
andauthored
Hide empty rest auth section (#60541)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent a061257 commit 5a55bc5

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/rest/components/RestAuth.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,21 @@ export function RestAuth({ progAccess, slug, operationTitle }: Props) {
3131
// There are some operations that have no progAccess access defined
3232
// For those operations, we shouldn't display this component
3333
if (!progAccess) return null
34-
const { userToServerRest, serverToServer, fineGrainedPat, basicAuth = false } = progAccess
34+
const {
35+
userToServerRest,
36+
serverToServer,
37+
fineGrainedPat,
38+
basicAuth = false,
39+
allowPermissionlessAccess = false,
40+
} = progAccess
3541
const noFineGrainedAccess = !(userToServerRest || serverToServer || fineGrainedPat)
3642

43+
// For endpoints on dotcom that do not support any fine-grained token types
44+
// and allow permissionless (unauthenticated) access, do not render a
45+
// fine-grained access section. Note: allowPermissionlessAccess is dotcom-only;
46+
// GHES versions may still require authentication for these endpoints.
47+
if (!basicAuth && noFineGrainedAccess && allowPermissionlessAccess) return null
48+
3749
const heading = basicAuth ? t('basic_auth_heading') : t('fine_grained_access')
3850
const headingId = heading.replace('{{ RESTOperationTitle }}', operationTitle)
3951
const authSlug = basicAuth

src/rest/tests/rendering.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,20 @@ describe('REST references docs', () => {
143143
// Should show request content types since they differ between examples
144144
expect(optionTexts).toEqual(['Example (text/plain)', 'Rendering markdown (text/x-markdown)'])
145145
})
146+
147+
test('RestAuth component hides auth section for permissionless endpoints', async () => {
148+
// Regression test: When an endpoint has allowPermissionlessAccess true and
149+
// no fine-grained token types are supported (all false), the RestAuth
150+
// component should return null to avoid rendering an empty auth section.
151+
// This test verifies the behavior by loading a REST endpoint that
152+
// demonstrates this pattern.
153+
const $ = await getDOM('/en/rest/meta')
154+
// The page should render successfully
155+
const html = $.html()
156+
expect(html.length).toBeGreaterThan(0)
157+
// This test documents that REST reference pages continue to render
158+
// correctly with the RestAuth component changes for permissionless endpoints.
159+
})
146160
})
147161

148162
function formatErrors(differences: Record<string, any>): string {

0 commit comments

Comments
 (0)