跳到导航

Rust configuration

以 Markdown 格式查看
You're viewing the legacy SDK docs

These pages cover SDK generation configured with generators.yml. New projects use sdk-config.yml, so see the Current version of this page for up-to-date guidance. To move an existing project, follow the SDK Config migration guide, which walks through fern sdk migrate, and review the sdk-config.yml reference.

You can customize the behavior of the Rust SDK generator in generators.yml:

generators.yml
groups:
rust-sdk:
generators:
- name: fern-rust-sdk
version: 0.53.3
config:
clientClassName: YourClientName
crateName: your-crate-name
crateVersion: "1.0.0"
dateTimeType: "offset"
environmentEnumName: YourEnvironment
enableWireTests: true
clientClassName
string

The name of the generated client struct. This allows you to customize the struct name that users will instantiate when using your SDK.

crateName
string

The name of the generated Rust crate. This is used in Cargo.toml and determines how users will add your SDK as a dependency. By default, hyphens become underscores in the package name (my-sdk publishes as my_sdk); set preserveCrateNameHyphens to keep them.

crateVersion
string

The version of the generated crate. This is used in Cargo.toml for publishing to crates.io.

dateTimeType
'offset' | 'utc'Defaults to offset

Determines how timezone information is handled:

  • offset: Uses DateTime<FixedOffset> to preserve the original timezone from API responses
  • utc: Uses DateTime<Utc> to normalize all datetimes to UTC regardless of their original timezone

Both options accept any datetime format and assume UTC if no timezone is provided in the datetime string.

environmentEnumName
string

The name of the generated environment enum. This allows you to customize the enum name that defines your API environments (such as production, staging, development).

enableWebsockets
booleanDefaults to false

Enable generation of WebSocket clients for APIs with WebSocket channels.

enableWireTests
booleanDefaults to false

When enabled, generates mock server (wire) tests to verify that the SDK sends the correct HTTP requests and correctly handles responses per the API spec.

generateExamples
booleanDefaults to true

When enabled, generates code examples in the README and reference documentation.

maxRetries
number

The default number of retries for failed requests. When not set, the generated SDK defaults to 3 retries. SDK users can still override this per-request via request options.

preserveCrateNameHyphens
booleanDefaults to false

Keeps hyphens from crateName in the Cargo package name. By default, the generator converts every run of hyphens and underscores to a single underscore, so crateName: my-sdk produces name = "my_sdk" in Cargo.toml. crates.io treats hyphenated and underscored spellings as the same crate, so enable this option when your crate is already published under a hyphenated name.

generators.yml
config:
crateName: my-sdk
preserveCrateNameHyphens: true

The hyphenated name applies to the Cargo.toml package name, the default description and docs.rs documentation URL, the default crates.io publish package name, and the README install snippet (cargo add my-sdk). The name is still lowercased, invalid characters are replaced, repeated separators are collapsed, and leading or trailing separators are trimmed. Rust code continues to import the crate by its underscored name (use my_sdk::prelude::*), since Cargo maps a hyphenated package name to an underscored library name. When crateName isn’t set, the default name derived from your organization and API name also keeps its hyphens.

respectOptionalRequestBody
booleanDefaults to false

Lets callers omit the request body on endpoints with an optional request body. The method takes the body as an Option, and a call that passes None 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.

Only applies to request bodies declared as a single named type that the endpoint takes on its own. Required bodies, bodies folded into a request wrapper, and inlined request properties are unaffected.

userAgentFromPlatformHeaders
booleanDefaults to false

Sets the default ClientConfig.user_agent to the platform User-Agent value that Fern computes for the SDK, matching the other Fern SDKs. By default, the Rust SDK uses "<ApiName> Rust SDK" (the API name in PascalCase) and ignores the user-agent template.

With this option enabled, the default user agent is <package-name>/<version>, or the resolved user-agent template when one is set. The template supports the {packageName}, {version}, {language}, {generatorVersion}, {organization}, and {apiName} placeholders and is resolved at generation time.

generators.yml
config:
userAgentFromPlatformHeaders: true
user-agent: "plantstore-rust-sdk/{version}"

This sets the default user agent to plantstore-rust-sdk/0.1.0. When Fern has no platform User-Agent value for the generation (for example, when the SDK version isn’t known), the default falls back to "<ApiName> Rust SDK".

Package metadata

Configure metadata for publishing to crates.io:

generators.yml
config:
packageDescription: "SDK for the Plant Store API"
packageLicense: "MIT"
packageRepository: "https://github.com/your-org/your-sdk"
packageDocumentation: "https://docs.example.com"
packageDescription
string

A description of the crate for crates.io. This appears in the crate’s metadata and search results.

packageLicense
string

The license identifier for the crate (e.g., “MIT”, “Apache-2.0”).

packageLicenseFile
string

Path to a custom license file (e.g., LICENSE.md). When set, uses license-file instead of license in Cargo.toml. This is useful when your license isn’t a standard Software Package Data Exchange (SPDX) identifier.

packageRepository
string

The URL of the crate’s source repository.

packageDocumentation
string

The URL of the crate’s documentation.

Dependencies

Add custom dependencies to your generated SDK:

generators.yml
config:
extraDependencies:
tokio: "1.0"
serde_json: "1.0"
extraDevDependencies:
mockall: "0.11"
extraDependencies
object

Additional dependencies to include in the generated Cargo.toml. Specify as a map of crate names to version requirements. You can also specify full dependency specifications with features and default features:

generators.yml
config:
extraDependencies:
reqwest:
version: "0.12"
defaultFeatures: true
generators.yml
config:
extraDependencies:
reqwest:
version: "0.12"
features: ["rustls-tls"]
extraDevDependencies
object

Additional dev dependencies to include in the generated Cargo.toml. These are only used during development and testing.