.NET configuration

View as Markdown

You can customize the behavior of the C#/.NET SDK generator in generators.yml:

generators.yml
1groups:
2 csharp-sdk:
3 generators:
4 - name: fern-csharp-sdk
5 version: 2.83.2
6 config:
7 client-class-name: YourApiClient
auto-generate-idempotency-key
boolean | objectDefaults to false

Overrides the API-wide api.settings.auto-generate-idempotency-key for this SDK. Set true to attach an idempotency-key header to eligible requests (POST and PUT by default) unless the caller provides one, or false to opt this SDK out when auto-generation is enabled API-wide. Pass an object to customize header-name and methods.

base-api-exception-class-name
string

Customizes the name of the base API exception class that all API-specific exceptions will inherit from. This allows you to define a custom base exception class name for better integration with your existing error handling patterns.

base-exception-class-name
string

Specifies the name of the base exception class that all generated exceptions will inherit from. This provides a common parent class for all SDK exceptions, enabling consistent exception handling patterns.

client-class-name
string

Sets the name of the generated API client class. This determines the primary client type name that users will interact with in the generated .NET SDK.

custom-pager-name
string

Customizes the name of the pagination helper class used for handling paginated API responses. This allows you to specify a custom name that fits your naming conventions.

default-timeout-in-milliseconds
number | 'infinity'Defaults to 30000

The default timeout for network requests, in milliseconds. Set to infinity to disable the default timeout. SDK users can still override this per request by passing RequestOptions.Timeout.

enable-forward-compatible-enums
boolean

When enabled, generates enum types that can handle unknown values. This allows the SDK to process new enum values that may be added to the API without breaking existing client code, improving forward compatibility.

enable-wire-tests
booleanDefaults to true

Generates mock server (wire) tests to verify that the SDK sends and receives HTTP requests as expected.

environment-class-name
string

Specifies the name of the environment configuration class used for managing different API environments (e.g., development, staging, production).

explicit-namespaces
boolean

When enabled, generates code with explicit namespace declarations throughout the SDK. This can help avoid naming conflicts and improve code clarity in larger projects.

exported-client-class-name
string

Sets the name of the exported client class that will be used in code examples and documentation. This is useful for customizing how the client appears in generated documentation.

generate-documentation-file
booleanDefaults to true

Controls whether the generated project emits an XML documentation file. When enabled, the published package ships lib/<framework>/<namespace>.xml, which supplies IntelliSense to consumers of the SDK. CS1591 is suppressed, so public members without a documentation comment don’t produce build warnings.

generate-error-types
boolean

When enabled, generates specific error type classes for different API errors. This provides strongly typed error handling instead of using generic exception types.

generate-mock-server-tests
booleanDefaults to true

Alias for enable-wire-tests, retained for backward compatibility. Generates mock server (wire) tests to verify that the SDK sends and receives HTTP requests as expected.

include-exception-handler
boolean

When enabled, includes built-in exception handling utilities in the generated SDK. This provides convenience methods for common error handling scenarios.

inline-path-parameters
boolean

When enabled, path parameters are included as properties in the request object instead of being passed as separate method parameters. This creates a more unified request structure where all parameters are grouped together.

maxRetries
number

The default number of retries for failed requests. When not set, the generated SDK uses its own built-in default. SDK users can still override this per-request via request options.

namespace
string

Specifies the root namespace for all generated .NET code. This determines the namespace hierarchy that users will import when using the SDK.

offset-semantics
'item-index' | 'page-index'

Controls how the offset parameter is interpreted for auto-paginated endpoints.

  • item-index: The offset counts individual items (e.g., offset 20 skips the first 20 items).
  • page-index: The offset counts pages (e.g., offset 3 skips to page 3).
omit-fern-headers
booleanDefaults to false

When enabled, the generated SDK omits the X-Fern-Language, X-Fern-SDK-Name, and X-Fern-SDK-Version headers from HTTP requests.

include-platform-headers
booleanDefaults to false

When enabled, the generated SDK sends a single structured User-Agent header of the form {sdkName}/{version} ({os}; {arch}) {runtime}/{runtimeVersion} (for example, my-sdk/1.2.0 (linux; x86_64) dotnet/8.0.4), carrying SDK, operating system, architecture, and runtime information in place of the default User-Agent and discrete platform headers. A configured user-agent template supplies the leading product token. If omit-fern-headers is enabled, no User-Agent or platform headers are sent and this option has no effect.

allow-user-agent-app-info
booleanDefaults to false

When enabled, the generated SDK emits an AppInfo record and exposes it as an AppInfo property on ClientOptions, which appends a {Name}/{Version} ({Comment}) product token to the User-Agent header so an application built on the SDK can identify itself to the API. The application sets a required Name plus an optional Version and Comment; omitted or blank values are dropped from the token. An explicit User-Agent header takes precedence, and omit-fern-headers suppresses the header entirely.

1AppInfo = new AppInfo { Name = "partner-app", Version = "3.1.0", Comment = "+https://partner.example" }
2// User-Agent: my-sdk/1.2.0 (linux; x86_64) dotnet/8.0.4 partner-app/3.1.0 (+https://partner.example)
package-id
string

Sets the NuGet package identifier for the generated SDK. This is used when publishing the SDK to NuGet or other package repositories.

package-metadata
object

NuGet package metadata written into the generated project file, which determines how the package appears once it’s published to NuGet. Unset keys are omitted from the project file, leaving NuGet’s own defaults or the values Fern derives from the SDK’s GitHub output location.

generators.yml
1config:
2 package-metadata:
3 description: A .NET SDK for the Plantstore API.
4 authors:
5 - Plantstore
6 tags:
7 - plants
8 - sdk
9 copyright: Copyright (c) Plantstore, Inc.
10 repository-url: https://github.com/plantstore/plantstore-dotnet
11 include-source-link: true
12 include-symbols: true
package-metadata.description
string

Sets <Description>, the package description shown on nuget.org.

package-metadata.authors
string | List<string>

Sets <Authors>. A list is joined with commas.

package-metadata.tags
string | List<string>

Sets <PackageTags>, the search tags on nuget.org. A list is joined with semicolons.

package-metadata.copyright
string

Sets <Copyright>.

package-metadata.icon
string

Sets <PackageIcon> and packs the image into the package. The path is relative to the root of the generated SDK, and the image file must exist there: add it to the SDK repository and list it in .fernignore so generation doesn’t remove it.

package-metadata.project-url
string

Sets <PackageProjectUrl>, overriding the URL derived from the SDK’s GitHub output location.

package-metadata.repository-url
string

Sets <RepositoryUrl>, overriding the URL derived from the SDK’s GitHub output location.

package-metadata.repository-type
stringDefaults to git

Sets <RepositoryType>. Applies only when the package has a repository URL.

package-metadata.include-source-link
booleanDefaults to false

When enabled, adds a Microsoft.SourceLink.GitHub package reference and builds the package deterministically with embedded source information, so debuggers can step into the SDK’s sources.

package-metadata.include-symbols
booleanDefaults to false

When enabled, the build produces a .snupkg symbol package alongside the .nupkg.

read-only-memory-types
List<string>

Specifies a list of types that should be generated using ReadOnlyMemory<T> instead of regular arrays or collections. This can improve performance for large data transfers by reducing memory allocations.

redact-response-body-on-error
boolean

When enabled, prevents raw response bodies from leaking into exception messages and logs. Deserialization error exceptions pass null instead of the raw response body, and the base API exception class includes a custom ToString() override that excludes the response body.

respect-optional-request-body
booleanDefaults to false

Lets callers omit the request body on endpoints with an optional request body. A call that omits it sends no body and no Content-Type header, instead of an empty JSON object ({}). Enable this when your API treats a missing body differently from an empty one.

The body parameter is defaulted, and Body on a wrapped request is no longer required:

1Task<Plant> WaterPlantAsync(string plantId, WaterRequest? request = null, ...)

Only applies to request bodies declared as a single named type. Required bodies and inlined request properties are unaffected.

root-client-class-access
'public' | 'internal'

Controls the access modifier for the root client class. Use ‘public’ to make the client accessible from other assemblies, or ‘internal’ to restrict access within the same assembly.

root-namespace-for-core-classes
boolean

When enabled, places core SDK classes (like base client classes and utilities) in the root namespace instead of nested namespaces. This can simplify imports for commonly used types.

use-discriminated-unions
boolean

When enabled, generates discriminated union types for API responses that can contain multiple different object types. This provides type-safe handling of polymorphic responses.

user-agent
stringDefaults to {packageName}/{version}

Sets a custom User-Agent header template for requests sent by the generated SDK. The template is resolved at generation time and supports the {packageName}, {version}, {language}, {generatorVersion}, {organization}, and {apiName} placeholders.

generators.yml
1config:
2 user-agent: "plantstore-dotnet-sdk/{version}"

This sends User-Agent: plantstore-dotnet-sdk/0.1.0. With include-platform-headers enabled, the resolved value leads the structured header: User-Agent: plantstore-dotnet-sdk/0.1.0 (linux; x86_64) dotnet/8.0.4. A value that doesn’t end in a version, such as plantstore/sdk-dotnet, is used as-is. The allow-user-agent-app-info token is appended after either form.