Closed plk closed 4 years ago
I'm not super happy with https://github.com/jhthorsen/mojolicious-plugin-openapi/commit/b7e0113a96290e9ee1d015329978b0d25f12d387#diff-9a6a9327b16cdf365665485886135c77R286. Will hopefully make a better rewrite after #160.
Hi, I'm still facing an issue with multipart/form-data file parameter validation (required).
I've created a testcase to reproduce it based on a test file from the Plugin repo (t/v3-file.t
), see below.
In short, schema expects parameter in form data named image
, which is missed, and I'm expected to get error response, like message => 'Missing property.', path => '/body/image'
Please let me know if I should open a new issue
.
use Mojo::Base -strict;
use Test::Mojo;
use Test::More;
use Mojolicious::Lite;
post '/upload' => sub {
my $c = shift->openapi->valid_input or return;
$c->render(openapi => {size => $c->req->upload('image')->size});
},
'upload';
plugin OpenAPI => {url => 'data://main/openapi.yaml'};
my $t = Test::Mojo->new;
my $image = Mojo::Asset::Memory->new->add_chunk('smileyface');
$t->post_ok('/api/upload', form => {imageParam => {file => $image}})->status_is(400)
->json_is('/errors/0', {message => 'Missing property.', path => '/body/image'});
$t->post_ok(
'/api/upload',
{Accept => 'application/json'},
form => {id => 1, image => {file => $image}}
)->content_like(qr{"size"})->status_is(200);
done_testing;
__DATA__
@@ openapi.yaml
---
openapi: 3.0.0
info:
title: Upload test
version: 1.0.0
servers:
- url: http://example.com/api
paths:
/upload:
post:
operationId: upload
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
required: [ image ]
properties:
image:
type: string
format: binary
responses:
200:
description: Accepted
content:
application/json:
schema:
required: [ size ]
properties:
size:
type: integer
Mojolicious::Plugin::OpenAPI - 5.09
I have a spec with a standard multipart/form body for a file upload:
In V2, this was:
The same client call:
works fine with the V2 spec but fails in
valid_input
with the V3 spec:I see the file asset in the request on the server:
Is this an issue withe validation in the plugin or am I missing something here?