Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content negotiation in v3 #110

Closed
plk opened this issue Feb 6, 2019 · 3 comments
Closed

Content negotiation in v3 #110

plk opened this issue Feb 6, 2019 · 3 comments
Assignees

Comments

@plk
Copy link

plk commented Feb 6, 2019

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 jhthorsen self-assigned this Feb 7, 2019
@jhthorsen
Copy link
Owner

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.

jhthorsen pushed a commit that referenced this issue Feb 14, 2019
 - Fix HEAD requests #105
 - Fix using /servers/0/url as basePath for OpenAPI v3 #110
   Note: This could be breaking change
 - Fix getting basePath when using under #107
 - Add support for "nullable" in OpenAPI 3.0 #106
 - Improved handling of Accept header in OpenAPI v3 #104
   Can now handle wildcards, such as application/* and */*, even though not
   defined in the specification.
 - Bump JSON::Validator to 3.06
@plk
Copy link
Author

plk commented Feb 14, 2019

Looks much better now.

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

@jhthorsen
Copy link
Owner

The Security plugin only works with v2 - for now.

PR is welcome! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants