jhthorsen / mojolicious-plugin-openapi

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

Content negotiation in v3 #110

Closed plk closed 5 years ago

plk commented 5 years ago

Apologies if I have missed something obvious here but I can't get v3 to work at all due to content negotiation errors even in the most basic form. I am using 2.12 DEV and the latest JSON::Validator. The following example gives 500 errors for me regardless of what Accept header I pass. In the real use case, it's "*/*" as that's what Swagger UI sends.

use v5.16;
use Mojo::Base -strict;
use Mojolicious::Lite;

get '/test' => sub {
  my $c = shift->openapi->valid_input or return;
  $c->render(status => 200, openapi => "test");
  },
  'File';

plugin OpenAPI => {schema => 'v3', url => 'data://main/file.yaml'};

my $ua = Mojo::UserAgent->new;
my $res = $ua->get("/v1/test" => {Accept => 'application/json'})->res;
#my $res = $ua->get("/v1/test" => {Accept => '*/*'})->res;

package main;
__DATA__
@@ file.yaml
openapi: 3.0.0
info:
  title: Title
  description: Description
  version: 1.0.0
servers:
  - url: 'https://server.com/v1'
paths:
  '/test':
    get:
      operationId: "File"
      responses:
        '200':
          description: Success listing connections
          content:
            application/json:
              schema:
                type: string
jhthorsen commented 5 years ago

This was a silly bug: M::P::OpenAPI did not extract "basePath" from "servers".

There might be a new bug in the future that wants to support multiple base paths, but I'll fix it when someone asks for it then, since it's not trivial to do tonight.

plk commented 5 years ago

Looks much better now.

Does Mojolicious::Plugin::OpenAPI::Security support securitySchemes in v3 or only securitydefinitions in v2?

jhthorsen commented 5 years ago

The Security plugin only works with v2 - for now.

PR is welcome! :)