flightphp / core

An extensible micro-framework for PHP
https://docs.flightphp.com
MIT License
2.62k stars 409 forks source link

describing routes #487

Closed lzanoni-stm closed 8 months ago

lzanoni-stm commented 1 year ago

Hello, I'm using Flight to create an API for a service. I'd like to auto-describe as much as possible (that is without writing a README on the APIs exposed) Is there a way to more or less automatically get the list of the routes (with their method) ? GET /api/things GET /api/thing/@id

Is it possible to 'hint' the optional or required parameters expected in the query string, but not in the URL route like /api/thing/@id?value=newvalue and finally, would it be possible to add a 'description' field when adding a route ? Flight::route('GET /languagesets', function(){ AsJSON(LanguageSet::ListSets(),"List the languages"); });

kuopassa commented 1 year ago

Perhaps you could try to create a regular expression that finds those significant parts. Something like:

$routes = file_get_contents('routes.php');

preg_match_all( "/Flight::route\('(.*)',[\n\r\s]+function\((.*)\){/", $routes, $matches );

foreach ($matches as $match) { var_dump($match); }

zpvini commented 9 months ago

May be too late, but you can list all routes with

\Flight::router()->getRoutes()

As of adding a description for a route, you can use Flight::map to create a new routing method that points to the original one, or override Flight's routing method and add new params to store the method name.

n0nag0n commented 8 months ago

Seems resolved with the last comment.