Skip to content

fix: Send empty value sends empty string instead of omitting empty array params#10869

Open
mixelburg wants to merge 1 commit into
swagger-api:masterfrom
mixelburg:fix/send-empty-value-array-param
Open

fix: Send empty value sends empty string instead of omitting empty array params#10869
mixelburg wants to merge 1 commit into
swagger-api:masterfrom
mixelburg:fix/send-empty-value-array-param

Conversation

@mixelburg
Copy link
Copy Markdown

Problem

When a multipart/form-data request has an array parameter (e.g., files: array<string>) with no items and the user checks the "Send empty value" checkbox, Swagger UI sends -F 'files=' (an empty string) instead of either omitting the field or sending an empty array.

This causes servers to respond with 422 Unprocessable Entity because an empty string is not a valid value for the expected array type.

Reported in #10785.

Root Cause

In src/core/plugins/spec/actions.js, the executeRequest filter logic was using requestBodyInclusionSetting.get(key) to override the empty check for all value types. When the "send empty value" flag was checked:

  1. Empty arrays ([]) passed through the filter
  2. swagger-client's formatKeyValue converted [] to an empty string via .join(",")
  3. The request was sent with -F 'files=' (empty string)

Fix

Updated the filter logic to handle arrays and nil values correctly:

  • Empty arrays: always excluded (never serialized as empty strings)
  • Nil values (null/undefined): only included when the "send empty" flag is set AND the value is not nil (prevents sending empty strings for nil values)
  • Empty strings: still properly handled by the inclusion flag

Testing

  1. Define a multipart/form-data endpoint with an array<string> parameter
  2. Open "Try it out" — do NOT add any items
  3. Check "Send empty value"
  4. Click Execute
  5. Verify the curl output does not contain -F 'files='

…value' is checked

When a multipart/form-data request has an array parameter with no items
and the user checks 'Send empty value', the empty array was being
serialized as an empty string () instead of being omitted.

The root cause was in the requestBody filter logic: the
requestBodyInclusionSetting flag was overriding the empty check for all
value types, including arrays and nil values. Empty arrays (empty
Immutable Lists) were converted to , then swagger-client's
formatKeyValue converted  to an empty string via .

The fix ensures:
- Empty arrays are always excluded (never serialized as empty strings)
- Nil values (null/undefined) are only included when the 'send empty'
  flag is set AND the value is not null/undefined
- Empty strings and other non-nil empty values are still properly
  handled by the inclusion flag

Fixes swagger-api#10785
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