enableOpenApi method

void enableOpenApi({
  1. String title = 'Bloom API',
  2. String version = '1.0.0',
  3. String description = 'Full-stack Bloom Server API',
  4. String schemaPath = '/api/openapi.json',
  5. String docsPath = '/api/docs',
  6. String swaggerPath = '/api/swagger',
})

Automatically generates an OpenAPI 3.1 specification and mounts interactive Scalar and Swagger UI documentation endpoints.

Mounts:

  • schemaPath (default '/api/openapi.json'): The raw OpenAPI 3.1 JSON specification.
  • docsPath (default '/api/docs'): Modern dark-themed Scalar API reference explorer.
  • swaggerPath (default '/api/swagger'): Interactive Swagger UI test console.

Example

router.enableOpenApi(
  title: 'E-Commerce API',
  version: '2.1.0',
  description: 'Public storefront and admin REST endpoints',
);

Implementation

void enableOpenApi({
  String title = 'Bloom API',
  String version = '1.0.0',
  String description = 'Full-stack Bloom Server API',
  String schemaPath = '/api/openapi.json',
  String docsPath = '/api/docs',
  String swaggerPath = '/api/swagger',
}) {
  get(
      schemaPath,
      (req) async => BloomResponse.json(toOpenApiSpec(
            title: title,
            version: version,
            description: description,
          )));

  get(
      docsPath,
      (req) async =>
          BloomResponse.html(_renderScalarHtml(title, schemaPath)));
  get(
      swaggerPath,
      (req) async =>
          BloomResponse.html(_renderSwaggerHtml(title, schemaPath)));
}