Redocly / Redocly/redoc

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

Open Beginner friendly
#2,833 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Type: Bug
Dominant language
TypeScript
Stars
25.9k
Forks
2.4k
Avg merge
13h 10m
Merged PRs (30d)
4

Description

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.
  • getSerializedValueserializeParameterValueserializeQueryParameter 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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/components/Fields/FieldDetails.tsx and trace getSerializedValue through src/utils/helpers.ts and query serialization; reproduce the OpenAPI array default with implicit form/explode behavior. Add regression coverage for a two-item default and verify the rendered Default value contains both items without a dangling parameter-name fragment.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.