Repository navigation
feat(cli): add show-scopes option to list required scopes per auth scheme on each endpoint - #18672
Conversation
…er endpoint Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
🟡 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()), |
There was a problem hiding this comment.
🔵 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.
There was a problem hiding this comment.
Devin Review found 3 potential issues.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| } | ||
| const alternatives = security | ||
| .map((item) => [...new Set(Object.values(item).flat())]) | ||
| .filter((scopes) => scopes.length > 0) |
There was a problem hiding this comment.
🔴 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
| return undefined; | ||
| } | ||
| const alternatives = security | ||
| .map((item) => [...new Set(Object.values(item).flat())]) |
There was a problem hiding this comment.
🟡 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.
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)) { |
There was a problem hiding this comment.
🟡 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Docs Generation Benchmark ResultsComparing PR branch against median of 5 nightly run(s) on
Docs generation runs |
SDK Generation Benchmark ResultsComparing PR branch against median of 5 nightly run(s) on Full benchmark table (click to expand)
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 |
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>
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>
Description
Jira ticket:
Refs Pylon #24492 (Mailchimp)
Adds an opt-in
show-scopesflag to API Reference sections indocs.yml. When it istrue, the CLI publishes the scopes from each endpoint'ssecurityrequirements on that endpoint's FDRmultiAuthentries, 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.Changes Made
**Required scopes:**line to endpoint descriptions. RemovedappendRequiredScopesToEndpointDocsand its test.showScopesis passed from the docs.yml item through the pending registration,RegisterApiFn, andTranslatedApiSpec, and from there toconvertIrToFdrApi→convertPackage→convertMultiAuth. Callers:publishDocs,publishDocsLedger(translated locales), andpreviewDocs(base and translated). The flag is part of the registration dedupe key.convertMultiAuthaddsscopesonly when the flag is on and a scheme lists scopes. Duplicate scopes are removed.@fern-api/fdr-sdkto1.2.174-85d1a9dc5f, which addsMultipleAuthType.scopes.mainand resolved the schema conflicts with the newtypesoption, keeping both options.multiAuthoutput is unchanged.Testing
endpoint-scopesfixture inopenapi-from-flag.test.ts, checking output with the flag on and off.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