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

Ignore unsupported HTTP methods #1294

Merged
merged 4 commits into from
Apr 20, 2018
Merged

Ignore unsupported HTTP methods #1294

merged 4 commits into from
Apr 20, 2018

Conversation

notFloran
Copy link
Contributor

@notFloran notFloran commented Apr 12, 2018

If an action use a LINK, UNLINK or COPY methods the bundle fails with: Notice: Undefined index: link in vendor/nelmio/api-doc-bundle/Describer/SwaggerPhpDescriber.php (line 174)

OpenAPI doesn't supports the LINK and UNLINK methods so the bundle must ignore this methods.

Fix #1290

@dbu
Copy link
Collaborator

dbu commented Apr 12, 2018

i just noticed a similar problem with an end point that supports COPY. are you sure that the javascript part can not handle this? if i understand correctly, this PR will simply drop those methods without reporting that there is a problem. is there anything better we can do?

@notFloran notFloran changed the title Ignore LINK and UNLINK methods Ignore unsupported HTTP methods Apr 13, 2018
@notFloran
Copy link
Contributor Author

i just noticed a similar problem with an end point that supports COPY. are you sure that the javascript part can not handle this?

Swagger/OpenAPI only supports : get, put, post, delete, options, head, patch. So this end points will never display in the javascript parts.

See:

if i understand correctly, this PR will simply drop those methods without reporting that there is a problem. is there anything better we can do?

Yes, methods that are not in ['get', 'post', 'put', 'patch', 'delete', 'options', 'head'] are ignored to allow the page to be displayed.

I don't see how to improve that, maybe a log ?

Copy link
Collaborator

@GuilhemN GuilhemN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a better solution unfortunately. No need to log this imo.

LGTM 👍

Copy link
Collaborator

@dbu dbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think logging a warning would be a good thing, as people might be confused why their method is missing.

and i have some questions:

@@ -206,6 +206,7 @@ private function getMethodsToParse(): \Generator
$path = $this->normalizePath($route->getPath());
$httpMethods = $route->getMethods() ?: Swagger::$METHODS;
$httpMethods = array_map('strtolower', $httpMethods);
$httpMethods = array_intersect($httpMethods, Swagger::$METHODS);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if the methods become an empty array here, because only unsupported methods are in the list?

also, is it invalid for open api spec to specify this methods, or is it "just" a bug of the swagger-ui library? if its a problem of that library, we should see if we can do something later in the process, or have a configuration option, so that people that care about the specification of their api can get a full spec that does not drop methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if the methods become an empty array here, because only unsupported methods are in the list?

Nothing, in the rest of the code we go through the methods to consolidate the annotations and add them to the analysis so if a path does not have methods it is ignored.

I have changed the code, if there are no valid methods we go to the next route.

also, is it invalid for open api spec to specify this methods, or is it "just" a bug of the swagger-ui library? if its a problem of that library, we should see if we can do something later in the process, or have a configuration option, so that people that care about the specification of their api can get a full spec that does not drop methods.

It's invalid for OpenAPI spec, the spec only supports : get, put, post, delete, options, head, patch.

See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#pathItemObject for the spec and this issue OAI/OpenAPI-Specification#480

@GuilhemN
Copy link
Collaborator

Could you add a test to ensure there won't be a regression please ? (Adding a method to one of the existing routes should be enough)

And I have no strong opinion about logging, that could indeed help people understand the situation and it isn't complicated to implement so if you feel so I think we should add it :)

Copy link
Collaborator

@GuilhemN GuilhemN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍


yield $method => [$path, $httpMethods];
if (empty($validHttpMethods)) {
$this->logger->warning('No valid HTTP method for path', [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about replacing no valid by no supported? It is less alarming imo :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to help the user some more, we could even say: "None of the HTTP methods specified for path {path} are supported by swagger-ui, skipping this path"

@GuilhemN GuilhemN merged commit 1680ba3 into nelmio:master Apr 20, 2018
@GuilhemN
Copy link
Collaborator

Thank you @notFloran :)

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

Successfully merging this pull request may close these issues.

3 participants