jhthorsen / mojolicious-plugin-openapi

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

Removing SpecRenderer alters routes, given multiple specs #188

Closed christopherraa closed 4 years ago

christopherraa commented 4 years ago

Given the following script:

use Mojolicious::Lite -signatures;

post "/foo" => sub($c) { $c->render(openapi => { foo => 'yes' }) }, "foo";
post "/bar" => sub($c) { $c->render(openapi => { bar => 'no'  }) }, "bar";

plugin OpenAPI => {
    url     => "data:///foo-spec.json",
    schema  => "v2",
    # plugins => [qw/+Cors +Security/], # uncomment this!
};
plugin OpenAPI => {
    url     => "data:///bar-spec.json",
    schema  => "v2",
    # plugins => [qw/+Cors +Security/], # uncomment this!
};
app->start;

__DATA__
@@ foo-spec.json
{
  "swagger" : "2.0",
  "info" : { "version": "0.0.1", "title" : "Foo Service" },
  "schemes" : [ "http" ],
  "basePath" : "/api",
  "paths" : {
    "/foo" : {
      "post" : {
        "x-mojo-name" : "foo",
        "parameters" : [
          { "in": "body", "name": "body", "schema": { "type" : "object" } }
        ],
        "responses" : {
          "200": {
            "description": "Foo response",
            "schema": { "type": "object" }
          }
        }
      }
    }
  }
}

@@ bar-spec.json
{
  "swagger" : "2.0",
  "info" : { "version": "0.0.1", "title" : "Bar Service" },
  "schemes" : [ "http" ],
  "basePath" : "/api",
  "paths" : {
    "/bar" : {
      "post" : {
        "x-mojo-name" : "bar",
        "parameters" : [
          { "in": "body", "name": "body", "schema": { "type" : "object" } }
        ],
        "responses" : {
          "200": {
            "description": "Bar response",
            "schema": { "type": "object" }
          }
        }
      }
    }
  }
}

You can uncomment the two lines marked # uncomment this! in the script to make the command perl name-of-script.pl routes produce output that go from this (correct):

/api     *        api
  +/     GET      
  +/foo  POST     "foo"
  +/foo  OPTIONS  "foo_openapi_documentation"
/api     *        api
  +/     GET      
  +/bar  POST     "bar"
  +/bar  OPTIONS  "bar_openapi_documentation"

to this (ehm, yeah):

/foo     POST  "foo"
/api     *     api
/api     *     api
  +/bar  POST  "bar"
christopherraa commented 4 years ago

Never mind! My mistake.