Skip to content

Working with Configuration

davidkallesen edited this page Apr 16, 2026 · 6 revisions

βš™οΈ Working with Configuration

This guide covers the ApiGeneratorOptions.json configuration file and the CLI commands for managing it.


πŸ“„ ApiGeneratorOptions.json

The ApiGeneratorOptions.json file controls how the generator behaves. It's auto-discovered from your project directory, or you can specify it explicitly with --options.

πŸ“ Creating a Configuration File

# Create with defaults in the current directory
atc-rest-api-gen options create -o .

# Create at a specific path
atc-rest-api-gen options create -o ./config/ApiGeneratorOptions.json

# Overwrite existing file
atc-rest-api-gen options create -o . --force

πŸ“‹ Default Configuration

{
  "general": {
    "validateSpecificationStrategy": "Standard",
    "includeDeprecated": false
  },
  "server": {
    "namespace": null,
    "subFolderStrategy": "BySegment",
    "versioningStrategy": "None",
    "defaultApiVersion": "1.0",
    "reportApiVersions": true,
    "assumeDefaultVersionWhenUnspecified": true,
    "useServersBasePath": false,
    "useGlobalErrorHandler": "Auto",
    "useMinimalApiPackage": "Auto",
    "domain": {
      "generateHandlersOutput": "Handlers",
      "handlerSuffix": "Handler",
      "stubImplementation": "NotImplementedException"
    }
  },
  "client": {
    "namespace": null,
    "generationMode": "EndpointPerOperation",
    "clientSuffix": "Endpoint",
    "httpClientName": null,
    "generatePartialModels": false,
    "generateOAuthTokenManagement": false,
    "useServersBasePath": true,
    "includePaths": [],
    "excludePaths": []
  }
}

βœ… Validating Configuration

The options validate command checks your configuration file for errors and displays a summary:

# Validate options file in current directory
atc-rest-api-gen options validate -o .

# Validate a specific file
atc-rest-api-gen options validate -o ./config/ApiGeneratorOptions.json

πŸ” What Gets Validated

Check Description
πŸ“„ File exists Verifies the JSON file is found at the specified path
πŸ”§ JSON syntax Validates the file is well-formed JSON
πŸ“‹ Known properties Warns about unrecognized property names (typos)
πŸ”’ Valid enum values Checks that strategy/mode values are valid (e.g., EndpointPerOperation, TypedClient)
πŸ”— Namespace format Validates namespace strings follow C# naming rules
πŸ“ Path references Checks that referenced paths/directories are valid

πŸ“Š Output Example

βœ“ Validation passed - options file is valid

Configuration summary:
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Section        β”‚ Setting                        β”‚ Value                   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ general        β”‚ validateSpecificationStrategy  β”‚ Standard                β”‚
β”‚ general        β”‚ includeDeprecated              β”‚ False                   β”‚
β”‚ server         β”‚ namespace                      β”‚ (auto-detect)           β”‚
β”‚ server         β”‚ subFolderStrategy              β”‚ BySegment               β”‚
β”‚ server         β”‚ versioningStrategy             β”‚ None                    β”‚
β”‚ server         β”‚ defaultApiVersion              β”‚ 1.0                     β”‚
β”‚ server.domain  β”‚ generateHandlersOutput         β”‚ Handlers                β”‚
β”‚ server.domain  β”‚ handlerSuffix                  β”‚ Handler                 β”‚
β”‚ server.domain  β”‚ stubImplementation             β”‚ NotImplementedException β”‚
β”‚ client         β”‚ namespace                      β”‚ (auto-detect)           β”‚
β”‚ client         β”‚ generationMode                 β”‚ EndpointPerOperation    β”‚
β”‚ client         β”‚ clientSuffix                   β”‚ Endpoint                β”‚
β”‚ client         β”‚ generateOAuthTokenManagement   β”‚ False                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”§ Configuration Reference

πŸ“‹ General Section

Setting Type Default Description
validateSpecificationStrategy enum Standard None, Minimal, Standard, Strict β€” how strictly to validate the OpenAPI spec
includeDeprecated bool false Whether to include deprecated operations and schemas

πŸ–₯️ Server Section

Setting Type Default Description
namespace string auto Override the generated namespace (defaults to project name)
subFolderStrategy enum BySegment How to organize generated files in subfolders
versioningStrategy enum None None, QueryString, UrlSegment, Header
defaultApiVersion string "1.0" Default API version when unspecified
reportApiVersions bool true Include version info in response headers
assumeDefaultVersionWhenUnspecified bool true Use default version when client doesn't specify
useServersBasePath bool false Prepend base path from OpenAPI servers[0].url to routes
useGlobalErrorHandler enum Auto Auto, Enabled, Disabled β€” GlobalErrorHandlingMiddleware
useMinimalApiPackage enum Auto Auto, Enabled, Disabled β€” Atc.Rest.MinimalApi package

πŸ₯ Health Check Section

Setting Type Default Description
healthChecks.enabled bool false Generate health check endpoints
healthChecks.path string "/health" Base path for health endpoints
healthChecks.includeLiveness bool true Generate /health/live liveness probe
healthChecks.includeReadiness bool true Generate /health/ready readiness probe
healthChecks.security string "none" "none" or "apiKey" (query param + header)
healthChecks.apiKeyQueryParameterName string "api-key" Query parameter name for API key
healthChecks.apiKeyHeaderName string "X-Health-Api-Key" Header name for API key

πŸ’‘ When security: "apiKey", the API key is read from IConfiguration["HealthChecks:ApiKey"] at runtime. If the config value is empty, the filter passes through (no security).

⚠️ If your OpenAPI spec already defines paths under the health check base path (e.g., /health), the generator emits a ATC_API_DEP009 warning about duplicate endpoint registration.

πŸ–₯️ Server Domain Section

Setting Type Default Description
generateHandlersOutput string "Handlers" Directory for generated handler scaffolds
handlerSuffix string "Handler" Suffix for handler class names
stubImplementation string "NotImplementedException" Default stub: NotImplementedException or TodoComment
injectLogger bool false Inject ILogger<T> constructor parameter into handler scaffolds
injectTracing bool false Inject ActivitySource for OpenTelemetry distributed tracing
maxLineLength int 80 Max line length for code formatting. Match dotnet_diagnostic.ATC201.max_line_length in .editorconfig

πŸ”Œ Client Section

Setting Type Default Description
namespace string auto Override the generated namespace
generationMode enum EndpointPerOperation EndpointPerOperation or TypedClient
clientSuffix string "Endpoint" Suffix for client/endpoint class names
httpClientName string auto Override the IHttpClientFactory named client
generatePartialModels bool false Generate partial records for extensibility
generateOAuthTokenManagement bool false Generate OAuth token refresh infrastructure
useServersBasePath bool true Prepend base path from OpenAPI servers[0].url to URLs
includePaths string[] [] Glob patterns to include (e.g., ["/pets/*", "/users/*"])
excludePaths string[] [] Glob patterns to exclude (e.g., ["/internal/*"])

πŸ”„ Marker Files vs Options File

The generator supports two configuration approaches:

Approach Best For How It Works
Marker files (.atc-rest-api-server, etc.) Simple projects JSON config embedded in the marker file, per-project
ApiGeneratorOptions.json Multi-project solutions Shared config file, referenced by marker files or auto-discovered

Marker file settings override options file settings when both are present.

πŸ’‘ See Marker Files for the complete marker file reference.


πŸ”— Related Guides

🏠 Home

πŸ’Ό Why This Tool?

πŸ“– Getting Started

βš™οΈ Features

🌐 Frontend

πŸ“‹ Reference


πŸ”— Resources

Clone this wiki locally