redoc icon indicating copy to clipboard operation
redoc copied to clipboard

Default value for array query parameter with explode:true (default) and 2+ items is rendered incorrectly (regression from #1806 fix)

Open sboisse opened this issue 3 months ago • 4 comments

Describe the bug

When a query parameter is an array with a default containing 2 or more items, and the parameter uses the default OpenAPI serialization (style: form, explode: true — i.e. no style/explode fields set at all, which is the spec default for query params), the rendered "Default:" value is mangled. It shows the first item concatenated with a dangling &paramName= fragment instead of a clean list.

Expected behavior

The "Default:" field should show something like ["Cat", "Dog"] or Cat, Dog — matching how example values for the same shape are displayed.

Minimal reproducible OpenAPI snippet(if possible)

paths:
  /species:
    get:
      parameters:
        - name: animals
          in: query
          required: false
          schema:
            type: array
            items:
              type: string
              enum: ["Cat", "Dog", "Bird", "Fish", "Elephant"]
            default: ["Cat", "Dog"]
          description: Animal species.
      responses:
        "200":
          description: OK

Screenshots

Image

Root cause

In src/components/Fields/FieldDetails.tsx:

const defaultValue =
  isObject(schema.default) && field.in
    ? getSerializedValue(field, schema.default).replace(`${field.name}=`, '')
    : schema.default;
  • isObject() (from src/utils/helpers.ts) is typeof item === 'object', which is true for arrays, so any array-type parameter default takes this branch.
  • getSerializedValue → serializeParameterValue → serializeQueryParameter serializes the default using the parameter's style/explode the same way it would appear on the wire. For the default explode: true, a 2-item array serializes to report_types=EFT&report_types=Credit Card (two report_types= occurrences).
  • .replace(${field.name}=, '') is a plain string replace, which only removes the first occurrence, not all of them (.replaceAll would be needed). This leaves the second &report_types= fragment in the displayed value.

This is a regression introduced by the fix for #1806 (PR #2186). That fix's own repro used explode: false with a comma-joined default, which serializes to a single name=val1,val2,val3 string (only one occurrence of name=), so the single-occurrence .replace() happened to fully strip it in that case. It was never tested against the explode: true + 2-or-more-items case, which is actually the more common case since it's the OpenAPI default for query array parameters (no explicit style/explode needed to trigger it).

Suggested fix

Replace the single-occurrence .replace(...) with .replaceAll(...), or better, avoid stripping via string manipulation entirely and instead render the parsed array default directly (e.g. join with the same separator/format used for example arrays) rather than round-tripping through wire-serialization + string-stripping.

Environment

  • ReDoc version: latest (redoc@latest via jsdelivr) — bug also present on main branch
  • OpenAPI version: 3.0 / 3.1 (style/explode defaults are shared across both)

sboisse avatar Aug 25 '26 02:08 sboisse

Still reproduces on the Redoc interactive demo (redocly.github.io/redoc, current release, 2026-08-30, Chromium 151):

  1. Open https://redocly.github.io/redoc/ and upload a minimal OpenAPI 3.0 spec. The trigger is a query parameter that is type: array with default: ["Cat", "Dog"] and no explicit style or explode — so the OpenAPI default (style: form, explode: true) applies.
  2. Navigate to the endpoint. The animals parameter shows Default: "Cat&animals=Dog" instead of ["Cat", "Dog"].
  3. Changing to a one-item default (default: ["Cat"]) renders correctly — only one animals= occurrence to strip.

The single .replace("animals=", "") in FieldDetails.tsx leaves the second &animals= from the explode: true wire serialization intact. A .replaceAll() would fix the two-item case, though rendering the parsed array directly (rather than round-tripping through wire serialization) avoids the problem entirely.

23-second recording: https://scenerecap.com/s/iqzt3braku

scenerecap avatar Aug 30 '26 17:08 scenerecap

Hi @sboisse, thank you for letting us know about the issue.

We are currently working on a new version of Redoc 3. It works as you expected on https://redocly.github.io/redoc/3.x.

Image

It will be fixed in the next major release Redoc 3.0

AlexVarchuk avatar Sep 15 '26 13:09 AlexVarchuk

@sboisse Hi, We've just shipped Redoc v3.0.0. And it should work as expected in new version

AlexVarchuk avatar Oct 14 '26 12:10 AlexVarchuk

Thanks @AlexVarchuk for the heads up, much appreciated!

sboisse avatar Oct 15 '26 19:10 sboisse