Default value for array query parameter with explode:true (default) and 2+ items is rendered incorrectly (regression from #1806 fix)
Nobody has claimed this yet.
- 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 ¶mName= 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
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()(fromsrc/utils/helpers.ts) istypeof item === 'object', which istruefor arrays, so any array-type parameter default takes this branch.getSerializedValue→serializeParameterValue→serializeQueryParameterserializes the default using the parameter'sstyle/explodethe same way it would appear on the wire. For the defaultexplode: true, a 2-item array serializes toreport_types=EFT&report_types=Credit Card(tworeport_types=occurrences)..replace(${field.name}=, '')is a plain string replace, which only removes the first occurrence, not all of them (.replaceAllwould 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@latestvia jsdelivr) — bug also present onmainbranch - OpenAPI version: 3.0 / 3.1 (style/explode defaults are shared across both)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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