Skip to content

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

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

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

Conversation

@srivastavaayush1611LT
Copy link
Copy Markdown

Summary

Port of #2956 (currently open against stage) to the testmuCom branch. Identical 4-file, +44/-18 change set — three cherry-picked commits, no behavioral divergence.

Two related fixes for the API Reference Try It experience:

  1. Trailing-slash double-slash fix — covers all 10 URL-construction sites across 3 files
  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
  3. Hardening — defensive guards on selectedBase, leading-slash normalization on endpoint paths, and a build-time warning when properties are derived from example

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

Three OpenAPI specs (Test Manager, User Management, Audit Logs) declare server URLs ending with /. Concatenating with endpoint.path (which starts with /) produced //api/v1/..., surfacing as 404s / "Failed to fetch" / CORS errors in the browser.

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)

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

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.

Fix: in scripts/build-api-data.js, when properties come up 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).

  • Only triggers when properties are missing — no regression on well-defined specs
  • Inferred fields have required: false and blank description (spec doesn't carry this when properties is omitted)
  • Long-term fix is for backend teams to add properties blocks to the upstream OpenAPI specs

Fix 3 — Hardening / defensive guards

No behavior change for current data; all three are defense-in-depth.

  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.
  2. scripts/build-api-data.js (flattenSpec): normalize endpoint paths to always start with /. Pre-fix, a trailing slash on the base URL silently compensated for a missing leading slash on the path; post-fix a malformed spec would produce https://host.comv1/foo. None of the current 220 endpoints hit this case — 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. Pre-fix useState(effectiveServers[0].url) silently accepted undefined; post-fix .replace() would throw TypeError on the same edge case.

Verified working (from #2956)

  • Test Manager PUT /api/v1/folder and PUT /api/v1/projects — body fields render, URL clean, real 200 response
  • 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

Related

🤖 Generated with Claude Code

srivastavaayush1611LT and others added 3 commits May 18, 2026 19:44
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 2dcdd89 into LambdaTest:testmuCom May 18, 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.

2 participants