jhthorsen / mojolicious-plugin-openapi

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

"basePath" handling broken for OpenAPI3 (or inconstent with OpenAPI2) #148

Closed augensalat closed 4 years ago

augensalat commented 4 years ago

In https://github.com/jhthorsen/mojolicious-plugin-openapi/issues/116#issuecomment-469418806 I learned how M:P:OpenAPI modifies the basePath value: It uses Mojo's url_for() to prepend the potential mount path of the application to the basePath: https://github.com/jhthorsen/mojolicious-plugin-openapi/blob/master/lib/Mojolicious/Plugin/OpenAPI/SpecRenderer.pm#L85 If I have a basePath: / in my OpenAPI2 spec file, and the whole application is mounted under /api, then in the resulting spec (available under scheme:host/api) I get

{
  "basePath": "/api"
}

Unfortunately the same procedure is not run for OpenAPI3's servers array: If I have

servers:
  - url: /

in my spec, and the whole application is again mounted under /api, then in the resulting spec (available under scheme:host/api) I get

{
  "servers": [
    {"url": "/"}
  ]
}

The expected output would have been

{
  "servers": [
    {"url": "/api"}
  ]
}

of course.

jhthorsen commented 4 years ago

Thanks!