Skip to content

feat: add server variable input for API Explorer via custom JS#258

Open
fern-api[bot] wants to merge 10 commits intomainfrom
fern/server-variable-input
Open

feat: add server variable input for API Explorer via custom JS#258
fern-api[bot] wants to merge 10 commits intomainfrom
fern/server-variable-input

Conversation

@fern-api
Copy link
Copy Markdown

@fern-api fern-api bot commented Apr 2, 2026

What

Adds a vanilla JS script that injects a dedicated Space name input field into the API Explorer ("Try It") panel for endpoints that use OpenAPI server variables.

Why

Addresses the server variable discoverability issue described in fern-api/fern#14493. Currently, users must double-click the base URL to edit server variables — this is not discoverable and leads to confusion.

How it works

  1. A MutationObserver watches for .playground-endpoint-baseurl elements in the API Explorer panel.
  2. When a URL with a known placeholder (e.g. {Your_Space_Name}, YOUR_SPACE) is detected, a labeled input field is injected into the explorer form.
  3. As the user types their space name:
    • The script writes the resolved URL to Fern's Jotai atomWithStorage localStorage keys (selected-environment-url and per-API variants)
    • Dispatches synthetic StorageEvents so React re-renders the URL bar and code samples
    • A computed URL preview is shown below the input
    • The value persists across page reloads via localStorage
  4. Works for both REST API (https://{space_name}.signalwire.com) and Compatibility API (https://{space_name}.signalwire.com/api/laml/2010-04-01) endpoints.

Changes

v2 (6c32ca2)

  • Fixed duplicate injection — uses document.getElementById() check instead of data attribute, preventing multiple sections from appearing
  • Fixed URL not updating — replaced unreliable double-click-to-edit approach with direct localStorage writes to Fern's Jotai atomWithStorage keys + synthetic StorageEvent dispatch, which updates both the URL bar and code samples
  • Debounced MutationObserver to avoid rapid re-processing
  • Idempotent CSS injection via element ID check

v1 (74cdc76)

  • Initial implementation with MutationObserver + DOM injection

Files changed

  • fern/server-variable-input.js — Custom JS script (434 lines)
  • fern/docs.yml — Added js: section to load the script with afterInteractive strategy

Related

Requested by: Fern Support

@fern-api
Copy link
Copy Markdown
Author

fern-api bot commented Apr 2, 2026

Requested by: Devon White
Slack thread: View conversation

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

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.

0 participants