Skip to content

Commit

Permalink
Add EXPERIMETNAL support for coercing to array when posting form data
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Henning Thorsen committed Jan 6, 2022
1 parent 070fe28 commit 65b31df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Revision history for perl distribution JSON-Validator

5.05 Not Released
- Add EXPERIMETNAL support for coercing to array when posting form data

5.04 2021-12-10T07:54:09+0900
- Fix coercing strings and numbers in schema specification #266

Expand Down
5 changes: 4 additions & 1 deletion lib/JSON/Validator/Schema/OpenAPIv3.pm
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,10 @@ sub _validate_body {
return E "/$param->{name}", [qw(object required)];
}
if ($val->{exists}) {
local $self->{"validate_$direction"} = 1;
$val->{content_type} //= $param->{accepts}[0];
local $self->{coerce}{arrays} = 1
if $val->{content_type} =~ m!^(application/x-www-form-urlencoded|multipart/form-data)$!;
local $self->{"validate_$direction"} = 1;
my @errors = map { $_->path(_prefix_error_path($param->{name}, $_->path)); $_ }
$self->validate($val->{value}, $param->{content}{$val->{content_type}}{schema});
$val->{valid} = @errors ? 0 : 1;
Expand All @@ -304,6 +306,7 @@ sub _validate_id { }

sub _validate_type_array {
my $self = shift;
$_[0] = [$_[0]] if ref $_[0] ne 'ARRAY' and $self->{coerce}{arrays};
return $_[1]->{schema}{nullable} && !defined $_[0] ? () : $self->SUPER::_validate_type_array(@_);
}

Expand Down

0 comments on commit 65b31df

Please sign in to comment.