-
Notifications
You must be signed in to change notification settings - Fork 1
API Reference
Reference for all generated extension methods, classes, and types produced by the source generator.
These extension methods are generated on IServiceCollection for dependency injection setup in Program.cs.
π About the
{Project}placeholder:{Project}is the last dot-segment of the project/assembly name (e.g.MyCompany.Product.PetStoreβPetStore, producingAddPetStoreApi()/MapPetStoreApi()). A trailingApisuffix on that segment is stripped (case-insensitive) so the generated names never double up:
Project name {Project}Generated method MyCompany.Product.PetStorePetStoreMapPetStoreApi()MyCompany.Product.Api(empty) MapApi()(notMapApiApi())MyCompany.Product.WebApiWebMapWebApi()(notMapWebApiApi())The same rule applies to
Add{Project}Api(),Use{Project}Api(), andAdd{Project}ApiVersioning().
| Method | Generated When | Description |
|---|---|---|
services.Add{Project}Api() |
Always (with useGlobalErrorHandler) |
Registers all API services: rate limiting, security policies, handler DI |
services.AddApiHandlersFromDomain() |
Domain project exists | Registers all handler implementations from the domain assembly |
services.AddApiValidatorsFromDomain() |
FluentValidation validators exist | Registers all IValidator<T> implementations |
services.AddApiHealthChecks() |
healthChecks.enabled: true |
Registers ASP.NET Core health check services |
| Method | Generated When | Description |
|---|---|---|
services.AddApiResilience() |
x-retry-* extensions in spec |
Configures Polly resilience policies on IHttpClientFactory
|
services.AddWebhookHandlersFromDomain() |
Webhooks + domain project | Registers webhook handler implementations |
These extension methods are generated on WebApplication for mapping API endpoints in Program.cs.
| Method | Generated When | Description |
|---|---|---|
app.Map{Project}Api() |
Always (with useGlobalErrorHandler) |
Maps all endpoints + configures middleware (rate limiter, auth, error handling) |
app.Map{Segment}Endpoints() |
Per path segment | Maps endpoints for a specific segment (e.g., app.MapAccountsEndpoints()) |
app.MapHealthCheckEndpoints() |
healthChecks.enabled: true |
Maps /health, /health/live, /health/ready with optional API key security |
app.Map{Project}Webhooks() |
Webhooks in spec | Maps webhook receiver endpoints |
When using EndpointPerOperation mode, each operation gets its own class:
// Generated per operation
public sealed class GetAccountByIdEndpoint : IEndpointDefinition
{
internal const string ApiRouteBase = "/accounts";
public void DefineEndpoints(WebApplication app) { ... }
}Generated from OpenAPI components/schemas:
[GeneratedCode("Atc.Rest.Api.SourceGenerator", "1.0.0")]
public sealed record Account(
Guid Id,
string Name,
string? Description,
DateTimeOffset CreatedAt);-
sealed recordby default (usegeneratePartialModels: trueforpartial record) - Optional properties are nullable with
? -
readOnly/writeOnlyproperties are nullable withnulldefault -
[Required],[StringLength],[Range]validation attributes from OpenAPI constraints -
/// <summary>from schemadescription,/// <example>from schemaexample
Generated from operation parameters and request body:
[GeneratedCode("Atc.Rest.Api.SourceGenerator", "1.0.0")]
public sealed record GetAccountByIdParameters(
[property: FromRoute(Name = "accountId"), Required] Guid AccountId);
public sealed record CreateAccountParameters(
[property: FromBody, Required] Account Body);Generated from operation responses:
[GeneratedCode("Atc.Rest.Api.SourceGenerator", "1.0.0")]
public class GetAccountByIdResult : IResult
{
public static GetAccountByIdResult Ok(Account response) => ...
public static GetAccountByIdResult NotFound() => ...
public static IResult ToIResult(GetAccountByIdResult result) => ...
}Generated from operations β implemented by the developer:
public interface IGetAccountByIdHandler
{
Task<GetAccountByIdResult> ExecuteAsync(
GetAccountByIdParameters parameters,
CancellationToken cancellationToken);
}Generated by the client generator, in addition to the models and parameters above:
| Type | Mode | Shape |
|---|---|---|
{ClientName} |
TypedClient |
sealed class, implements I{ClientName}
|
I{ClientName} |
TypedClient |
Interface declaring every operation β always generated, no opt-in flag |
Add{ClientName}() |
TypedClient |
DI extension, emitted when Microsoft.Extensions.Http is referenced |
{Operation}Endpoint |
EndpointPerOperation |
sealed class, implements I{Operation}Endpoint
|
{Operation}EndpointResult |
EndpointPerOperation |
partial class with a static factory per documented response |
// Always partial β extend it from your own file, no marker-file flag needed.
public partial class GetAccountByIdEndpointResult : EndpointResponse, IGetAccountByIdEndpointResult
{
public static GetAccountByIdEndpointResult Ok(Account content) => ...
public static GetAccountByIdEndpointResult NotFound() => ...
}βΉοΈ
generatePartialModelsapplies to models only. Endpoint result classes arepartialunconditionally; the typed client class stayssealedβ depend onI{ClientName}instead of deriving from it.
β‘οΈ See Working with C# Client Testing for how these are used in tests.
// Generated from x-ratelimit-* extensions
public static class RateLimitPolicies
{
public const string Global = "global";
public const string AccountsStrict = "accounts-strict";
}// Generated from x-retry-* extensions
public static class ResiliencePolicies
{
public const string Standard = "standard";
public const string ExternalService = "external-service";
}// Generated from security schemes
public static class SecurityPolicies
{
public const string BearerAuth = "BearerAuth";
public const string ReadAccounts = "read:accounts";
}// Generated from x-cache-* extensions
public static class OutputCachePolicies
{
public const string AccountsList = "accounts-list";
}
public static class CachePolicies
{
public const string AccountsDetail = "accounts-detail";
}// Generated for EndpointPerOperation mode
public static class Constants
{
public const string HttpClientName = "MyApi-ApiClient";
}Usage in DI:
services.AddHttpClient(Constants.HttpClientName, client =>
{
client.BaseAddress = new Uri("https://api.example.com");
});- Marker Files β Configuration options that control what gets generated
-
Working with Configuration β
ApiGeneratorOptions.jsonreference - Working with Security β Security scheme generation details
- Working with Rate Limiting β Rate limit policy generation
- Working with Resilience β Resilience policy generation
- Working with Caching β Cache policy generation
- Development Notes β Extractor architecture
π Home
- πΌ FAQ Business Value
- π Getting Started with Basic
- π οΈ Getting Started with CLI
- π Migration Guide
- β¬οΈ Upgrading to v2
- π Working with OpenAPI
- π³οΈ Working with Nullability
- π οΈ 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 C# Client
- π§ͺ Working with C# Client Testing
- π¦ 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