Skip to content

TE-17800: Body example + variants for Try It modal (testmuCom)#3118

Open
srivastavaayush1611LT wants to merge 5 commits into
LambdaTest:testmuComfrom
srivastavaayush1611LT:cherry-pick/te-17800-body-variants-testmucom
Open

TE-17800: Body example + variants for Try It modal (testmuCom)#3118
srivastavaayush1611LT wants to merge 5 commits into
LambdaTest:testmuComfrom
srivastavaayush1611LT:cherry-pick/te-17800-body-variants-testmucom

Conversation

@srivastavaayush1611LT

Copy link
Copy Markdown
Contributor

Summary

Cherry-pick of PR #3115 and PR #3117 to testmuCom branch.

Changes

From PR #3115:

  • Surface spec body examples in Try It modal
  • Flatten single-item array bodies into per-field form inputs
  • Fix parent_folder_idparent_id for Test Manager folder endpoints (TE-17800)

From PR #3117:

  • PUT /api/v1/folder: render Rename / Move as Body tabs
  • Variant tabs on static API reference page
  • Stack variants vertically instead of tabs on static pages

Commits cherry-picked

  1. 93210820 - TE-17800: surface spec body example + flatten single-item array bodies
  2. 80a6b84c - Address review: coerce flattened inner values, fix two comments, mark PUT override
  3. ba504115 - PUT /api/v1/folder: render Rename / Move as Body tabs
  4. 298b7101 - Variant tabs on the static API reference page
  5. 80c5a880 - Static page: stack variants vertically instead of tabs

Test plan

  • PUT /api/v1/folder Try It modal shows Rename/Move tabs
  • Switching tabs updates body fields correctly
  • Static page shows variants stacked vertically

🤖 Generated with Claude Code

srivastavaayush1611LT and others added 5 commits June 16, 2026 20:03
Three layered fixes for Try It body rendering, all driven by the
`requestBody.example` block that already exists in the upstream specs:

1. **Carry spec example through the build.** `extractRequestBody` now
   attaches `example` alongside `properties` so downstream code can use the
   author's intended payload. ~18 example-only endpoints (most of Test
   Manager, Analytics, parts of User Management) previously rendered hollow
   bodies (e.g. `"folders": []`) and now show the populated example.

2. **Apply local overrides for known-wrong upstream examples.** Adds a
   `REQUEST_BODY_EXAMPLE_OVERRIDES` map keyed by `<spec>|<method>|<path>`.
   Currently fixes the TE-17800 case: upstream YAML uses `parent_folder_id`
   for Test Manager POST/PUT `/api/v1/folder` but the real API expects
   `parent_id`. Override flips the key and matches the value. Marked with
   `// TE-17800` for easy removal once the upstream YAML is corrected.

3. **Flatten single-item array bodies into per-field form inputs.** New
   `detectFlattenedArrayBody` helper recognises bodies shaped like
   `{ wrapper: [ { ...primitive fields } ] }` (POST `/api/v1/folder`).
   When matched, the Body section renders one input per inner field
   prefilled with the example, and buildCurl/handleSend/langUtils wrap
   the typed inputs back into the array shape. Other bodies retain
   existing rendering. Multipart endpoints explicitly gated off.

Also: language tabs (Python/JS/PHP/Go/Java/Ruby) and the live Send
request go through the same assembly so cURL, code snippets, and the
real fetch all agree on the body shape.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… PUT override

- Apply coerceBodyValue in all three flattened-body assembly sites
  (langUtils generateCodeExample, TryItModal buildCurl, TryItModal handleSend)
  so integer/boolean/number inner fields aren't sent as strings. No behavior
  change for POST /api/v1/folder (all inner fields are string), but unblocks
  future flattened endpoints with non-string inner types.

- Reword detectFlattenedArrayBody comment to match the predicate: rejection
  is for arrays/non-null objects only; null values pass through as string.

- Rename "Untyped fields" -> "Empty inputs" in two TryItModal comments;
  the predicate is `if (!raw)`, not a type check.

- Add `// TE-17800:` marker to the PUT folder override so a future cleanup
  sweep that greps for the ticket catches both override entries.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The endpoint serves two operations distinguished by an `action` field:
- Rename (action="update"): id, action, entity_id, name
- Move   (action="move"):   id, action, entity_id, entity_type, name, parent_id, serial_no

The upstream YAML ships a single example matching neither real payload.
Until upstream is fixed, override the example via a new variants registry
and render one tab per variant in the Try It modal.

Build script:
- Add REQUEST_BODY_VARIANTS_OVERRIDES map keyed by spec|method|path.
  Each entry returns [{name, example}, ...]. Extracted properties are
  inferred per-variant from the example.
- Factor inferFieldsFromExample helper out of the legacy example-fallback
  path so variants reuse the same inference.
- When variants are present, the first variant's example becomes the
  canonical top-level requestBody.example/properties — keeps the static
  CodeExamples panel (which doesn't know about variants) showing a
  sensible default instead of the now-stale spec example.
- Drop the prior example override for PUT folder (now superseded by
  variants). POST folder retains its example override unchanged.

Modal:
- Add selectedVariantIdx state and an effectiveEndpoint useMemo that
  swaps in the selected variant's example + properties. Downstream
  helpers (buildCurl, handleSend, generateCodeExample) stay
  variant-agnostic — they just see an endpoint with the chosen body.
- Render a tab strip above the Body section when variants exist.
- Reset and re-prefill body params on tab switch (path/query/auth
  params are preserved).

POST /api/v1/folder behavior unchanged.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Hoist selectedVariantIdx to _ApiDocPage so the Body section (EndpointDetail)
and the code panel (CodeExamples) stay in sync — clicking a tab in the Body
section swaps the cURL/Python/JS snippet on the right.

- _ApiDocPage: add selectedVariantIdx state + reset effect on endpoint nav.
- EndpointDetail: accept selectedVariantIdx + onVariantChange; render tab
  strip above the body fields when requestBody.variants exists; key ParamRow
  on `${variantIdx}-${i}` so React rebuilds rows on tab switch.
- CodeExamples: accept selectedVariantIdx; shim an effectiveEndpoint with
  the active variant's example + properties before calling
  generateCodeExample.
- TryItModal: accept initialVariantIdx so the modal opens on whichever
  variant the user was reading on the static page.

PUT /api/v1/folder now shows the Rename/Move tab strip on the static page,
and clicking Try It carries the current tab into the modal.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Per feedback, the static API reference page renders one Body section
and one code panel per variant, stacked one below the other. The Try It
modal keeps its tab UI (interactive surface; tabs are the right call
there).

- EndpointDetail: when requestBody.variants exists, render N stacked
  Body sections titled "<endpoint name> (<variant name>)" — e.g.
  "Update Folder By ID (Rename)" and "Update Folder By ID (Move)".
- CodeExamples: render N stacked code panels, one per variant, sharing
  the language selector (lives in the first panel's header). Each panel
  has its own copy button. Extracted CodePanel inline subcomponent.
- TryItModal: remove the unused initialVariantIdx prop; the modal
  manages its own variant state.
- _ApiDocPage: drop the lifted selectedVariantIdx state, the reset
  effect, and the variant props passed to children — no longer needed.

POST /api/v1/folder and all non-variant endpoints behave unchanged.

Co-Authored-By: Claude Opus 4.7 <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.

1 participant