home / skills / stuartf303 / sorcha / scalar

scalar skill

/.claude/skills/scalar

This skill configures and deploys Scalar OpenAPI UI for documenting APIs with a Purple theme across services.

npx playbooks add skill stuartf303/sorcha --skill scalar

Review the files below or copy the command above to add this skill to your agents.

Files (3)
SKILL.md
3.8 KB
---
name: scalar
description: |
  Generates and configures Scalar OpenAPI UI for API documentation.
  Use when: Adding API documentation to services, configuring OpenAPI endpoints, customizing documentation themes
allowed-tools: Read, Edit, Write, Glob, Grep, Bash, mcp__context7__resolve-library-id, mcp__context7__query-docs
---

# Scalar Skill

Scalar replaces Swagger/Swashbuckle as the OpenAPI documentation UI in this codebase. All services use .NET 10's built-in `AddOpenApi()` with Scalar's `MapScalarApiReference()` for the UI. The project enforces Purple theme consistency across all microservices.

## Quick Start

### Standard Service Configuration

```csharp
// Program.cs - Service setup
builder.Services.AddOpenApi();

var app = builder.Build();
app.MapOpenApi();

if (app.Environment.IsDevelopment())
{
    app.MapScalarApiReference(options =>
    {
        options
            .WithTitle("Blueprint Service")
            .WithTheme(ScalarTheme.Purple)
            .WithDefaultHttpClient(ScalarTarget.CSharp, ScalarClient.HttpClient);
    });
}
```

### API Gateway with Aggregated Documentation

```csharp
// Aggregated OpenAPI from all services
app.MapGet("/openapi/aggregated.json", async (OpenApiAggregationService service) =>
{
    var spec = await service.GetAggregatedOpenApiAsync();
    return Results.Json(spec);
})
.ExcludeFromDescription();

app.MapScalarApiReference(options =>
{
    options
        .WithTitle("Sorcha API Gateway - All Services")
        .WithTheme(ScalarTheme.Purple)
        .WithDefaultHttpClient(ScalarTarget.CSharp, ScalarClient.HttpClient)
        .WithOpenApiRoutePattern("/openapi/aggregated.json");
});
```

## Key Concepts

| Concept | Usage | Example |
|---------|-------|---------|
| `AddOpenApi()` | Register OpenAPI services | `builder.Services.AddOpenApi()` |
| `MapOpenApi()` | Expose `/openapi/v1.json` | `app.MapOpenApi()` |
| `MapScalarApiReference()` | Mount Scalar UI at `/scalar` | See examples above |
| `ScalarTheme` | Visual theme enum | `ScalarTheme.Purple` |
| `ScalarTarget` | Code generation target | `ScalarTarget.CSharp` |
| `ScalarClient` | HTTP client library | `ScalarClient.HttpClient` |

## Common Patterns

### Document Endpoints for Scalar

```csharp
app.MapPost("/api/wallets", handler)
    .WithName("CreateWallet")
    .WithSummary("Create a new wallet")
    .WithDescription("Creates an HD wallet with the specified algorithm")
    .WithTags("Wallets");
```

### Rich OpenAPI Descriptions with Markdown

```csharp
builder.Services.AddOpenApi(options =>
{
    options.AddDocumentTransformer((document, context, ct) =>
    {
        document.Info.Title = "Register Service API";
        document.Info.Version = "1.0.0";
        document.Info.Description = """
            # Register Service
            
            ## Overview
            Provides a **distributed ledger** for immutable transactions.
            
            ## Key Features
            - Cryptographic signatures
            - Chain integrity verification
            """;
        return Task.CompletedTask;
    });
});
```

## See Also

- [patterns](references/patterns.md)
- [workflows](references/workflows.md)

## Related Skills

- See the **minimal-apis** skill for endpoint documentation patterns
- See the **aspire** skill for service discovery integration
- See the **yarp** skill for API Gateway configuration

## Documentation Resources

> Fetch latest Scalar documentation with Context7.

**How to use Context7:**
1. Use `mcp__context7__resolve-library-id` to search for "scalar"
2. Prefer website documentation (`/websites/guides_scalar`) over source repositories
3. Query with `mcp__context7__query-docs` using the resolved library ID

**Library ID:** `/websites/guides_scalar`

**Recommended Queries:**
- "Scalar .NET ASP.NET Core configuration options themes"
- "Scalar themes available dark mode customization"
- "Scalar API reference configuration fluent API"

Overview

This skill generates and configures the Scalar OpenAPI UI for .NET services to provide consistent, centralized API documentation. It replaces Swagger/Swashbuckle patterns in the codebase and enforces a Purple visual theme across microservices. Use it to mount a responsive Scalar UI, aggregate multiple OpenAPI specs, and wire code-generation defaults for C# clients.

How this skill works

The skill integrates with ASP.NET Core’s AddOpenApi()/MapOpenApi() pipeline and exposes Scalar via MapScalarApiReference(), normally mounted at /scalar. It can point Scalar at a single service OpenAPI route or an aggregated JSON endpoint produced by an API gateway. Fluent options let you set title, theme, default client target, and the OpenAPI route pattern used by the UI.

When to use it

  • Adding interactive API documentation to a microservice using built-in .NET AddOpenApi()
  • Replacing existing Swagger/Swashbuckle UI with Scalar for consistent theming
  • Configuring an API Gateway to serve a combined OpenAPI spec to a single Scalar UI
  • Standardizing client code generation defaults (e.g., C# HttpClient) across services
  • Customizing title, theme, or OpenAPI route pattern for developer portals

Best practices

  • Register AddOpenApi() in Program.cs and call MapOpenApi() before mounting Scalar
  • Mount MapScalarApiReference() conditionally (for example, only in Development) unless you want public docs
  • Use an aggregated OpenAPI endpoint for gateways so one Scalar UI covers all services
  • Set WithDefaultHttpClient and ScalarTarget to enforce consistent client generation
  • Keep theme and branding consistent (use ScalarTheme.Purple across microservices)
  • Provide rich Markdown descriptions in document transformers to improve discoverability

Example use cases

  • Service-level docs: Add MapScalarApiReference in a single service to expose its OpenAPI at /scalar
  • API Gateway: Expose /openapi/aggregated.json and point Scalar to that route for unified docs
  • Client generation policy: Configure WithDefaultHttpClient(ScalarTarget.CSharp, ScalarClient.HttpClient) for all services
  • Theming enforcement: Apply ScalarTheme.Purple in all microservices for consistent developer experience
  • Rich documentation: Use AddDocumentTransformer to populate title, version, and Markdown-rich descriptions

FAQ

Can I expose Scalar only in development?

Yes. Mount MapScalarApiReference() behind an environment check (app.Environment.IsDevelopment()) to limit exposure.

How do I document multiple services in one UI?

Have the gateway produce an aggregated OpenAPI JSON (e.g., /openapi/aggregated.json) and configure MapScalarApiReference().WithOpenApiRoutePattern to point at it.