jhthorsen / mojolicious-plugin-openapi

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

Valid OpenApi Spec v3 not accepted #192

Closed marcoarthur closed 4 years ago

marcoarthur commented 4 years ago

Running this script that use this spec

#!/usr/bin/env perl
use Mojolicious::Lite;

plugin OpenAPI => {
    url    => 'https://api.v2.emissions-api.org/openapi.json',
    schema => "v3",
};

app->start;

__DATA__
@@ index.html.ep
% layout 'default';
% title 'geo db';

Geo DB

I got this error trying to list the routes ( perl emissions.pl routes )


Invalid JSON specification https://api.v2.emissions-api.org/openapi.json
- /components/schemas/Averages/items/properties/end/type: /oneOf/0/oneOf/0/oneOf/0 Not in enum list: array, boolean, integer, number, object, string.
- /components/schemas/Averages/items/properties/end/$ref: /oneOf/0/oneOf/0/oneOf/1 Missing property.
- /components/schemas/Averages/items/properties/start/type: /oneOf/0/oneOf/0/oneOf/0 Not in enum list: array, boolean, integer, number, object, string.
- /components/schemas/Averages/items/properties/start/$ref: /oneOf/0/oneOf/0/oneOf/1 Missing property.
- /components/schemas/Averages/items/$ref: /oneOf/0/oneOf/1 Missing property.
- /components/schemas/Averages/$ref: /oneOf/1 Missing property.
- /components/schemas/DataRange/properties/first/type: /oneOf/0/oneOf/0 Not in enum list: array, boolean, integer, number, object, string.
- /components/schemas/DataRange/properties/first/$ref: /oneOf/0/oneOf/1 Missing property.
- /components/schemas/DataRange/properties/last/type: /oneOf/0/oneOf/0 Not in enum list: array, boolean, integer, number, object, string.
- /components/schemas/DataRange/properties/last/$ref: /oneOf/0/oneOf/1 Missing property.
- /components/schemas/DataRange/$ref: /oneOf/1 Missing property.
- /components/schemas/Statistics/items/properties/time/properties/interval_start/type: /oneOf/0/oneOf/0/oneOf/0/oneOf/0 Not in enum list: array, boolean, integer, number, object, string.
- /components/schemas/Statistics/items/properties/time/properties/interval_start/$ref: /oneOf/0/oneOf/0/oneOf/0/oneOf/1 Missing property.
- /components/schemas/Statistics/items/properties/time/properties/max/type: /oneOf/0/oneOf/0/oneOf/0/oneOf/0 Not in enum list: array, boolean, integer, number, object, string.
- /components/schemas/Statistics/items/properties/time/properties/max/$ref: /oneOf/0/oneOf/0/oneOf/0/oneOf/1 Missing property.
- /components/schemas/Statistics/items/properties/time/properties/min/type: /oneOf/0/oneOf/0/oneOf/0/oneOf/0 Not in enum list: array, boolean, integer, number, object, string.
- /components/schemas/Statistics/items/properties/time/properties/min/$ref: /oneOf/0/oneOf/0/oneOf/0/oneOf/1 Missing property.
- /components/schemas/Statistics/items/properties/time/$ref: /oneOf/0/oneOf/0/oneOf/1 Missing property.
- /components/schemas/Statistics/items/$ref: /oneOf/0/oneOf/1 Missing property.
- /components/schemas/Statistics/$ref: /oneOf/1 Missing property. at /home/itaipu/perl5/perlbrew/perls/perl-5.28.2/lib/site_perl/5.28.2/JSON/Validator.pm line 168.
    JSON::Validator::load_and_validate_schema(JSON::Validator::OpenAPI::Mojolicious=HASH(0x563d010b1258), "https://api.v2.emissions-api.org/openapi.json", HASH(0x563d013d9d78)) called at /home/itaipu/perl5/perlbrew/perls/perl-5.28.2/lib/site_perl/5.28.2/JSON/Validator/OpenAPI/Mojolicious.pm line 40
    JSON::Validator::OpenAPI::Mojolicious::load_and_validate_schema(JSON::Validator::OpenAPI::Mojolicious=HASH(0x563d010b1258), "https://api.v2.emissions-api.org/openapi.json", HASH(0x563d013d9d78)) called at /home/itaipu/perl5/perlbrew/perls/perl-5.28.2/lib/site_perl/5.28.2/Mojolicious/Plugin/OpenAPI.pm line 35
    Mojolicious::Plugin::OpenAPI::register(Mojolicious::Plugin::OpenAPI=HASH(0x563d03083dd0), Mojolicious::Lite=HASH(0x563d010bbdd0), HASH(0x563d01096328)) called at /home/itaipu/perl5/perlbrew/perls/perl-5.28.2/lib/site_perl/5.28.2/Mojolicious/Plugins.pm line 45
    Mojolicious::Plugins::register_plugin(Mojolicious::Plugins=HASH(0x563d010c8890), "OpenAPI", Mojolicious::Lite=HASH(0x563d010bbdd0), HASH(0x563d01096328)) called at /home/itaipu/perl5/perlbrew/perls/perl-5.28.2/lib/site_perl/5.28.2/Mojolicious.pm line 178
    Mojolicious::plugin(Mojolicious::Lite=HASH(0x563d010bbdd0), "OpenAPI", HASH(0x563d01096328)) called at /home/itaipu/perl5/perlbrew/perls/perl-5.28.2/lib/site_perl/5.28.2/Mojolicious/Lite.pm line 45
    main::plugin("OpenAPI", HASH(0x563d01096328)) called at emissions.pl line 4

The validator on https://validator.swagger.io/ says it is a correct Spec.

jhthorsen commented 4 years ago

I don't understand how that is a valid spec. I don't see "date-time" in the table here: https://swagger.io/specification/#data-types

Can you point me to where the spec says "type" can be "date-time"?

marcoarthur commented 4 years ago

Hi @jhthorsen ,

Thanks to point out that the Spec is faulty. So I will link this issue so maybe they (https://github.com/emissions-api) would change the Spec. But meanwhile what is the approach to M::P::OpenAPI so I can accept this type ? I mean what is the important bits of code so I can extend the M::P::OpenAPI ? thks in advance

marcoarthur commented 4 years ago

Since the discussion is getting the Spec right, I will close this issue. Thks again to point me out swagger specification.

jhthorsen commented 4 years ago

The only way I can think of is if you use Mojo::UserAgent to download the spec and then rewrite $c->req->json, before passing it to the OpenAPI plugin.

(“url” can be a hash-ref)

I think I would just download it, rewrite it, place it somewhere locally and load it from file.