Skip to content

Fix: API Try It double-slash URLs (complete) + render body fields for incomplete specs#2956

Merged
surishubham merged 3 commits into
LambdaTest:stagefrom
srivastavaayush1611LT:fix/api-tryit-double-slash-complete
May 18, 2026
Merged

Fix: API Try It double-slash URLs (complete) + render body fields for incomplete specs#2956
surishubham merged 3 commits into
LambdaTest:stagefrom
srivastavaayush1611LT:fix/api-tryit-double-slash-complete

Conversation

@srivastavaayush1611LT
Copy link
Copy Markdown

Summary

Two related fixes for the API Reference Try It experience:

  1. Complete the trailing-slash fix started by Fix: API Try It double-slash URL causing 404 errors #2951 — covers all 10 URL-construction sites, not just the 2 in the original PR
  2. Render body fields when OpenAPI spec omits schema.properties — defensive fallback that uses the spec's example block to derive fields, unblocking 19 endpoints

Fix 1 — Trailing-slash double-slash (3 files, 10 sites)

Why #2951 wasn't enough

PR #2951 patched 2 sites (buildCurl and the send-request URL in TryItModal.js). But users were still seeing // in:

  • The URL bar at the top of every API doc page
  • The dropdown options (US/EU server picker)
  • The Copy URL button output
  • The Code Examples panel (cURL, JavaScript, Python, Node, Ruby, Go snippets)
  • The URL preview inside the Try It modal

Sites covered in this PR

File Sites
TryItModal.js 5: buildCurl, selectedServer initial state, useEffect sync, send-request URL, dropdown <option> values
EndpointDetail.js 4: selectedBase initial state, useEffect sync, copyUrl, dropdown <option> values
langUtils.js 1: generateCodeExample (covers all language snippets)

Approach

Strip trailing slash at two layers — at the source (state + <option> values) so the URL bar displays cleanly, and again at concatenation sites as defense in depth. .replace(/\/+$/, '') is a no-op when no trailing slash exists, so APIs without the defect are unaffected.

Affected APIs

  • Test Manager (test-manager-api.lambdatest.com/)
  • User Management (auth.lambdatest.com/)
  • Audit logs (audit-logs.lambdatest.com/)

Fix 2 — Render body fields for properties-less request bodies (1 file)

The problem

Several OpenAPI specs (e.g. PUT /api/v1/projects, PUT /api/v1/folder) define request bodies as:

requestBody:
  content:
    application/json:
      schema:
        type: object       # no properties defined
      example:
        id: 'folder_id'
        name: ...
        description: ...
        parent_folder_id: 'parent_folder_id'

Our extractRequestBody only reads schema.properties, so the Try It modal rendered zero body fields for these endpoints — users couldn't construct a valid request body and got 400 errors.

Impact: 19 endpoints affected across Test Manager, User Management, and App Automation.

The fix

In scripts/build-api-data.js, after extracting properties, if the result is empty AND bodyContent.example (or schema.example) is a plain object, derive a property list from the example's keys. Type inferred from value shape (string / number / integer / boolean / array / object).

Behavior

  • ✅ Only triggers when properties are missing — no regression on well-defined specs
  • ✅ All 19 affected endpoints now render editable inputs
  • ⚠️ Inferred fields have required: false and blank description (spec doesn't carry this when properties is omitted)
  • The proper long-term fix is for backend teams to add properties blocks to the upstream OpenAPI specs

Verified working

  • ✅ Test Manager PUT /api/v1/folder (Update Folder By ID) — body fields render, URL clean, real 200 response with correct payload
  • ✅ Test Manager PUT /api/v1/projects (Update Project By ID) — body fields render
  • ✅ All affected APIs no longer show // anywhere (URL bar, dropdown, copy, code examples, modal, sent request)
  • ✅ APIs without trailing slashes (Selenium, Build, HyperExecute) — unchanged, no regression

Test plan

  • Dev: npm start boots, prebuild regenerates API data
  • Visit any Test Manager / User Management / Audit Logs endpoint — verify no // in URL bar, dropdown, code examples, Try It modal
  • Open Update Folder By ID and Update Project By ID — verify body fields are rendered (id, name, description, etc.)
  • Send a real request with valid credentials — should reach the server (200/4xx based on payload), not 404
  • Regression: open a Selenium or Build API endpoint — URL/fields unchanged from current production
  • npm run build completes successfully

Note on PR #2951

This PR supersedes #2951 — the 2 sites fixed there are included here plus the other 8. #2951 can be closed in favor of this one.

🤖 Generated with Claude Code

srivastavaayush1611LT and others added 2 commits May 18, 2026 18:37
Three OpenAPI specs (Test Manager, User Management, Audit Logs) declare
server URLs ending with `/`. Concatenating with `endpoint.path` (which
starts with `/`) produced `//api/v1/...`, returning 404 and surfacing in
browsers as "Failed to fetch"/CORS errors.

PR LambdaTest#2951 patched 2 sites in TryItModal.js. This commit covers the
remaining surfaces so every URL shown to the user — visual, copied,
or sent — is clean:

TryItModal.js (5 sites):
- buildCurl URL concatenation
- selectedServer initial state
- selectedServer useEffect sync on endpoint change
- send-request URL
- server dropdown <option> values

EndpointDetail.js (4 sites):
- selectedBase initial state
- selectedBase useEffect sync on endpoint change
- copyUrl clipboard URL
- server dropdown <option> values

langUtils.js (1 site):
- generateCodeExample URL (used by all language snippets:
  cURL/JavaScript/Python/Node/Ruby/Go)

Approach: strip trailing slash at two layers — at the source (state +
<option> values) so the URL bar displays cleanly, and again at
concatenation sites as defense in depth. Uses .replace(/\/+$/, '')
which is a no-op when no trailing slash exists, so APIs without the
defect are unaffected.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Several OpenAPI specs (test_management PUT /api/v1/projects,
PUT /api/v1/folder, etc.) declare request bodies as `type: object`
with only an `example` block — no `properties` definition. Our
extractor only read `schema.properties`, so the Try It modal rendered
zero body fields for these endpoints, blocking users from constructing
a valid request body.

19 endpoints across Test Manager, User Management, and App Automation
were affected.

This adds a defensive fallback in extractRequestBody: when properties
come up empty AND bodyContent.example (or schema.example) is a plain
object, derive a property list from the example's keys with types
inferred from value shape (string / number / integer / boolean /
array / object).

Behavior:
- Only triggers when properties are missing — no regression on
  well-defined specs.
- Inferred fields have `required: false` and blank description (the
  spec doesn't carry this metadata when properties are omitted).
- The proper long-term fix is to add `properties` blocks to the
  affected OpenAPI specs upstream, but this unblocks users today.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Addresses review feedback on PR LambdaTest#2956 — no behavior change for current
data, all three are defense-in-depth guards.

1. scripts/build-api-data.js (extractRequestBody fallback):
   - Emit console.warn naming the spec / method / path when fields are
     derived from `example` rather than `schema.properties`. Makes spec
     defects discoverable in the build log instead of silently shipping
     best-effort types/required/descriptions to the Try It modal.
   - Drop the rot-prone endpoint citation from the fallback comment.

2. scripts/build-api-data.js (flattenSpec):
   - Normalize endpoint paths to always start with `/`. Pre-PR, a
     trailing slash on the base URL silently compensated for a missing
     leading slash on the path; post-PR (slash stripped from base) a
     malformed spec would produce `https://host.comv1/foo`. None of
     the current 220 endpoints hit this case — guard is purely
     defensive against future spec drift.

3. src/component/ApiReference/EndpointDetail.js (selectedBase):
   - Use `(effectiveServers[0]?.url || '').replace(...)` matching the
     defensive pattern already used in TryItModal.js (lines 295/323).
     Pre-PR `useState(effectiveServers[0].url)` silently accepted
     undefined; post-PR `.replace()` would throw TypeError on the same
     edge case. None of the current 12 APIs hit this — guard is
     purely defensive.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@surishubham surishubham merged commit d1ae091 into LambdaTest:stage May 18, 2026
1 check failed
surishubham pushed a commit that referenced this pull request May 18, 2026
Addresses review feedback on PR #2956 — no behavior change for current
data, all three are defense-in-depth guards.

1. scripts/build-api-data.js (extractRequestBody fallback):
   - Emit console.warn naming the spec / method / path when fields are
     derived from `example` rather than `schema.properties`. Makes spec
     defects discoverable in the build log instead of silently shipping
     best-effort types/required/descriptions to the Try It modal.
   - Drop the rot-prone endpoint citation from the fallback comment.

2. scripts/build-api-data.js (flattenSpec):
   - Normalize endpoint paths to always start with `/`. Pre-PR, a
     trailing slash on the base URL silently compensated for a missing
     leading slash on the path; post-PR (slash stripped from base) a
     malformed spec would produce `https://host.comv1/foo`. None of
     the current 220 endpoints hit this case — guard is purely
     defensive against future spec drift.

3. src/component/ApiReference/EndpointDetail.js (selectedBase):
   - Use `(effectiveServers[0]?.url || '').replace(...)` matching the
     defensive pattern already used in TryItModal.js (lines 295/323).
     Pre-PR `useState(effectiveServers[0].url)` silently accepted
     undefined; post-PR `.replace()` would throw TypeError on the same
     edge case. None of the current 12 APIs hit this — guard is
     purely defensive.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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