-
Notifications
You must be signed in to change notification settings - Fork 1
Home
A Roslyn Source Generator that automatically generates REST API server and client code from OpenAPI specifications. No CLI commands, no manual code generation - just build your project and get production-ready code.
| Area | Feature | Description |
|---|---|---|
| Core | π§ Zero Configuration | Add the NuGet package, drop your YAML file, build |
| ποΈ Minimal API | Generates modern ASP.NET Core minimal API endpoints | |
| π Contract-Enforced Results | Handlers can only return responses defined in OpenAPI - compile-time safety! | |
| β Validation | Automatic [Required], [Range], [StringLength] from OpenAPI constraints |
|
| Server | π Handler Scaffolds | Auto-generates handler stubs for unimplemented operations |
| π Security | JWT, OAuth2 scopes, API Key, role-based auth - all from OpenAPI | |
| β±οΈ Rate Limiting | Server-side rate limiting from x-ratelimit-* extensions |
|
| πΎ Caching | Output caching and HybridCache support from x-cache-* extensions |
|
| Client | π Type-Safe Client | Strongly-typed HTTP client with full IntelliSense |
| π Resilience | Client-side retry/circuit breaker from x-retry-* extensions |
|
| π URL Encoding | Automatic RFC 3986 compliant encoding - no more broken URLs | |
| Models | π― Enum Support | Generates C# enums from OpenAPI string enums |
| π Pagination | Generic PaginatedResult<T> from allOf composition |
|
| Data | π File Uploads | Full support for binary uploads (single, multiple, with metadata) |
| π Streaming |
IAsyncEnumerable<T> support for efficient data streaming |
|
| CLI | π₯οΈ Project Scaffolding |
generate server / generate client creates complete project structure |
| π¦ TypeScript Client |
generate client-typescript β Fetch/Axios, interceptors, retry, MSW handlers |
|
| βοΈ React Hooks | React Query (useQuery/useMutation/useInfiniteQuery/useSuspenseQuery) + SWR β streaming hooks for IAsyncEnumerable
|
|
| πͺͺ Branded ID types |
--branded-ids emits nominal types β getUser(petId) becomes a compile error |
|
| π Runtime Zod validation |
--zod-runtime-validate wires Zod into response parsing β spec-drift detection |
|
| π SignalR Hub Hooks |
x-signalr-hubs extension β typed use<Hub>Hub() with auto-reconnect |
|
| π Spec Validation |
spec validate validates OpenAPI specs with strict/standard modes |
|
| π Multi-Part Specs |
spec merge / spec split for large API specifications |
|
| βοΈ Options Management |
options create / options validate for configuration files |
|
| π Migration |
migrate validate / migrate execute to migrate from old CLI generator |
dotnet add package Atc.Rest.Api.SourceGeneratorAdd your *.yaml file and marker file to .csproj:
<ItemGroup>
<AdditionalFiles Include="MyApi.yaml" />
<AdditionalFiles Include=".atc-rest-api-server" />
</ItemGroup>Create .atc-rest-api-server:
{
"generate": true,
"validateSpecificationStrategy": "Standard"
}dotnet buildGenerated code includes:
- π¦ Models - C# records with validation attributes
- π― Handler Interfaces -
IListPetsHandler,ICreatePetHandler, etc. - π£οΈ Endpoints - Minimal API
MapGet,MapPost, etc. - π DI Extensions -
AddApiHandlersFromDomain(),MapApiEndpoints()
π‘ Tip: Use the CLI tool to scaffold complete projects automatically!
dotnet tool install -g atc-rest-api-gen atc-rest-api-gen generate server -s api.yaml -o ./my-api -n MyApiSee Getting Started with CLI for a complete walkthrough.
π Migrating from the old CLI generator? Use the built-in migration tool:
atc-rest-api-gen migrate validate -s ./my-project -p api.yaml atc-rest-api-gen migrate execute -s ./my-project -p api.yamlSee Migration Guide for step-by-step instructions.
- .NET 10 or later
- OpenAPI 3.0.x or 3.1.x specification
The project uses a three-layer architecture:
| Layer | Project | Description |
|---|---|---|
| π¦ Shared | Atc.Rest.Api.Generator |
All extractors, services, configuration, validation (Roslyn-independent) |
| βοΈ Generators | Atc.Rest.Api.SourceGenerator |
Roslyn source generators (thin wrappers calling shared services) |
| π οΈ CLI | Atc.Rest.Api.Generator.Cli |
Command-line tool for validation and generation |
public class GetPetByIdHandler : IGetPetByIdHandler
{
public async Task<GetPetByIdResult> ExecuteAsync(
GetPetByIdParameters parameters,
CancellationToken ct)
{
var pet = await repository.GetByIdAsync(parameters.PetId, ct);
// β
Clean syntax with implicit operator
if (pet is not null)
return pet; // Implicitly converts to GetPetByIdResult.Ok(pet)
// β
Factory methods for error responses
return GetPetByIdResult.NotFound();
// β COMPILE ERROR - Method doesn't exist!
// return GetPetByIdResult.InternalServerError();
}
}π Type-Safe Results: Result classes have private constructors and factory methods matching your OpenAPI responses. You literally cannot return a status code that isn't in your spec!
π·οΈ Marker Files
| File | Purpose |
|---|---|
.atc-rest-api-server |
Server code (models, endpoints, handlers) |
.atc-rest-api-server-handlers |
Handler implementation scaffolds |
.atc-rest-api-client |
HTTP client generation |
MIT License - see LICENSE for details.
π Home
- πΌ FAQ Business Value
- π Getting Started with Basic
- π οΈ Getting Started with CLI
- π Migration Guide
- π Working with OpenAPI
- π οΈ Working with CLI
- π How-To Guides
- π Working with Security
- π¦ Working with Rate Limiting
- π Working with Resilience
- ποΈ Working with Caching
- π’ Working with Versioning
- β Working with Validations
- π Working with Webhooks
- βοΈ Working with Aspire
- π£οΈ Working with Endpoint Definitions
- π Working with Multi-Part Specs
- π§ͺ Working with Code Coverage
- π¦ Working with TypeScript Client
- πͺ Showcase Demo
- π§ͺ Working with E2E Testing
- βοΈ Working with Configuration
- π Marker Files
- π API Reference
- π Analyzer Rules
- β FAQ and Troubleshooting
- πΊοΈ Roadmap
- π§ Development Notes
- π¦ GitHub Repository
- π₯ NuGet Package
- π Report Issues