fix: Send empty value sends empty string instead of omitting empty array params#10869
Open
mixelburg wants to merge 1 commit into
Open
fix: Send empty value sends empty string instead of omitting empty array params#10869mixelburg wants to merge 1 commit into
mixelburg wants to merge 1 commit into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a
multipart/form-datarequest 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
arraytype.Reported in #10785.
Root Cause
In
src/core/plugins/spec/actions.js, theexecuteRequestfilter logic was usingrequestBodyInclusionSetting.get(key)to override the empty check for all value types. When the "send empty value" flag was checked:[]) passed through the filterformatKeyValueconverted[]to an empty string via.join(",")-F 'files='(empty string)Fix
Updated the filter logic to handle arrays and nil values correctly:
null/undefined): only included when the "send empty" flag is set AND the value is not nil (prevents sending empty strings for nil values)Testing
multipart/form-dataendpoint with anarray<string>parameter-F 'files='