Hello, I am trying to write an openapi generator from rspec request tests. In rails it is possible to analyse routes, parse the route and get the name of the action and controller - rspec-openapi/lib/rspec/openapi/record_builder.rb at master · exoego/rspec-openapi · GitHub. Is there any way to get action and controller information in hanami 2.0+ ?
Hi @AlexeyMatskevich, thanks for using Hanami!
We do provide a way to introspect router routes: Hanami::Router::Inspector
.
To use the inspector, you want to create it along with a formatter, and then pass the inspector as the inspector:
arg when initializing a Hanami::Router
instance.
Please let me how you go with this! If you discover the some changes may be required for your use case, I’d be very happy to hear about them
First of all thank you for your help. I have now had success with my custom inspector.
As a user I understand how you can add an inspector in your application, but as a library writer, I’m not sure I’m doing it properly. I am having problems with having an instance of the inspector in my extractor, while at the same time passing the inspector to the hanami router before running the tests.
I noticed that if I add the inspector after running the tests (or maybe after prepare), I get an empty list of routers. Maybe I’m doing something wrong, at the moment I have to extend the router interface to load the inspector before the code starts.
If you have any advice on this, it would be appreciated. At the moment, the only alternative I see is to provide the inspector and describe in the readme that the inspector must be loaded for this gem to work correctly in test env.