Skip to content

Fix SDK API reference parameter labels#2164

Merged
monadoid merged 1 commit into
mainfrom
codex/sdk-api-param-labels
May 27, 2026
Merged

Fix SDK API reference parameter labels#2164
monadoid merged 1 commit into
mainfrom
codex/sdk-api-param-labels

Conversation

@monadoid
Copy link
Copy Markdown
Contributor

@monadoid monadoid commented May 25, 2026

Summary

  • add a Mintlify custom script that rewrites generated SDK API reference schema labels from OpenAPI camelCase to SDK snake_case on Python and Ruby pages
  • keep code/pre/input/script/style content untouched so generated code samples stay language-correct
  • leave Java/Go/TypeScript routes unchanged for now

Why

Mintlify renders these language-scoped API reference pages from the Stainless documented OpenAPI spec, so visible schema labels use wire-format camelCase even when the Python and Ruby SDK snippets use snake_case.

Validation

  • pnpm --dir packages/docs exec prettier --check sdk-api-reference-labels.js
  • node --check packages/docs/sdk-api-reference-labels.js
  • confirmed Mintlify embeds root-level docs JS by checking the existing custom script in local/prod HTML and the new script in local HTML
  • browser fixture served at /v3/api-reference/{python,ruby,java}/...: Python/Ruby labels rewrote to snake_case, code blocks stayed camelCase, and Java remained unchanged

Summary by cubic

Fixes mismatched parameter labels on Python and Ruby SDK API reference pages by rewriting OpenAPI camelCase labels to SDK snake_case. Code samples and inputs remain unchanged; other languages are unaffected.

  • Bug Fixes
    • Added packages/docs/sdk-api-reference-labels.js to relabel visible schema fields for Python and Ruby only.
    • Skips code, pre, input, script, style, and editable elements to preserve language-correct snippets.
    • Reacts to SPA route changes and DOM mutations to keep labels consistent.
    • Leaves Java/Go/TypeScript pages unchanged.

Written for commit ea143a6. Summary will update on new commits. Review in cubic

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 25, 2026

⚠️ No Changeset found

Latest commit: ea143a6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@mintlify
Copy link
Copy Markdown
Contributor

mintlify Bot commented May 25, 2026

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
stagehand 🟢 Ready View Preview May 25, 2026, 4:17 PM

💡 Tip: Enable Workflows to automatically generate PRs for you.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file

Confidence score: 3/5

  • There is a concrete behavioral risk in packages/docs/sdk-api-reference-labels.js: per-mutation subtree debouncing can miss concurrently added subtrees, which may leave label rewriting inconsistent on the page.
  • Given the moderate severity (5/10) and high confidence (8/10), this is more than a cosmetic uncertainty and introduces a plausible regression in docs rendering behavior.
  • Pay close attention to packages/docs/sdk-api-reference-labels.js - debounce scheduling should cover coalesced mutations with a full-page rewrite to avoid missed rewrites.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/docs/sdk-api-reference-labels.js">

<violation number="1" location="packages/docs/sdk-api-reference-labels.js:187">
P2: Debouncing rewrites with a per-mutation subtree root can miss other concurrently added subtrees, causing inconsistent label rewriting. Schedule a full-page rewrite here so coalesced mutations are all covered.</violation>
</file>
Architecture diagram
sequenceDiagram
    participant Browser as Client Browser
    participant Mintlify as Mintlify Renderer
    participant Script as SDK Label Rewriter
    participant SPA as SPA Router
    participant DOM as DOM Tree

    Note over Browser,DOM: Page Load Flow

    Browser->>Mintlify: Request /v3/api-reference/{language}/...
    Mintlify->>Mintlify: Render OpenAPI spec (camelCase labels)
    Mintlify->>Browser: Return HTML with SDK code samples

    Note over Browser,DOM: SDK Label Rewriter Execution

    Browser->>Script: Load sdk-api-reference-labels.js
    Script->>Script: scheduleRewrite() on initial load
    Script->>DOM: Create TreeWalker to scan text nodes

    alt Python or Ruby path (e.g., /v3/api-reference/python/...)
        Script->>Script: currentSdkLanguage() returns "python" or "ruby"
        Script->>Script: Load SNAKE_CASE_PARAM_LABELS mapping
        Script->>DOM: Walk text nodes within content-area, api-section, field

        loop For each matching text node
            alt Node is inside code, pre, input, script, style, or editable element
                Script->>DOM: SKIP - preserve camelCase
            else Node is valid label text
                Script->>DOM: Replace camelCase → snake_case using RegExp
            end
        end
    else Java/Go/TypeScript path
        Script->>Script: currentSdkLanguage() returns unsupported language
        Script->>DOM: No rewrite - labels remain camelCase
    end

    Note over Browser,DOM: SPA Route Change Handling

    Browser->>SPA: User navigates to new API reference page
    SPA->>Script: pathname changes (polled every 250ms)
    Script->>Script: Detect path change via setInterval
    Script->>DOM: scheduleRewrite() with document.body

    Note over Browser,DOM: Dynamic DOM Updates

    DOM->>Script: Trigger MutationObserver on added nodes
    Script->>Script: scheduleRewrite() with new subtree
    Script->>DOM: Rewrite labels in newly added content only

    Note over Browser,DOM: Validation

    Browser->>Browser: Verify Python/Ruby labels display snake_case
    Browser->>Browser: Verify code blocks remain camelCase
    Browser->>Browser: Verify Java page labels unchanged
Loading

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

for (const mutation of mutations) {
for (const node of mutation.addedNodes) {
if (node.nodeType === Node.ELEMENT_NODE) {
scheduleRewrite(node);
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot May 26, 2026

Choose a reason for hiding this comment

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

P2: Debouncing rewrites with a per-mutation subtree root can miss other concurrently added subtrees, causing inconsistent label rewriting. Schedule a full-page rewrite here so coalesced mutations are all covered.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/docs/sdk-api-reference-labels.js, line 187:

<comment>Debouncing rewrites with a per-mutation subtree root can miss other concurrently added subtrees, causing inconsistent label rewriting. Schedule a full-page rewrite here so coalesced mutations are all covered.</comment>

<file context>
@@ -0,0 +1,202 @@
+    for (const mutation of mutations) {
+      for (const node of mutation.addedNodes) {
+        if (node.nodeType === Node.ELEMENT_NODE) {
+          scheduleRewrite(node);
+          return;
+        }
</file context>
Fix with Cubic

@monadoid monadoid merged commit 947e6e4 into main May 27, 2026
12 checks passed
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