Route extraction
Route extraction turns the routes of the host app into a list of endpoints with a request schema. The UI shows this list in the route explorer.
The rule that shapes this flow is simple. Nimbus reads the source of the host app through the AST modules and does not run host code to learn about it.
The flow
ExtractRoutesActionAsks the configured routes processor for the routes.AutoDetectRoutesProcessorReads the Laravel router.OpenAPISchemaRoutesProcessorReconciles a file with the detected routes.ExtractApplicationRoutesActionKeeps the routes under the prefix and drops the ignored ones.ExtractableRouteFactoryClosures get an empty schema.FormRequestStrategySpatieDataObjectStrategyInlineRequestValidatorStrategyExtractRouteMetadataActionName, middleware, auth hint and throttle.ExtractedRouteA broken route definition throws InvalidRouteDefinitionException. A failure while reading one route is logged and does not stop the list. The route stays in it with an empty schema and a RulesExtractionError, which the UI shows as the extraction error of that route.
Where the AST fits
The Ast module wraps PhpParser. ClassQuery and MethodQuery load a class file and answer questions such as the return value of a method or the docblock of a class. Strategies use them to read a rules() array, an inline validator array or a resource body as syntax.
A Form Request is the one place with a fast path. The strategy reads the class and calls rules() on it. If that call throws, for example because the rules use $this->user(), the strategy falls back to the AST and records a RulesExtractionError on the schema. Keep new strategies on the AST first.
Adding a strategy
- Add a class that implements
RequestSchemaStrategyContractinsrc/Modules/Extractor/Services/Request/Strategies. - Return a
Schema, ornullwhen the strategy does not apply. - Register it in the constructor of
RequestSchemaExtractor. The order is the priority. - Test it with a controller fixture under
tests/App/Modules/Extractor.
The next step is schema building. Large apps can store the result with the routes snapshot.