Skip to content

ANcpLua/Scalar.Kiota.Extension

Repository files navigation

.NET 10 NuGet License codecov

demo_gen

Scalar.Kiota.Extension

Automates Kiota SDK generation and integrates it with Scalar API documentation for ASP.NET Core minimal APIs with native AOT support.

Installation

dotnet add package Scalar.Kiota.Extension --prerelease

Quick Start

using Scalar.Kiota.Extension;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddScalarWithKiota();

var app = builder.Build();

app.MapScalarWithKiota("/api");

await app.RunAsync();

Configuration

builder.Services.AddScalarWithKiota(options =>
{
    options.WithTitle("My API")                    // Default: "{ApplicationName} API"
           .WithTheme(ScalarTheme.Saturn)          // Default: Saturn
           .WithSdkName("MyApiClient")             // Default: "ApiClient" (space-free for compatibility) 
           .WithLanguages("TypeScript", "CSharp")  // Default: ["TypeScript"]
           .WithOutputPath("./custom-output")      // Default: "wwwroot/.scalar-kiota"
           .WithOpenDocsOnStartup();               // Default: false
           
    options.BundleTypeScript = true;               // Default: true
    options.DocumentationPath = "/docs";           // Default: null (uses pattern)
});

Available Languages

  • TypeScript - Bundled with esbuild for browser usage
  • CSharp - .NET client
  • Python - Python client
  • Java - Java client
  • Go - Go client
  • PHP - PHP client
  • Ruby - Ruby client
  • Swift - Swift client
  • CLI - Command line client

Available Themes

ScalarTheme.Default, ScalarTheme.Alternate, ScalarTheme.Moon, ScalarTheme.Purple, ScalarTheme.Solarized, ScalarTheme.BluePlanet, ScalarTheme.Saturn, ScalarTheme.Kepler, ScalarTheme.Mars, ScalarTheme.DeepSpace

How It Works

  1. Downloads OpenAPI spec from /openapi/v1.json
  2. Generates SDKs using Kiota CLI (auto-installed if missing)
  3. For TypeScript: creates package.json, installs dependencies, bundles with esbuild
  4. Creates config.js that exposes the SDK to Scalar's "Try It" feature
  5. Only regenerates when OpenAPI spec changes (SHA256 hash-based caching)

Generated Structure

wwwroot/.scalar-kiota/
├── openapi.json      # Downloaded spec
├── config.js         # Scalar integration
├── sdk.js           # Bundled TypeScript (if enabled)
├── .spec.hash       # Cache validation
└── [language]/      # Generated SDK sources

Requirements

License

This project is licensed under the MIT License.

About

Downloads /openapi/v1.json from your minimal API, generates language SDKs via Kiota, serves them through Scalar UI

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages