Skip to content

feat: Create Snaps API documentation from generated schema#2702

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

feat: Create Snaps API documentation from generated schema#2702
Mrtenz wants to merge 34 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
Adds a build-time docs generation step that fetches a remote schema and writes MDX files, which can break builds/CI or produce inconsistent docs if the schema changes or is unavailable.

Overview
Snaps API reference is now generated from a schema instead of maintained manually. A new Docusaurus plugin (plugin-snaps-docs) adds a snaps:generate CLI command that fetches the Snaps JSON-RPC schema and writes one MDX page per method under snaps/reference/snaps-api/, rendered via a new SnapsAPIReference component suite (description/parameters/returns/examples/tags) using react-markdown.

The docs navigation and content are updated to match the new structure: the old monolithic snaps/reference/snaps-api.md (and wallet-api-for-snaps.md) are removed, the Snaps sidebar now nests a Snaps API reference section, and many docs links are rewritten to point at the new generated per-method routes.

Build/CI now runs generation automatically (start/build prepend docusaurus snaps:generate, and the CI linkCheck job installs deps and generates the reference before link checking); generated files are added to .gitignore.

Written by Cursor Bugbot for commit ebe6f62. 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 Mar 10, 2026 8:33am

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.09910010083100

View full report

@bgravenorst
Copy link
Contributor

Should there be an await?
Just asking because our existing examples often use it for snap.request

Screenshot 2026-03-06 at 3 35 25 pm

@bgravenorst
Copy link
Contributor

The ToC on the right is incorrect. It's not showing Returns and Examples.

Screenshot 2026-03-06 at 3 54 16 pm

@bgravenorst
Copy link
Contributor

General feedback:

  • No examples for snap_closeWebSocket, snap_getPreferences, and a few others
  • snap_dialog is hard to understand. The description introduces a bullet list (which is actually the parameters section). Also due to the formatting it's hard to follow what's happening in the Parameters section.
  • Some examples have manifests, others don't
  • snap_getLocale should this have a deprecated label?
  • snap_scheduleBackgroundEvent, the “Common properties” section is confusing here because request isn’t an optional shared add-on, it’s a required top-level field in both union variants (I assume). so it would be clearer to document the parameter object once and state that exactly one of date or duration must be provided, along with the required request object.
  • snap_sendWebSocketMessage Options is missing some text

@Mrtenz
Copy link
Member Author

Mrtenz commented Mar 6, 2026

The ToC on the right is incorrect. It's not showing Returns and Examples.

Screenshot 2026-03-06 at 3 54 16 pm

@bgravenorst Do you have a good way to resolve this? It seems that Docusaurus isn't picking up the conditionally rendered headings. 😕

@Mrtenz
Copy link
Member Author

Mrtenz commented Mar 6, 2026

@bgravenorst

  • snap_dialog is hard to understand. The description introduces a bullet list (which is actually the parameters section). Also due to the formatting it's hard to follow what's happening in the Parameters section.

Agreed, I added the list description temporarily until we figure out a better way to show this. Can look into this as a follow-up if that's alright?

  • Some examples have manifests, others don't

Only examples where additional permissions are needed have a manifest.

  • snap_getLocale should this have a deprecated label?

Intended to remove this from the docs, but didn't push the change to the schema yet. It will be removed soon.

  • snap_scheduleBackgroundEvent, the “Common properties” section is confusing here because request isn’t an optional shared add-on, it’s a required top-level field in both union variants (I assume). so it would be clearer to document the parameter object once and state that exactly one of date or duration must be provided, along with the required request object.

In this case I actually feel like it's pretty clear that request must be provided to one of the options? Do you have an example of what you were thinking?

  • snap_sendWebSocketMessage Options is missing some text

This is a limitation in the schema generation script, will add some extra explanation to the message description for the time being, but can try and find a better solution in a follow-up.

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.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

:::

- [`wallet_snap`](/snaps/reference/wallet-api-for-snaps/#wallet_snap) - Gaining permission requires
- [`wallet_snap`](/snaps/reference/snaps-api/wallet_snap) - Gaining permission requires
Copy link
Contributor

Choose a reason for hiding this comment

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

Working fine with local build of this (drops me into new reference page) but the vercel build here is throwing me elsewhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

This links me to the right place in the Vercel build?

### `getInterface`

If your Snap uses [`snap_dialog`](snaps-api.md#snap_dialog) to show user interfaces, you can use the
If your Snap uses [`snap_dialog`](snaps-api/snap_dialog.mdx) to show user interfaces, you can use the
Copy link
Contributor

Choose a reason for hiding this comment

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

many links from this on are absolute instead of relative

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure what you mean? These links are relative.

Copy link
Contributor

@m4sterbunny m4sterbunny Mar 10, 2026

Choose a reason for hiding this comment

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

[link](absolute/link)

vs
[link](./relative/sibling-link)
or
[link](../relative/one-level-up-link)

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.

3 participants