Skip to content

Add data payload validation option#247

Open
jeff-matthews wants to merge 13 commits intomainfrom
fetch-json-component
Open

Add data payload validation option#247
jeff-matthews wants to merge 13 commits intomainfrom
fetch-json-component

Conversation

@jeff-matthews
Copy link
Copy Markdown
Contributor

@jeff-matthews jeff-matthews commented Mar 30, 2026

Purpose

This pull request (PR) adds a new section to the OpenGraph schema docs that describes an option for validating data payloads against the JSON schema stored in the chow repo. We want to host a new JSON file on the docs site that references the schema so that we have a more favorable URL that developers can use to configure their editors.

In the interest of consolidating schema reference, we're also adding a custom React component to fetch JSON data from a raw GitHub URLs instead of hardcoding corresponding examples in the docs. This will reduce maintenance overhead, which currently requires updating examples in multiple places instead of one.

Note

The current implementation fetches data from the main branch in the chow repo, but it might be better to point to a commit SHA instead to avoid unexpected changes.

Staging

https://specterops-fetch-json-component.mintlify.app/opengraph/developer/schema

Summary by CodeRabbit

  • New Features

    • Added a live JSON code block that fetches and displays schema/examples from GitHub with a source link option and loading/error states.
  • Documentation

    • Replaced embedded OpenGraph schema examples with dynamically loaded references from GitHub.
    • Added a "Data Payload Validation" section with guidance for schema validation and editor setup.
    • Introduced a small referenced payload schema to point to the canonical external schema.

@jeff-matthews jeff-matthews self-assigned this Mar 30, 2026
@jeff-matthews jeff-matthews added the opengraph Docs related to OpenGraph extension use and development label Mar 30, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f8550364-364e-4956-879c-428c770d03d5

📥 Commits

Reviewing files that changed from the base of the PR and between f9f4a39 and 22fad09.

📒 Files selected for processing (1)
  • docs/opengraph/developer/schema.mdx
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/opengraph/developer/schema.mdx

Walkthrough

Deleted local OpenGraph JSON schema files, added a React component that fetches and displays JSON from GitHub, and updated docs to reference external schemas and include a Data Payload Validation section.

Changes

Cohort / File(s) Summary
Local Schema Deletions
docs/assets/opengraph/opengraph-edge.json, docs/assets/opengraph/opengraph-node.json
Removed inline JSON Schema files for OpenGraph edge and node payloads.
GitHub JSON Codeblock Component
docs/snippets/opengraph/github-json-codeblock.jsx
Added GitHubJsonCodeblock React component that fetches JSON from sourceUrl, handles loading, errors, aborts, formats JSON for a CodeBlock, and optionally renders a source link.
Docs & Schema Reference
docs/opengraph/developer/schema.mdx, docs/assets/opengraph/payload-schema.json
Replaced inline schema/examples with <GitHubJsonCodeblock> usages, added Data Payload Validation guidance and editor allow-list examples, and added payload-schema.json referencing an external GitHub-hosted schema.

Sequence Diagram(s)

sequenceDiagram
    participant Reader as Docs Page (Browser)
    participant Component as GitHubJsonCodeblock
    participant GitHub as raw.githubusercontent.com
    participant Renderer as CodeBlock

    Reader->>Component: Render with `sourceUrl`
    Component->>GitHub: fetch(sourceUrl)
    GitHub-->>Component: JSON response / error
    Component->>Renderer: render formatted JSON or error/loading text
    Component-->>Reader: display CodeBlock (and optional source link)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through docs and fields so wide,
Pulled JSON from GitHub like a tide,
No more local schema stacks,
A fetching rabbit got your backs,
Snug CodeBlock crumbs left by my stride. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add data payload validation option' accurately describes the main change: introducing a new data payload validation section and component to enable JSON schema validation for OpenGraph payloads.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fetch-json-component

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.

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: 3

🧹 Nitpick comments (4)
docs/snippets/opengraph/github-json-codeblock.jsx (3)

19-25: Consider adding a timeout to the fetch request.

The fetch has no timeout, which could cause the component to stay in loading state indefinitely if the GitHub raw URL is slow or unresponsive. While AbortController handles component unmount, it doesn't protect against slow requests while mounted.

💡 Proposed timeout implementation
     try {
+      const timeoutId = setTimeout(() => abortController.abort(), 10000);
       const response = await fetch(sourceUrl, {
         signal: abortController.signal,
         headers: {
           Accept: 'application/json, text/plain;q=0.9,*/*;q=0.8',
         },
       });
+      clearTimeout(timeoutId);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/snippets/opengraph/github-json-codeblock.jsx` around lines 19 - 25, Add
a request timeout around the fetch of sourceUrl by starting a timer (e.g.,
TIMEOUT_MS constant) that calls abortController.abort() after the timeout, clear
that timer immediately when fetch resolves or rejects, and also clear it on
component unmount; update the fetch logic where abortController.signal is passed
so the request is aborted both on unmount and when the timeout elapses, and
ensure any timeout-related errors are handled the same as AbortError in the
existing error handling.

82-91: Source link renders raw.githubusercontent.com URL.

When showSourceLink is enabled, users see and can click a link to raw.githubusercontent.com. This may be intentional, but typically you'd want to link to the GitHub blob view (e.g., github.com/SpecterOps/chow/blob/main/...) for a better user experience. The current raw URL downloads the file directly rather than showing it in GitHub's UI.

💡 Transform raw URL to GitHub blob URL for better UX
+  const getGitHubBlobUrl = (rawUrl) => {
+    if (!rawUrl) return rawUrl;
+    // Transform raw.githubusercontent.com/owner/repo/refs/heads/branch/path
+    // to github.com/owner/repo/blob/branch/path
+    return rawUrl
+      .replace('raw.githubusercontent.com', 'github.com')
+      .replace('/refs/heads/', '/blob/');
+  };
+
   return (
     <>
       {showSourceLink && sourceUrl && (
         <p>
-          Source: <a href={sourceUrl}>{fileName}</a>
+          Source: <a href={getGitHubBlobUrl(sourceUrl)}>{fileName}</a>
         </p>
       )}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/snippets/opengraph/github-json-codeblock.jsx` around lines 82 - 91, The
source link currently renders the raw.githubusercontent.com URL (sourceUrl)
which causes direct download; update the rendering logic that checks
showSourceLink and sourceUrl to transform the raw URL into the GitHub blob view
URL before using it (e.g., convert raw.githubusercontent.com/.../path to
github.com/{owner}/{repo}/blob/{branch}/... or replace the raw host and adjust
the path), then pass that transformed URL into the <a href={...}>{fileName}</a>
output (keep using fileName and renderCode as-is). Ensure the transformation
handles typical raw URL patterns and falls back to sourceUrl unchanged if it
cannot be parsed.

1-9: Add a comment clarifying that React hooks and CodeBlock are provided by Mintlify globally.

The component omits imports for useState, useEffect, useMemo, and CodeBlock, which is intentional for Mintlify snippets (as indicated by the existing comment on line 1). Consider adding a brief clarification comment explaining that these are provided by Mintlify's global scope to help future maintainers understand the pattern and avoid confusion.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/snippets/opengraph/github-json-codeblock.jsx` around lines 1 - 9, Add a
short clarifying comment at the top of the GitHubJsonCodeblock snippet (near the
existing "Must use arrow function syntax in Mintlify snippets" note) stating
that React hooks (useState, useEffect, useMemo) and the CodeBlock component are
available from Mintlify's global scope and intentionally omitted from imports;
reference the GitHubJsonCodeblock component name and the hook/component names
(useState, useEffect, useMemo, CodeBlock) so future maintainers know this is
deliberate.
docs/assets/opengraph/schema.json (1)

1-3: Consider pinning to a commit SHA or tag instead of main branch.

The $ref points to refs/heads/main, meaning the schema can change unexpectedly when the upstream repository is updated. This could cause documentation examples to become invalid or user validation to break if the schema changes incompatibly. Pointing to a specific commit SHA or release tag would provide better stability.

💡 Example with commit SHA (replace with actual SHA)
 {
-  "$ref": "https://raw.githubusercontent.com/SpecterOps/chow/refs/heads/main/pkg/validator/jsonschema/opengraph.json"
+  "$ref": "https://raw.githubusercontent.com/SpecterOps/chow/<COMMIT_SHA>/pkg/validator/jsonschema/opengraph.json"
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/assets/opengraph/schema.json` around lines 1 - 3, The $ref currently
points to the upstream repo using refs/heads/main which allows the schema to
change unexpectedly; update the "$ref" value in the JSON (the existing "$ref":
"https://raw.githubusercontent.com/SpecterOps/chow/refs/heads/main/pkg/validator/jsonschema/opengraph.json")
to reference a stable identifier—replace refs/heads/main with a specific commit
SHA or a release tag (e.g., refs/heads/<commit-sha> or tags/vX.Y.Z) so the
schema URL is deterministic and won't change with upstream branch updates.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/opengraph/developer/schema.mdx`:
- Around line 104-107: Remove the unused "language" prop from all
GitHubJsonCodeblock usages in this file: locate each JSX/MDX component instance
named GitHubJsonCodeblock (examples around the shown diff and the other
occurrences noted) and delete the language="json" attribute so only supported
props remain; do not change the component implementation itself, just remove the
extraneous language prop from each GitHubJsonCodeblock instance.
- Around line 67-72: Fix the duplicated phrase "that's hosted that's hosted" in
the sentence and clarify the allowlist guidance: replace the sentence with a
corrected version (remove the duplicate) and explicitly state that users should
allowlist the full schema URL
(https://bloodhound.specterops.io/assets/opengraph/schema.json) and, if their
editor requires directory-level access, the raw GitHub directory base URL
(https://raw.githubusercontent.com/SpecterOps/chow/refs/heads/main/pkg/validator/jsonschema/);
update the surrounding text to make clear which exact strings to add to editor
configuration and that one is a single schema file and the other is a repository
directory.

In `@docs/snippets/opengraph/github-json-codeblock.jsx`:
- Around line 2-6: The component GitHubJsonCodeblock currently ignores a
passed-in language prop; update the component signature to accept a language
prop (e.g., language = 'json') and replace the hardcoded language used in
renderCode with that variable so the success render path uses the provided
language; locate the renderCode call in the success branch (around the existing
line ~89) and swap the hardcoded 'json'/'text' argument for the new language
prop, leaving existing defaults and showSourceLink behavior intact.

---

Nitpick comments:
In `@docs/assets/opengraph/schema.json`:
- Around line 1-3: The $ref currently points to the upstream repo using
refs/heads/main which allows the schema to change unexpectedly; update the
"$ref" value in the JSON (the existing "$ref":
"https://raw.githubusercontent.com/SpecterOps/chow/refs/heads/main/pkg/validator/jsonschema/opengraph.json")
to reference a stable identifier—replace refs/heads/main with a specific commit
SHA or a release tag (e.g., refs/heads/<commit-sha> or tags/vX.Y.Z) so the
schema URL is deterministic and won't change with upstream branch updates.

In `@docs/snippets/opengraph/github-json-codeblock.jsx`:
- Around line 19-25: Add a request timeout around the fetch of sourceUrl by
starting a timer (e.g., TIMEOUT_MS constant) that calls abortController.abort()
after the timeout, clear that timer immediately when fetch resolves or rejects,
and also clear it on component unmount; update the fetch logic where
abortController.signal is passed so the request is aborted both on unmount and
when the timeout elapses, and ensure any timeout-related errors are handled the
same as AbortError in the existing error handling.
- Around line 82-91: The source link currently renders the
raw.githubusercontent.com URL (sourceUrl) which causes direct download; update
the rendering logic that checks showSourceLink and sourceUrl to transform the
raw URL into the GitHub blob view URL before using it (e.g., convert
raw.githubusercontent.com/.../path to
github.com/{owner}/{repo}/blob/{branch}/... or replace the raw host and adjust
the path), then pass that transformed URL into the <a href={...}>{fileName}</a>
output (keep using fileName and renderCode as-is). Ensure the transformation
handles typical raw URL patterns and falls back to sourceUrl unchanged if it
cannot be parsed.
- Around line 1-9: Add a short clarifying comment at the top of the
GitHubJsonCodeblock snippet (near the existing "Must use arrow function syntax
in Mintlify snippets" note) stating that React hooks (useState, useEffect,
useMemo) and the CodeBlock component are available from Mintlify's global scope
and intentionally omitted from imports; reference the GitHubJsonCodeblock
component name and the hook/component names (useState, useEffect, useMemo,
CodeBlock) so future maintainers know this is deliberate.
🪄 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: 0d5dec28-4871-48a3-a599-28e926edd12b

📥 Commits

Reviewing files that changed from the base of the PR and between 2de77f9 and 13a57c7.

📒 Files selected for processing (5)
  • docs/assets/opengraph/opengraph-edge.json
  • docs/assets/opengraph/opengraph-node.json
  • docs/assets/opengraph/schema.json
  • docs/opengraph/developer/schema.mdx
  • docs/snippets/opengraph/github-json-codeblock.jsx
💤 Files with no reviewable changes (2)
  • docs/assets/opengraph/opengraph-edge.json
  • docs/assets/opengraph/opengraph-node.json

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.

🧹 Nitpick comments (1)
docs/opengraph/developer/schema.mdx (1)

71-72: Prefer immutable URLs over refs/heads/main for schema/example fetches.

Line 71 and Lines 105-106, 240-241, 341-342, 355-356 currently point to moving branch refs. This can cause docs output to change unexpectedly without a docs change. Pinning to commit SHAs will make rendering deterministic.

Suggested direction
-https://raw.githubusercontent.com/SpecterOps/chow/refs/heads/main/pkg/validator/jsonschema/
+https://raw.githubusercontent.com/SpecterOps/chow/<chow_commit_sha>/pkg/validator/jsonschema/

-sourceUrl="https://raw.githubusercontent.com/SpecterOps/chow/refs/heads/main/pkg/validator/jsonschema/node.json"
+sourceUrl="https://raw.githubusercontent.com/SpecterOps/chow/<chow_commit_sha>/pkg/validator/jsonschema/node.json"

-sourceUrl="https://raw.githubusercontent.com/SpecterOps/chow/refs/heads/main/pkg/validator/jsonschema/edge.json"
+sourceUrl="https://raw.githubusercontent.com/SpecterOps/chow/<chow_commit_sha>/pkg/validator/jsonschema/edge.json"

-sourceUrl="https://raw.githubusercontent.com/SpecterOps/chow/refs/heads/main/pkg/validator/jsonschema/metadata.json"
+sourceUrl="https://raw.githubusercontent.com/SpecterOps/chow/<chow_commit_sha>/pkg/validator/jsonschema/metadata.json"

-sourceUrl="https://raw.githubusercontent.com/SpecterOps/bloodhound-docs/refs/heads/main/docs/assets/opengraph/opengraph-minimal.json"
+sourceUrl="https://raw.githubusercontent.com/SpecterOps/bloodhound-docs/<docs_commit_sha>/docs/assets/opengraph/opengraph-minimal.json"

Also applies to: 105-106, 240-241, 341-342, 355-356

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/opengraph/developer/schema.mdx` around lines 71 - 72, Replace
branch-based raw.githubusercontent URLs that use "refs/heads/main" with
immutable permalinks pinned to a specific commit SHA; locate occurrences of the
string
"https://raw.githubusercontent.com/SpecterOps/chow/refs/heads/main/pkg/validator/jsonschema/"
(and the other similar refs/heads/main URLs in the file) and change them to the
equivalent raw.githubusercontent.com URL using the repository commit SHA (obtain
the SHA via git rev-parse or the GitHub UI and substitute it in place of
refs/heads/main) so all schema/example fetches in schema.mdx are deterministic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@docs/opengraph/developer/schema.mdx`:
- Around line 71-72: Replace branch-based raw.githubusercontent URLs that use
"refs/heads/main" with immutable permalinks pinned to a specific commit SHA;
locate occurrences of the string
"https://raw.githubusercontent.com/SpecterOps/chow/refs/heads/main/pkg/validator/jsonschema/"
(and the other similar refs/heads/main URLs in the file) and change them to the
equivalent raw.githubusercontent.com URL using the repository commit SHA (obtain
the SHA via git rev-parse or the GitHub UI and substitute it in place of
refs/heads/main) so all schema/example fetches in schema.mdx are deterministic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 190548c0-3b6e-4052-aac4-b8fa992982c7

📥 Commits

Reviewing files that changed from the base of the PR and between 13a57c7 and d49853b.

📒 Files selected for processing (1)
  • docs/opengraph/developer/schema.mdx

@jeff-matthews jeff-matthews requested a review from craigw-SO March 31, 2026 16:18
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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/opengraph/developer/schema.mdx`:
- Around line 69-72: The docs use mutable branch URLs (refs/heads/main) for the
schema and examples; replace those with immutable, commit-pinned URLs: update
the inline code block URL (the
https://raw.githubusercontent.com/.../refs/heads/main path) to use the specific
commit SHA, update every GitHubJsonCodeblock sourceUrl attribute to point to the
same commit-pinned raw URL, and change the $ref in the payload schema file to
the commit-pinned URL as well so all references (the inline code block, the
GitHubJsonCodeblock sourceUrl attributes, and the $ref in the payload schema)
reference the exact commit SHA instead of refs/heads/main.
🪄 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: 0ab9c50c-14b1-4b93-8d84-03c402a0a145

📥 Commits

Reviewing files that changed from the base of the PR and between d49853b and f9f4a39.

📒 Files selected for processing (2)
  • docs/assets/opengraph/payload-schema.json
  • docs/opengraph/developer/schema.mdx
✅ Files skipped from review due to trivial changes (1)
  • docs/assets/opengraph/payload-schema.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

opengraph Docs related to OpenGraph extension use and development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants