jhthorsen / mojolicious-plugin-openapi

OpenAPI / Swagger plugin for Mojolicious
54 stars 44 forks source link

Confusing error message during schema loading #90

Closed elcamlost closed 6 years ago

elcamlost commented 6 years ago

Example full mojolicious app. Saved to app.pl file

#!/usr/bin/env perl

package App;
use Mojo::Base 'Mojolicious', -signatures;

sub startup ($self) {
    $self->plugin(OpenAPI => {
        url => $self->home->rel_file('spec.json'),
    });
}

package main;
use strict;
use warnings;
use Mojolicious::Commands;
Mojolicious::Commands->start_app('App');

1;

Running app like this

JSON_VALIDATOR_DEBUG=1 PERL5LIB=local/lib/perl5 perl -Ilib local/bin/morbo app.pl
Server available at http://127.0.0.1:3000
[JSON::Validator] Loading schema from file: /Users/camlost/devel/mojolicious-plugin-openapi/spec.json
[JSON::Validator] Using root_schema_url of '/Users/camlost/devel/mojolicious-plugin-openapi/spec.json'
[JSON::Validator] Loading schema from file: /Users/camlost/devel/definitions/weight.json
[JSON::Validator] Loading schema from URL /Users/camlost/devel/definitions/unit.json
Can't load application from file "/Users/camlost/devel/mojolicious-plugin-openapi/app.pl": Can't call method "server" on an undefined value at local/lib/perl5/Mojo/Server/Daemon.pm line 55.

Problem here that file definitions/unit.json doesn't exists. But without JSON_VALIDATOR_DEBUG env variable error is very confusing - Can't call method "server" on an undefined value at local/lib/perl5/Mojo/Server/Daemon.pm line 55

Is it ok? Shouild it be fixed? And if yes, where to fix it? Here or in JSON::Validator module?

jhthorsen commented 6 years ago

Hey, thanks for reporting in!

I've fixed this in JSON::Validator now: https://github.com/jhthorsen/json-validator/commit/f58f54fab14fc3e5bfe5d8cafbc185ea7263ab13

You can try it out with

cpanm https://github.com/jhthorsen/json-validator/archive/master.tar.gz

Let me know what you think.

elcamlost commented 6 years ago

Yeah, now error directly gives the proper message. Thanks!

jhthorsen commented 6 years ago

Awesome! I'll make a new release later today 👍