jhthorsen / mojolicious-plugin-openapi

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

Typo in a route name shows a confusing error message #87

Closed kivilahtio closed 5 years ago

kivilahtio commented 5 years ago

Hi!

The problem is replicated by this script: https://github.com/kivilahtio/mojolicious-plugin-openapi/commit/3af62c61985cdebdbcb347da25ffe2c64d4c54a7

Running this test file shows error: [Sat Sep 22 07:28:16 2018] [debug] Using default_handler to render data since 'openapi' was not found in stash. Set 'handler' in stash to avoid this message.

It took a bit of time to figure out what this meant.

If you take a look at the openapi.yaml at the bottom, you find that there is a typo in the path name:

x-mojo-name: getEcho,

I managed to leave the comma there, when refactoring an API spec from json to yaml. Essentially there is no such method/route to handle the GET /echo -endpoint.

I'd prefer to have a solid error message saying that there is no implementation for the endpoint, instead of complaining about the missing openapi renderer.

Later on there is a 501 error Not Implemented, which is rather spot on.

Would it be possible to have some static safety when loading the OpenAPI-plugin to check that all the endpoints have an implementation, or atleast a matching route?

jhthorsen commented 5 years ago

This is fixed in master now, but I'm working on a better fix while also fixing #80.