Closed gaiederer closed 5 years ago
The special case for "/" is to be compatible with OpenAPI v2. I can agree that it's not a very good solution to put this in as a generic logic inside _resolve_ref()
, but I also can't see any good reasons to use absolute paths.
Do you actually have a /srv/
directory on your filesystem?
We need absolute paths because the api for the system is spread across a number of git projects. Each project is its own mojolicious plugin with model and controllers, and some modules are shared between projects. Since mojolicious runs inside docker, we can mount the deployed directories anywhere we want, but they are relative to a common system root, not the web root or any specific project root. /srv was a convenient, not already used path to mount everything under.
I see. I think the fix here is to add support for “file://...”.
What do you think about that?
I just added support for "file://", since I cannot come up with another solution for this.
I'll try it out. The issue is that mojolicious is not yet fully running (it is still initializing when it starts the plugin), so it cannot serve anything.
Maybe not an issue, since Mojo is using its user agent to make the query, it is not actually serving it.
I don’t understand what you’re talking about. “file://...” will look up a file on disk. It won’t use the user agent at all. So you do:
$ref: 'file:///srv/api-common/openapi.yaml#/components/responses/responseNotValid'
Sorry for the confusion -- just thinking out loud and didn't actually check the implementation. My apologies.
Finally got to try it out, works like a charm. Thanks much.
JSON::Validator version: https://cpan.metacpan.org/authors/id/J/JH/JHTHORSEN/Mojolicious-Plugin-OpenAPI-2.07.tar.gz
Perl version: Perl (v5.26.3, linux) Mojolicious (8.10, Supervillain)
Operating system: alpine 3.7
Steps to reproduce the behavior
In my mojolicious app file:
where $app->home->rel_file("openapi.yaml") contains:
and the reference /srv/api-common/openapi.yaml document contains:
Expected behavior
I would expect Validator.pm to find the $ref file, because it does exist in the specified location and is readable.
Actual behavior
When I start mojolicious, it complains:
Basically, it cannot find the $ref file /srv/api-common/openapi.yaml, even though it exists in that location.
I was able to trace the issue to two places:
When I modified JSON::Validator.pm as follows, I was able to get everything to load properly (although I am not submitting a merge request, because I don't know that it might not break some other $ref use case -- there's a lot going on in this sub).