Problem Statement
Every project that uses #[RestController] needs to manually create a service to expose the OpenAPI spec. This is boilerplate that belongs in the library itself, since webfiori/http already owns the API layer and the OpenAPIGenerator.
Proposed Solution
Add two things:
1. Namespace scanning to OpenAPIGenerator
A new method that scans a namespace for #[RestController] classes and generates the spec automatically:
$generator = new OpenAPIGenerator();
$spec = $generator->generateFromNamespace('App\\Apis', 'API Title', '1.0.0', '/apis');
This complements the existing explicit-instance approach:
$spec = $generator->generate([new ProductService(), new UserService()], ...);
Both produce the same OpenAPIObj. Users pick whichever fits:
- Explicit instances — full control over which services to include and ordering
- Namespace scan — convenient auto-discovery, no manual maintenance
2. Built-in OpenAPISpecService
A ready-to-use service bundled in the library that exposes the generated spec:
#[RestController('openapi', 'OpenAPI specification endpoint')]
class OpenAPISpecService extends WebService {
// User configures namespace + base path
// GET returns the JSON spec directly
}
Users register it like any other service, passing namespace and base path as config.
Alternatives Considered
- Putting this in
webfiori/framework — rejected because API docs belong with the API layer itself
- Relying on a central manager — the new framework design has each service working independently, so namespace scanning is the right discovery mechanism
Breaking Change
No
Additional Context
The namespace scanning would use reflection to find classes with #[RestController] attribute, instantiate them, and pass them to the existing generate() method internally.
Problem Statement
Every project that uses
#[RestController]needs to manually create a service to expose the OpenAPI spec. This is boilerplate that belongs in the library itself, sincewebfiori/httpalready owns the API layer and theOpenAPIGenerator.Proposed Solution
Add two things:
1. Namespace scanning to
OpenAPIGeneratorA new method that scans a namespace for
#[RestController]classes and generates the spec automatically:This complements the existing explicit-instance approach:
Both produce the same
OpenAPIObj. Users pick whichever fits:2. Built-in
OpenAPISpecServiceA ready-to-use service bundled in the library that exposes the generated spec:
Users register it like any other service, passing namespace and base path as config.
Alternatives Considered
webfiori/framework— rejected because API docs belong with the API layer itselfBreaking Change
No
Additional Context
The namespace scanning would use reflection to find classes with
#[RestController]attribute, instantiate them, and pass them to the existinggenerate()method internally.