Fix: API Try It double-slash URLs (complete) + render body fields for incomplete specs [testmuCom]#2958
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>
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
Port of #2956 (currently open against
stage) to thetestmuCombranch. Identical 4-file, +44/-18 change set — three cherry-picked commits, no behavioral divergence.Two related fixes for the API Reference Try It experience:
schema.properties— defensive fallback that uses the spec'sexampleblock to derive fields, unblocking 19 endpointsselectedBase, leading-slash normalization on endpoint paths, and a build-time warning when properties are derived fromexampleFix 1 — Trailing-slash double-slash (3 files, 10 sites)
Three OpenAPI specs (Test Manager, User Management, Audit Logs) declare server URLs ending with
/. Concatenating withendpoint.path(which starts with/) produced//api/v1/..., surfacing as 404s / "Failed to fetch" / CORS errors in the browser.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 (
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: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.
Fix: in
scripts/build-api-data.js, when properties come up 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).required: falseand blank description (spec doesn't carry this whenpropertiesis omitted)propertiesblocks to the upstream OpenAPI specsFix 3 — Hardening / defensive guards
No behavior change for current data; all three are defense-in-depth.
scripts/build-api-data.js(extractRequestBodyfallback): emitconsole.warnnaming the spec / method / path when fields are derived fromexamplerather thanschema.properties. Makes spec defects discoverable in the build log.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 producehttps://host.comv1/foo. None of the current 220 endpoints hit this case — purely defensive against future spec drift.src/component/ApiReference/EndpointDetail.js(selectedBase): use(effectiveServers[0]?.url || '').replace(...)matching the defensive pattern already used inTryItModal.js. Pre-fixuseState(effectiveServers[0].url)silently accepted undefined; post-fix.replace()would throwTypeErroron the same edge case.Verified working (from #2956)
PUT /api/v1/folderandPUT /api/v1/projects— body fields render, URL clean, real 200 response//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 successfullyRelated
stage: Fix: API Try It double-slash URLs (complete) + render body fields for incomplete specs #2956🤖 Generated with Claude Code