Closed Ovid closed 2 years ago
Note that I have a basePath: /api
in the spec, even though my test calls /echo
.
Changing that to /api/echo
in the test gets me:
t/basic.t .. [2022-03-12 15:00:12.65159] [10099] [trace] [Txd4wWPlecBL] POST "/api/echo"
[2022-03-12 15:00:12.65195] [10099] [trace] [Txd4wWPlecBL] Template "echo.html.ep" not found
[2022-03-12 15:00:12.65244] [10099] [error] [Txd4wWPlecBL] Route without action and nothing to render at /Users/ovid/perl5/perlbrew/perls/perl-5.26.3/lib/site_perl/5.26.3/Mojolicious.pm line 125.
[2022-03-12 15:00:12.65269] [10099] [trace] [Txd4wWPlecBL] 500 Internal Server Error (0.001104s, 905.797/s)
I've also tried changing my main class:
# $r->post('/echo')->to('echo#echo');
$r->post('/api/echo')->to('echo#echo');
But I get the same error (but since I have a basePath:
, it wasn't actually necessary to do that in the Lite app). There seems to be very little documentation about using this plugin with a full Mojo app.
If I remove the basePath: /api
from the config, I get the "Route without action" error.
This is incorrect:
$self->app->openapi->valid_input
it should be:
$self->openapi->valid_input
The helper can’t be called on the app, since you can load the plugin multiple times, allowing each route work on a different spec and a different validator instance.
@jhthorsen: Thank you for that explanation. It's very clear.
Unfortunately, I get the same error with $self->openapi->valid_input
.
When I look at your code closer I find more issues, but it boils down to the helpers not being called inside an OpenAPI powered action.
The SYNOPSIS is too simple and it has created so much confusion for users that I consider getting rid of it. Please read one of the following (or both) documents instead:
Just to give you some pointers: (They are documented in the guides above)
Feel free to hang around in #perl-openapi and I'll try to guide you if you have further questions after reading the guides, but because of the timezone I might not be available right away.
I tried to make it a bit more clear in the documentation now that you should read the guides: https://metacpan.org/release/JHTHORSEN/Mojolicious-Plugin-OpenAPI-5.04/view/lib/Mojolicious/Plugin/OpenAPI.pm#SYNOPSIS
I'm trying to take the Mojolicious:Lite 'echo' example from the docs and play around with turning that into a well-structured mojo app, but I'm getting the following error:
I've stripped out all other code to reduce this to a minimal use case.
My main class:
My controller class:
My OpenAPI spec:
And the test that is generating the error:
That test worked fine when I was using a Lite app. I've searched like mad all through the docs and even tests to figure out what I'm doing wrong, but to no avail. Help?