Skip to content

Accept a file object for array-form type with format: binary - #228

Open
takayamaki wants to merge 4 commits into
ota42y:masterfrom
takayamaki:binary-format-in-type-array
Open

takayamaki wants to merge 4 commits into
ota42y:masterfrom
takayamaki:binary-format-in-type-array

Conversation

@takayamaki

Copy link
Copy Markdown
Contributor

Part of #215 (item 7).

When coerce_value is off, type: [string, "null"] with format: binary rejected an uploaded file object.
A single type: string with format: binary accepts it.

file:
  type: [string, "null"]
  format: binary

For an array-form type, the validator picks the type from the class of the value.
A file object matches none of the listed types, so it fell into the type-mismatch error.
A single type: string goes to the string validator, which skips the check when format is binary.

Changes

  • When the value is not a String, format is binary and string is listed in the array-form type, the validator now uses the string validator.
    The result is the same as a single type: string.
  • Other cases do not change.
    type: [integer, "null"] with format: binary still rejects a file object.
    With coerce_value on, the array form already passed, and it still does.

I did not change how a file object is detected.
The string validator still accepts any non-String value for format: binary, as before.

When coerce_value is off, type: ["string", "null"] with format: binary rejected an uploaded file object.
pick_array_type found no matching type, so the value fell into the type-mismatch validator.
A single type: string reaches the binary branch of the string validator and passes.
Now the array form falls back to string when format is binary and string is listed.
@takayamaki takayamaki closed this Oct 27, 2026
@takayamaki takayamaki reopened this Oct 27, 2026
@takayamaki
takayamaki marked this pull request as ready for review October 27, 2026 15:12
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