Skip to content

feat: add a 'pseudoCode' flag for request viewers to default showing …#1234

Open
aaguiarz wants to merge 6 commits intomainfrom
feat/pseudo-code-mode
Open

feat: add a 'pseudoCode' flag for request viewers to default showing …#1234
aaguiarz wants to merge 6 commits intomainfrom
feat/pseudo-code-mode

Conversation

@aaguiarz
Copy link
Copy Markdown
Member

@aaguiarz aaguiarz commented Apr 12, 2026

…just pseudocode

Description

What problem is being solved?

When we want to explain a specific use case, showing the API syntax in every language adds noise, and makes the document more complex to read.

I'm adding a parameter to RequestViewer widgets that makes them show a pseudo code version by default and allow viewing the SDK syntax. By default it shows the SDK view,

pseudocode-tab

I like to get the team's opinion and we probably need to adjust the design of the action link. I think we should change the default to show the pseudo code view in most places besides that pages that explain how to use the APIs.

How is it being solved?

What changes are made to solve it?

References

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

Summary by CodeRabbit

  • New Features

    • Added a toggle to switch between SDK syntax and pseudocode views in code examples for improved readability.
  • Documentation

    • Updated authorization model documentation to showcase the pseudocode viewing capability.
  • Style

    • Improved code snippet formatting by streamlining RPC code generation output.

@aaguiarz aaguiarz requested review from a team as code owners April 12, 2026 03:40
Copilot AI review requested due to automatic review settings April 12, 2026 03:40
@aaguiarz aaguiarz requested a review from a team as a code owner April 12, 2026 03:40
@aaguiarz aaguiarz requested review from Copilot and rhamzeh and removed request for Copilot April 12, 2026 03:40
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 12, 2026

Walkthrough

The pull request introduces a new pseudoCodeMode option to multiple code snippet viewer components and refines RPC code snippet generation across the codebase. The feature enables switching between SDK syntax and pseudocode views, with adjustments to remove version-compatibility comments and certain authorization parameters from generated code samples.

Changes

Cohort / File(s) Summary
Documentation example updates
docs/content/modeling/agents/agents-as-principals.mdx
Added pseudoCodeMode={true} prop to CheckRequestViewer components in permission-check examples.
Viewer interface option additions
src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx, src/components/Docs/SnippetViewer/CheckRequestViewer.tsx, src/components/Docs/SnippetViewer/ListObjectsRequestViewer.tsx, src/components/Docs/SnippetViewer/ListUsersRequestViewer.tsx
Added optional pseudoCodeMode?: boolean property to respective \*ViewerOpts interfaces.
RPC snippet generation refinements
src/components/Docs/SnippetViewer/CheckRequestViewer.tsx, src/components/Docs/SnippetViewer/ListObjectsRequestViewer.tsx, src/components/Docs/SnippetViewer/ListUsersRequestViewer.tsx, src/components/Docs/SnippetViewer/WriteRequestViewer.tsx
Modified RPC code template formatting: removed version-compatibility comments (in CheckRequestViewer), removed authorization_model_id arguments, and adjusted contextual tuple/newline rendering in generated snippets.
Batch viewer snippet cleanup
src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx
Removed leading version-compatibility comment lines from JS, Go, Python, and Java SDK code snippet templates, adjusting string interpolation to begin directly with code statements.
Tabbed viewer UI refactoring
src/components/Docs/SnippetViewer/DefaultTabbedViewer.tsx
Added pseudoCodeMode option, introduced SdkToggle component with local state for switching between "SDK syntax" and "View Pseudocode" modes, conditional rendering of either tabbed UI or RPC language wrapper with adjusted margin styling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • dyeam0
  • rhamzeh
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main feature: adding a 'pseudoCode' flag to request viewers to control default display mode between pseudocode and SDK syntax.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/pseudo-code-mode

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 12, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://openfga.github.io/openfga.dev/pr-preview/pr-1234/

Built to branch gh-pages at 2026-04-12 16:30 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a pseudoCodeMode option to request snippet viewers so they can default to showing pseudocode (RPC) and optionally toggle to SDK syntax.

Changes:

  • Introduces pseudoCodeMode?: boolean on several RequestViewer option types and uses it in the shared tabbed viewer.
  • Adds a pseudocode-first rendering path with a “View SDK syntax” toggle in DefaultTabbedViewer.
  • Simplifies some pseudocode (RPC) outputs by removing authorization model ID parameters and adjusts one doc page to enable pseudocode mode.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/components/Docs/SnippetViewer/DefaultTabbedViewer.tsx Adds pseudoCodeMode handling and a toggle UI to switch between pseudocode and non-RPC views.
src/components/Docs/SnippetViewer/CheckRequestViewer.tsx Adds pseudoCodeMode opt and tweaks RPC pseudocode formatting/fields.
src/components/Docs/SnippetViewer/ListUsersRequestViewer.tsx Adds pseudoCodeMode opt and simplifies RPC pseudocode.
src/components/Docs/SnippetViewer/ListObjectsRequestViewer.tsx Adds pseudoCodeMode opt and simplifies RPC pseudocode.
src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx Adds pseudoCodeMode opt and removes SDK version requirement comments from snippets.
src/components/Docs/SnippetViewer/WriteRequestViewer.tsx Simplifies RPC pseudocode for write/delete calls.
docs/content/modeling/agents/agents-as-principals.mdx Enables pseudocode-first view for the embedded Check examples.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/components/Docs/SnippetViewer/DefaultTabbedViewer.tsx Outdated
Comment thread src/components/Docs/SnippetViewer/DefaultTabbedViewer.tsx
Comment thread src/components/Docs/SnippetViewer/DefaultTabbedViewer.tsx Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/components/Docs/SnippetViewer/CheckRequestViewer.tsx (1)

257-279: ⚠️ Potential issue | 🟠 Major

Preserve custom headers in the RPC/pseudocode renderer.

This branch now drops opts.headers entirely. Because defaultOperationsViewer() makes the RPC block the default view when pseudoCodeMode is enabled, any example that depends on custom headers now renders an incomplete request unless the reader manually switches views.

Suggested fix
 return `check(
   user = "${user}", // check if the user \`${user}\`
   relation = "${relation}", // has an \`${relation}\` relation
   object = "${object}", // with the object \`${object}\`${
+    headers && Object.keys(headers).length > 0
+      ? `
+  headers = { ${Object.entries(headers)
+    .map(([key, value]) => `${key} = "${value}"`)
+    .join(', ')} },`
+      : ''
+  }${
     contextualTuples
       ? `
   contextual_tuples = [ // Assuming the following is true
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/Docs/SnippetViewer/CheckRequestViewer.tsx` around lines 257 -
279, The pseudocode renderer in CheckRequestViewer.tsx currently omits
opts.headers, causing examples relying on custom headers to render incomplete
RPC blocks; update the string template that returns the check(...) snippet (the
block that uses user, relation, object, contextualTuples, context, and Reply:
${allowed}) to include a headers section when opts.headers exists—format it
similarly to the context block (map Object.entries(opts.headers) into key =
"value" or "Key: Value" lines) so headers are rendered into the pseudocode by
default when pseudoCodeMode/defaultOperationsViewer() selects this view.
🧹 Nitpick comments (1)
src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx (1)

16-21: Consider inheriting the shared viewer options.

skipSetup/pseudoCodeMode are now duplicated across multiple *RequestViewerOpts types. Extending DefaultTabbedViewerOpts here would keep the shared contract in one place and reduce drift the next time a common viewer option is added.

Suggested refactor
-import { defaultOperationsViewer } from './DefaultTabbedViewer';
+import { defaultOperationsViewer, type DefaultTabbedViewerOpts } from './DefaultTabbedViewer';
@@
-interface BatchCheckRequestViewerOpts {
+interface BatchCheckRequestViewerOpts extends DefaultTabbedViewerOpts {
   authorizationModelId?: string;
   checks: Check[];
-  skipSetup?: boolean;
-  pseudoCodeMode?: boolean;
   allowedLanguages?: SupportedLanguage[];
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx` around lines
16 - 21, The BatchCheckRequestViewerOpts type duplicates common viewer options
(skipSetup, pseudoCodeMode) — change its declaration to extend the shared
DefaultTabbedViewerOpts so these shared fields are inherited; update the
interface name BatchCheckRequestViewerOpts to `extends DefaultTabbedViewerOpts`
and remove the duplicated skipSetup and pseudoCodeMode properties, keeping
unique fields like authorizationModelId, checks, and allowedLanguages as-is.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/Docs/SnippetViewer/DefaultTabbedViewer.tsx`:
- Around line 81-93: The current render guard uses pseudoCodeMode && hasRpc
which still shows the SdkToggle when RPC is the only allowed language; change
the condition so the toggle only renders if there is at least one SDK language
besides RPC (e.g., compute sdkLanguages = allowedLanguages.filter(l => l !==
SupportedLanguage.RPC) or check allowedLanguages.some(l => l !==
SupportedLanguage.RPC) and require sdkLanguages.length > 0) before returning the
SdkToggle; update the condition around pseudoCodeMode/hasRpc and ensure any
downstream code that expects sdkLanguages uses the new filtered list to avoid an
empty panel when switching to "View SDK syntax".

---

Outside diff comments:
In `@src/components/Docs/SnippetViewer/CheckRequestViewer.tsx`:
- Around line 257-279: The pseudocode renderer in CheckRequestViewer.tsx
currently omits opts.headers, causing examples relying on custom headers to
render incomplete RPC blocks; update the string template that returns the
check(...) snippet (the block that uses user, relation, object,
contextualTuples, context, and Reply: ${allowed}) to include a headers section
when opts.headers exists—format it similarly to the context block (map
Object.entries(opts.headers) into key = "value" or "Key: Value" lines) so
headers are rendered into the pseudocode by default when
pseudoCodeMode/defaultOperationsViewer() selects this view.

---

Nitpick comments:
In `@src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx`:
- Around line 16-21: The BatchCheckRequestViewerOpts type duplicates common
viewer options (skipSetup, pseudoCodeMode) — change its declaration to extend
the shared DefaultTabbedViewerOpts so these shared fields are inherited; update
the interface name BatchCheckRequestViewerOpts to `extends
DefaultTabbedViewerOpts` and remove the duplicated skipSetup and pseudoCodeMode
properties, keeping unique fields like authorizationModelId, checks, and
allowedLanguages as-is.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f4309895-2253-4680-938d-0e21567d52d8

📥 Commits

Reviewing files that changed from the base of the PR and between 671d560 and 6c1f654.

📒 Files selected for processing (7)
  • docs/content/modeling/agents/agents-as-principals.mdx
  • src/components/Docs/SnippetViewer/BatchCheckRequestViewer.tsx
  • src/components/Docs/SnippetViewer/CheckRequestViewer.tsx
  • src/components/Docs/SnippetViewer/DefaultTabbedViewer.tsx
  • src/components/Docs/SnippetViewer/ListObjectsRequestViewer.tsx
  • src/components/Docs/SnippetViewer/ListUsersRequestViewer.tsx
  • src/components/Docs/SnippetViewer/WriteRequestViewer.tsx

Comment thread src/components/Docs/SnippetViewer/DefaultTabbedViewer.tsx
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/components/Docs/SnippetViewer/DefaultTabbedViewer.tsx Outdated
Comment thread src/components/Docs/SnippetViewer/DefaultTabbedViewer.tsx Outdated
Comment thread src/components/Docs/SnippetViewer/DefaultTabbedViewer.tsx Outdated
Comment thread src/components/Docs/SnippetViewer/WriteRequestViewer.tsx
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +14 to +29
function SdkToggle<T extends DefaultTabbedViewerOpts>({
allowedLanguages,
opts,
tabViewFn,
langMappings,
}: {
allowedLanguages: SupportedLanguage[];
opts: T;
tabViewFn: (lang: SupportedLanguage, opts: T, langMappings: LanguageMappings) => string;
langMappings: LanguageMappings;
}): JSX.Element {
const [showSdk, setShowSdk] = useState(false);

const sdkLanguages = allowedLanguages.filter((language) => language !== SupportedLanguage.RPC);
const toggleLabel = showSdk ? 'View pseudocode' : 'View code';

Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

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

SdkToggle, sdkLanguages, and showSdk are named as if the toggle only switches SDK languages, but the implementation includes all non-RPC languages (e.g., CLI/curl) by filtering only SupportedLanguage.RPC. Consider renaming to reflect the actual behavior (e.g., CodeToggle, codeLanguages, showCode) or tighten the filter to SDK languages if that’s the intent.

Copilot uses AI. Check for mistakes.
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