Closed christopherraa closed 3 years ago
Here is an example that demonstrates the issue:
#!/usr/bin/env perl
use Mojo::Base -strict;
use Test::More;
use Test::Mojo;
use Mojolicious::Lite;
post '/echo' => sub {
my $c = shift->openapi->valid_input or return;
$c->render(text => $c->req->body);
}, 'echo';
plugin('OpenAPI' => {url => "data:///spec.json"});
my $t = Test::Mojo->new;
$t->post_ok('/v1/echo' => 'Echo echo!')->status_is(200)->content_is('Echo echo!');
done_testing();
__DATA__
@@ spec.json
{
"swagger": "2.0",
"info": {
"version": "0.0.1",
"title": "Echo API"
},
"basePath": "/v1",
"paths": {
"/echo": {
"post": {
"summary": "Echo the thing",
"description": "This endpoint echos the thing",
"operationId": "echo",
"x-mojo-name": "echo",
"consumes": [
"text/plain"
],
"parameters": [
{
"name": "echodata",
"in": "body",
"description": "Payload that should be echoed",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"$ref": "#/responses/response200_ok"
}
}
}
}
},
"responses": {
"response200_ok": {
"description": "Successful response",
"schema": {
"type": "string"
}
}
}
}
This used to work just fine and is according to my reading of the swagger docs perfectly valid. If running with these versions the above tests succeed:
I have not checked at which point the breakage was introduced.
Update: Tested running the tests for every version of JSON::Validator
from 4.13 to 4.20. All succeed. Assuming the problem is in M::P::OpenAPI
. Will do some testing there as well.
Verified now that it breaks in Mojolicious::Plugin::OpenAPI@4.00
. So at least we know when the bug was introduced.
That was a rather bad regression 😞 It should be fixed in 4.05.
Given a route that looks something like this:
should it not be expected that one could send arbitrary text data in the body of a request and have that go through to the controller method? Currently this is rendered to the client when calling
$c->openapi->valid_input
:According to documentation on swagger.io:
Based on that I have concluded that naming should not be an issue here.
I know that the above structure used to work, as the reason we discovered this issue was by running our test suite against the newest version of everything. Tested now using:
Is this currently expected behaviour?