Skip to content

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 ​

Routes endpointExtractRoutesActionAsks the configured routes processor for the routes.
Routes processor
Auto detectAutoDetectRoutesProcessorReads the Laravel router.
OpenAPIOpenAPISchemaRoutesProcessorReconciles a file with the detected routes.
Filter the routesExtractApplicationRoutesActionKeeps the routes under the prefix and drops the ignored ones.
Check the actionExtractableRouteFactoryClosures get an empty schema.
Request schema, tried in this order until one applies
Form RequestFormRequestStrategy
Data objectSpatieDataObjectStrategy
Inline validationInlineRequestValidatorStrategy
Add query keysFor GET routes, keys read by the controller become optional properties.
Add metadataExtractRouteMetadataActionName, middleware, auth hint and throttle.
Extracted routeExtractedRoute

A 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 ​

  1. Add a class that implements RequestSchemaStrategyContract in src/Modules/Extractor/Services/Request/Strategies.
  2. Return a Schema, or null when the strategy does not apply.
  3. Register it in the constructor of RequestSchemaExtractor. The order is the priority.
  4. 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.