Skip to content

feat: Create Snaps API documentation from generated schema#2702

Open
Mrtenz wants to merge 21 commits intomainfrom
mrtenz/dynamic-snaps-docs
Open

feat: Create Snaps API documentation from generated schema#2702
Mrtenz wants to merge 21 commits intomainfrom
mrtenz/dynamic-snaps-docs

Conversation

@Mrtenz
Copy link
Member

@Mrtenz Mrtenz commented Feb 12, 2026

Description

This adds a Docusaurus plugin for dynamically generating Snaps API documentation from a schema file. The schema file will be generated automatically based on the implementations in MetaMask/snaps. This allows for easier maintenance of the documentation, as some methods have become quite outdated currently.

The plugin works by fetching the schema file, and writing a new MDX file to disk for each JSON-RPC method. I've considered a similar approach to the Wallet API documentation, but it had several drawbacks, like needing to hack the sidebar to show the dynamic items. By generating the MDX files before running Docusaurus, @docusaurus/plugin-content-docs will just pick it up as any other documentation page.

Related to: https://consensyssoftware.atlassian.net/browse/WPC-347 and https://consensyssoftware.atlassian.net/browse/WPC-442.

Preview

Checklist

  • If this PR updates or adds documentation content that changes or adds technical meaning, it has received an approval from an engineer or DevRel from the relevant team.
  • If this PR updates or adds documentation content, it has received an approval from a technical writer.

External contributor checklist

  • I've read the contribution guidelines.
  • I've created a new issue (or assigned myself to an existing issue) describing what this PR addresses.

Note

Medium Risk
Introduces a build-time fetch-and-generate step for docs pages (network dependency and generated content shape), which can break builds/link checks if the schema or generation output changes unexpectedly.

Overview
Adds a custom Docusaurus plugin (plugin-snaps-docs) and snaps:generate CLI command that fetches the Snaps JSON-RPC schema and generates per-method snaps/reference/snaps-api/*.mdx pages rendered via a new SnapsAPIReference component (including markdown descriptions, parameter/return type rendering, examples, and tags).

Reworks Snaps docs navigation and links to point at the new generated reference structure (new snaps/reference/snaps-api/index.md, updated snaps-sidebar.js, and widespread link updates), and removes the old monolithic snaps/reference/snaps-api.md page.

Integrates generation into local and CI workflows by running docusaurus snaps:generate during npm start/build and before link checking, adds react-markdown dependency, and ignores generated MDX outputs in .gitignore.

Written by Cursor Bugbot for commit 92e71cd. This will update automatically on new commits. Configure here.

@vercel
Copy link

vercel bot commented Feb 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
metamask-docs Ready Ready Preview, Comment Feb 25, 2026 2:11pm

Request Review

@socket-security
Copy link

socket-security bot commented Feb 12, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedreact-markdown@​10.1.09910010084100

View full report

import { LoadContext, Plugin } from '@docusaurus/types'

// TODO: Update to `latest`.
export const SNAPS_RPC_URL = 'https://metamask.github.io/snaps/schema/staging/schema.json'
Copy link
Member Author

Choose a reason for hiding this comment

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

Need to change this before merging.

import { LoadContext, Plugin } from '@docusaurus/types'

// TODO: Update to `latest`.
export const SNAPS_RPC_URL = 'https://metamask.github.io/snaps/schema/staging/schema.json'
Copy link

Choose a reason for hiding this comment

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

Staging schema URL used in production code

High Severity

SNAPS_RPC_URL points to a staging endpoint (staging/schema.json) rather than a production/latest endpoint. The accompanying TODO comment confirms this is temporary. If merged as-is, all generated Snaps API documentation will be sourced from the staging schema, which may contain incomplete, experimental, or unstable data — and the endpoint could be removed or changed without notice.

Fix in Cursor Fix in Web


{Array.isArray(props.method.examples) ?
props.method.examples.map((example, index) => (
<Example key={index} index={index + 1} example={example} only={props.method.examples.length === 1} />
Copy link

Choose a reason for hiding this comment

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

Prop name mismatch prevents example titles from displaying

Medium Severity

The Examples component passes an only prop to Example, but the Example component reads props.showTitle to decide whether to render the <h3> title. Since showTitle is never provided, example titles are never rendered. The only prop is unused.

Additional Locations (1)

Fix in Cursor Fix in Web

`

await writeFile(filePath, content)
}
Copy link

Choose a reason for hiding this comment

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

Missing cleanup of stale generated docs before regeneration

Medium Severity

generateSnapsDocs writes new .mdx files into snaps/reference/snaps-api/ but never clears existing files from previous runs. If a method is renamed or removed from the schema between runs, the old .mdx file persists on disk. Docusaurus then picks up both stale and current files, resulting in phantom documentation pages for methods that no longer exist in the schema. Clearing the output directory before writing would prevent this.

Fix in Cursor Fix in Web

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

</TabItem>
))}
</Tabs>
: <CodeBlock language={props.example.examples[0].language}>{props.example.examples[0].content}</CodeBlock>
Copy link

Choose a reason for hiding this comment

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

Accessing index zero of potentially empty array crashes

Low Severity

If an example group from the schema has an empty examples array (length 0), the condition on line 7 (examples.length > 1) is false, causing the else branch on line 15 to evaluate props.example.examples[0].language. Since [0] on an empty array is undefined, this throws a TypeError and crashes the page. No guard ensures the inner examples array is non-empty before accessing its first element.

Fix in Cursor Fix in Web

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.

1 participant