noas / openapi
Zero-dependency OpenAPI 3.1 specification generator for Noas.
Requires
- php: ^8.4
- noas/framework: ^0.1
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Generate OpenAPI 3.1 from controllers using Noas\Attribute\Route, Body,
Query, and UseMiddleware. Bearer middleware is detected at controller and
method scope using Noas\Middleware\BearerTokenMiddleware.
$spec = (new Noas\OpenApi\OpenApiGenerator())->generate( [TaskController::class], title: 'Tasks API', );
HTTP errors reference the shared Noas.Http.ProblemDetails schema and
application/problem+json. Validation has a documented 422 response; protected
operations also document 401 and WWW-Authenticate. Other failures use the default
error response. SSE responses use text/event-stream, not a JSON transport DTO.
No third-party runtime packages are required.
For interactive documentation, return a Scalar response from an application controller and choose the route and OpenAPI document URL:
use Noas\Attribute\Route; use Noas\Http\Response; use Noas\OpenApi\ScalarApiReference; #[Route(method: 'GET', path: '/api/docs')] public function docs(): Response { return (new ScalarApiReference())->response('/api/openapi.json', 'Tasks API'); }
The browser loads Scalar from jsDelivr and must be able to access the CDN and the OpenAPI document. The document endpoint and documentation route remain the application's responsibility. If the document is cross-origin, configure CORS on its server.
After composer install, run composer ci. Linting uses find/xargs, as in the
framework. HTTP middleware metadata does not describe authorization inside MCP
tool calls.