CodeBridge.Core 0.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package CodeBridge.Core --version 0.0.2
                    
NuGet\Install-Package CodeBridge.Core -Version 0.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CodeBridge.Core" Version="0.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CodeBridge.Core" Version="0.0.2" />
                    
Directory.Packages.props
<PackageReference Include="CodeBridge.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CodeBridge.Core --version 0.0.2
                    
#r "nuget: CodeBridge.Core, 0.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CodeBridge.Core@0.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CodeBridge.Core&version=0.0.2
                    
Install as a Cake Addin
#tool nuget:?package=CodeBridge.Core&version=0.0.2
                    
Install as a Cake Tool

CodeBridge.Core

Core library for CodeBridge SDK generator. This package contains the core abstractions, services, and models used by CodeBridge to analyze .NET code and generate TypeScript SDKs.

📦 Installation

dotnet add package CodeBridge.Core

🎯 What's Included

Services

  • SourceAnalyzer - Roslyn-based C# code analyzer

    • Discovers endpoints with [GenerateSdk] attribute
    • Analyzes types and their properties
    • Discovers FluentValidation rules
  • TypeMapper - C# to TypeScript type mapping

    • 50+ built-in type mappings
    • Generic type support (List<T>, Dictionary<K,V>, etc.)
    • Custom type mapping support
    • Nullable type handling
  • CodeGenerator - TypeScript code generation

    • Interface generation
    • Enum generation
    • API client functions
    • Validation schemas (Zod)
    • React Query hooks
    • Next.js server actions
  • ConfigurationLoader - Configuration management

    • JSON-based configuration
    • Environment-specific overrides
    • Validation and error reporting

Models

  • EndpointInfo - API endpoint metadata
  • TypeInfo - Type information and properties
  • PropertyInfo - Property details
  • PropertyValidationRules - Validation rule metadata
  • CodeBridgeConfig - Complete configuration model

Attributes

  • GenerateSdkAttribute - Mark endpoints for SDK generation
    [GenerateSdk(
        Summary = "Get all products",
        Group = "products",
        RequiresAuth = true,
        Tags = new[] { "products", "catalog" }
    )]
    

🔧 Usage

Analyze Source Code

using CodeBridge.Core.Services;
using Microsoft.Extensions.Logging;

var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
var analyzer = new SourceAnalyzer(loggerFactory.CreateLogger<SourceAnalyzer>());

var projects = new List<ProjectInfo>
{
    new() { Name = "MyApi", Path = "/path/to/project" }
};

var endpoints = await analyzer.DiscoverEndpointsAsync(projects, cancellationToken);
var types = await analyzer.DiscoverTypesAsync(projects, cancellationToken);

Map Types

var typeMapper = new TypeMapper(logger, advancedOptions);

var tsType = typeMapper.MapToTypeScript("List<Product>"); 
// Result: "Product[]"

var tsType2 = typeMapper.MapToTypeScript("Dictionary<string, int>");
// Result: "Record<string, number>"

Generate Code

var generator = new CodeGenerator(logger, typeMapper, targetOptions, featureOptions);

// Generate TypeScript interface
var interfaceCode = await generator.GenerateTypeScriptInterfaceAsync(typeInfo, cancellationToken);

// Generate API function
var functionCode = await generator.GenerateApiClientFunctionAsync(endpoint, cancellationToken);

// Generate React hook
var hookCode = await generator.GenerateReactHookAsync(endpoint, cancellationToken);

Load Configuration

var configLoader = new ConfigurationLoader(logger);
var config = await configLoader.LoadAsync("codebridge.json", cancellationToken);

// Validate configuration
var errors = config.Validate();
if (errors.Count > 0)
{
    foreach (var error in errors)
    {
        Console.WriteLine(error);
    }
}

🎨 Type Mappings

Primitives

C# Type TypeScript Type
string string
int, long, decimal, double, float number
bool boolean
DateTime, DateTimeOffset string
Guid string
void void
object, dynamic any

Collections

C# Type TypeScript Type
List<T>, T[], IEnumerable<T> T[]
Dictionary<string, T> Record<string, T>
Dictionary<K, V> Map<K, V>
HashSet<T> Set<T>

Special Types

C# Type TypeScript Type
Result<T> Result<T>
Task<T>, ActionResult<T> T (unwrapped)
Nullable<T>, T? T \| null
IFormFile FormData
Stream Blob

🔌 Extensibility

Custom Type Mappings

{
  "advanced": {
    "customTypeMappings": {
      "MyCustomType": "CustomTsType",
      "PagedResult<T>": "PagedResponse<T>"
    }
  }
}

📚 API Reference

For detailed API documentation, see the API Reference.

🤝 Contributing

This is the core package that powers CodeBridge. Contributions are welcome!

📄 License

MIT License - see LICENSE for details.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 182 10/10/2025
1.0.0-preview.8 142 10/9/2025
1.0.0-preview.7 133 10/9/2025
1.0.0-preview.6 142 10/9/2025
1.0.0-preview.5 131 10/9/2025
0.0.4 189 10/9/2025
0.0.3 179 10/9/2025
0.0.2 183 10/9/2025
0.0.1 192 10/2/2025

Added Minimal API support - can now detect and generate SDKs for
           ASP.NET Core Minimal APIs using MapGet/MapPost/MapPut/MapDelete patterns