Skip to content

feat(cli): add show-scopes option to list required scopes per auth scheme on each endpoint - #18672

Merged
cadesark merged 6 commits into
mainfrom
devin/1793377196-show-oauth-scopes
Nov 19, 2026
Merged

cadesark merged 6 commits into
mainfrom
devin/1793377196-show-oauth-scopes

Conversation

@fern-api

@fern-api fern-api Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Description

Jira ticket:
Refs Pylon #24492 (Mailchimp)

Adds an opt-in show-scopes flag to API Reference sections in docs.yml. When it is true, the CLI publishes the scopes from each endpoint's security requirements on that endpoint's FDR multiAuth entries, keyed by scheme, for example { schemes: ["mcOauth2"], scopes: { mcOauth2: ["audiences:read"] } }. The renderer then lists them under the matching scheme in the endpoint's Authentication section. The renderer side is postman-eng/sdk-gen-fern-platform#1082, which is merged.

navigation:
  - api: API Reference
    show-scopes: true

Changes Made

  • Replaced the earlier approach, which appended a **Required scopes:** line to endpoint descriptions. Removed appendRequiredScopesToEndpointDocs and its test.
  • showScopes is passed from the docs.yml item through the pending registration, RegisterApiFn, and TranslatedApiSpec, and from there to convertIrToFdrApi → convertPackage → convertMultiAuth. Callers: publishDocs, publishDocsLedger (translated locales), and previewDocs (base and translated). The flag is part of the registration dedupe key.
  • convertMultiAuth adds scopes only when the flag is on and a scheme lists scopes. Duplicate scopes are removed.
  • Bumped @fern-api/fdr-sdk to 1.2.174-85d1a9dc5f, which adds MultipleAuthType.scopes.
  • Merged main and resolved the schema conflicts with the new types option, keeping both options.
  • Effect on existing sites: none while the flag is off, because multiAuth output is unchanged.

Testing

  • Unit tests added/updated: new endpoint-scopes fixture in openapi-from-flag.test.ts, checking output with the flag on and off.
  • Manual testing completed (end-to-end on a local stack is pending)

Link to Devin session: https://app.devin.ai/sessions/3d4af88f81ba4d0fbf81eceb2a4f81d8
Open in Devin Desktop: https://app.devin.ai/desktop/session/3d4af88f81ba4d0fbf81eceb2a4f81d8?variant=devin
Requested by: @cadesark


Devin Review

…er endpoint

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

@nitpickybot nitpickybot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Review Summary

Adds an opt-in show-scopes flag that appends OAuth scopes from endpoint security requirements into endpoint docs. The plumbing (schema, zod, parse, AST visitors, changelog) looks consistent. A few issues in the new util: mutating a shared IR, a fragile idempotency check, and a typed-interface mismatch with the real IR type; also the serialization layer uses the wire property name inconsistently with surrounding fields.

  • 🟡 2 warning(s)
  • 🔵 2 suggestion(s)

AI Review

🟡 warning — packages/cli/docs-resolver/src/utils/appendRequiredScopesToEndpointDocs.ts (line 15)

This function mutates the IR in place. DocsDefinitionResolver calls it on ir and on each translated IR; if the same IR object is ever reused for another navigation item (e.g. the same api referenced from two API Reference sections, one with show-scopes and one without), the scopes line leaks into the section that didn't ask for it. Worth either cloning the endpoints before mutation or documenting/guaranteeing that the IR is unique per item.

🔵 suggestion — packages/cli/docs-resolver/src/utils/appendRequiredScopesToEndpointDocs.ts (line 10)

The hand-rolled EndpointWithSecurity / structural ir parameter duplicates the real IR shape. If HttpEndpoint.docs or services ever changes (e.g. docs becomes a richer type), this will silently drift instead of failing to compile. Prefer typing the parameter as Pick<FernIr.IntermediateRepresentation, "services"> and deriving the endpoint type from FernIr.HttpEndpoint.

Also, the doc comment on lines 5-9 is attached to the EndpointWithSecurity interface rather than the function it describes — worth moving it above appendRequiredScopesToEndpointDocs.

Review Scope

  • Mode: Full pull request
  • Range: Full pull request through fd5eee71cfd413359450c573c372f0304a68e964
  • Current range coverage: Complete
  • Cumulative pull request coverage: Complete

This review is complete for the current scope. Addressing all critical and warning findings above satisfies the review; suggestions are optional. Request another review only if subsequent changes introduce new behavior or materially expand the pull request's scope.

for (const service of Object.values(ir.services)) {
for (const endpoint of service.endpoints) {
const scopesLine = getRequiredScopesLine(endpoint.security);
if (scopesLine == null || endpoint.docs?.includes(REQUIRED_SCOPES_LABEL)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 warning

The idempotency guard uses a substring check on the whole docs body. Any endpoint whose description legitimately contains the literal text **Required scopes:** (e.g. hand-written docs that already document scopes, or a spec authored before enabling the flag) will silently be skipped, so the generated line never appears. Consider instead tracking mutation at the call site (only run once per IR) or appending a non-visible marker/dedicated field rather than string-sniffing user content.

),
flattened: core.serialization.boolean().optional(),
paginated: core.serialization.boolean().optional(),
showScopes: core.serialization.property("show-scopes", core.serialization.boolean().optional()),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 suggestion

Please regenerate this file (and the JSON schemas) with the codegen rather than hand-editing — the PR description notes pnpm jsonschema wasn't run. Worth double-checking the generator emits the same core.serialization.property("show-scopes", ...) form here; neighboring fields like sort-by-availability use the raw key directly, so a mismatch would be easy to introduce by hand.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 3 potential issues.

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

}
const alternatives = security
.map((item) => [...new Set(Object.values(item).flat())])
.filter((scopes) => scopes.length > 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Optional OAuth scopes shown as mandatory

When an endpoint accepts OAuth or an unscoped alternative, getRequiredScopesLine discards the unscoped option. Readers see OAuth scopes labeled required despite a valid path without them.

Learn more

An endpoint's security array represents alternative ways to authorize a request; each entry is a collection of schemes that must all be satisfied. Empty scope lists still represent a valid authentication alternative, and an empty collection can represent anonymous access. The filter drops those alternatives while retaining scoped ones, so a statement about required scopes becomes false. The IR contract defines this alternative structure in HttpEndpoint.

Example: For security: [{ OAuth: ['plants:read'] }, { ApiKey: [] }], either OAuth with plants:read or an API key works. The generated description says **Required scopes:** plants:read without mentioning the API-key option.

Recommended fix: Preserve unscoped alternatives in the rendered requirement expression, including the authentication scheme or anonymous option where appropriate; do not label a scope universally required when another valid option does not need it.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

return undefined;
}
const alternatives = security
.map((item) => [...new Set(Object.values(item).flat())])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Multiple required credentials collapse into one scope list

When one security alternative requires two scoped schemes, getRequiredScopesLine merges their scopes into one list. Readers cannot tell that both credentials are required.

Learn more

An IR security entry is a collection of authentication schemes that must all be satisfied, not a single bag of scopes. Flattening the scope arrays loses the scheme boundaries and their AND relationship, while the output only distinguishes different entries using or. See the security contract.

Example: For security: [{ UserOAuth: ['profile:read'], AdminOAuth: ['audit:read'] }], the caller needs both credentials. The description presents profile:read, audit:read as one undifferentiated set of scopes.

Recommended fix: Format each scheme within an alternative separately, preserve its scheme name, and join schemes with an explicit AND before joining alternatives with OR.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

for (const service of Object.values(ir.services)) {
for (const endpoint of service.endpoints) {
const scopesLine = getRequiredScopesLine(endpoint.security);
if (scopesLine == null || endpoint.docs?.includes(REQUIRED_SCOPES_LABEL)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Existing label hides endpoint scope requirements

When authored endpoint docs contain **Required scopes:**, appendRequiredScopesToEndpointDocs skips the endpoint's actual security scopes. The displayed requirements can remain outdated or incomplete.

Learn more

The helper uses a string search in authored endpoint documentation as its idempotency test. Authored documentation is not generated state, so a naturally occurring label can block generation even on the helper's first invocation. Conversely the security requirements can change while a previously generated label remains.

Example: An endpoint's authored description says **Required scopes:** see the authorization guide, and its security declares plants:read. With show-scopes: true, the output omits plants:read.

Recommended fix: Track whether the helper added a line independently of authored content, or identify and replace only a generated suffix with a reliable marker; retain authored text and ensure the current scopes appear.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

Docs Generation Benchmark Results

Comparing PR branch against median of 5 nightly run(s) on main (latest: 2026-10-30T04:04:50Z).

Fixture main PR Delta
docs 159.8s (n=5) 250.4s (35 versions) +90.6s (+56.7%)

Docs generation runs fern generate --docs --preview end-to-end against the benchmark fixture with 35 API versions (each version: markdown processing + OpenAPI-to-IR + FDR upload).
Delta is computed against the nightly baseline on main.
Baseline from nightly run(s) on main (latest: 2026-10-30T04:04:50Z). Trigger benchmark-baseline to refresh.
Last updated: 2026-10-30 17:20 UTC

@github-actions

Copy link
Copy Markdown
Contributor

SDK Generation Benchmark Results

Comparing PR branch against median of 5 nightly run(s) on main (latest: 2026-10-30T04:04:50Z).

Full benchmark table (click to expand)
Generator Spec main (generator) main (E2E) PR (generator) Delta
csharp-sdk square 83s (n=4) 102s (n=5) 67s -16s (-19.3%)
go-sdk square 128s (n=5) 204s (n=5) 91s -37s (-28.9%)
java-sdk square 190s (n=4) 234s (n=5) 225s +35s (+18.4%)
php-sdk square 61s (n=5) N/A 63s +2s (+3.3%)
python-sdk square 122s (n=4) 187s (n=5) 147s +25s (+20.5%)
ruby-sdk-v2 square 81s (n=5) N/A 93s +12s (+14.8%)
rust-sdk square 194s (n=5) 189s (n=5) 274s +80s (+41.2%)
swift-sdk square 66s (n=4) 297s (n=5) 40s -26s (-39.4%)
ts-sdk square 149s (n=5) 139s (n=5) 95s -54s (-36.2%)

main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via fern generate). main (E2E): full customer-observable time including build/test scripts (nightly baseline, informational). Delta is computed against generator-only baseline.
⚠️ = generation exited with a non-zero exit code (timing may not reflect a successful run).
Baseline from nightly runs on main (latest: 2026-10-30T04:04:50Z). Trigger benchmark-baseline to refresh.
Last updated: 2026-10-30 17:22 UTC

feat(cli): publish show-scopes as per-scheme scopes on multiAuth instead of appending them to endpoint descriptions

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration devin-ai-integration Bot changed the title feat(cli): add show-scopes option to display required OAuth scopes per endpoint feat(cli): add show-scopes option to list required scopes per auth scheme on each endpoint Nov 19, 2026
cadesark and others added 3 commits November 19, 2026 19:23
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…AuthType.scopes

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@cadesark
cadesark merged commit a9b5e6c into main Nov 19, 2026
28 checks passed
@cadesark
cadesark deleted the devin/1793377196-show-oauth-scopes branch November 19, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants