Fix: API Try It double-slash URLs (complete) + render body fields for incomplete specs#2956
Merged
surishubham merged 3 commits intoMay 18, 2026
Conversation
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>
6 tasks
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two related fixes for the API Reference Try It experience:
schema.properties— defensive fallback that uses the spec'sexampleblock to derive fields, unblocking 19 endpointsFix 1 — Trailing-slash double-slash (3 files, 10 sites)
Why #2951 wasn't enough
PR #2951 patched 2 sites (
buildCurland the send-request URL inTryItModal.js). But users were still seeing//in:Sites covered in this PR
TryItModal.jsbuildCurl,selectedServerinitial state, useEffect sync, send-request URL, dropdown<option>valuesEndpointDetail.jsselectedBaseinitial state, useEffect sync,copyUrl, dropdown<option>valueslangUtils.jsgenerateCodeExample(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-api.lambdatest.com/)auth.lambdatest.com/)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:Our
extractRequestBodyonly readsschema.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 ANDbodyContent.example(orschema.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
required: falseand blank description (spec doesn't carry this whenpropertiesis omitted)propertiesblocks to the upstream OpenAPI specsVerified working
PUT /api/v1/folder(Update Folder By ID) — body fields render, URL clean, real 200 response with correct payloadPUT /api/v1/projects(Update Project By ID) — body fields render//anywhere (URL bar, dropdown, copy, code examples, modal, sent request)Test plan
npm startboots, prebuild regenerates API data//in URL bar, dropdown, code examples, Try It modalnpm run buildcompletes successfullyNote 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