Speakeasy Logo
Skip to Content

Control Property Naming and Casing

TypeScript SDKs support configurable property naming to match your API’s field naming conventions. You can either normalize property names to a consistent casing style, or preserve the exact names from your OpenAPI spec.

Property Casing

Use modelPropertyCasing to control whether generated TypeScript types use camelCase or snake_case property names.

Configuration

<sdk-root>/.speakeasy/gen.yaml
typescript: modelPropertyCasing: "camel" # or "snake"

Options

  • camel (default): Properties use camelCase naming (e.g., firstName, createdAt)
  • snake: Properties use snake_case naming (e.g., first_name, created_at)

Examples

camelCase naming (default)

// Configuration: modelPropertyCasing: "camel" export type User = { id: string; firstName: string; lastName: string; emailAddress: string; createdAt: Date; isActive: boolean; };

snake_case naming

// Configuration: modelPropertyCasing: "snake" export type User = { id: string; first_name: string; last_name: string; email_address: string; created_at: Date; is_active: boolean; };

Preserve Original Property Names

Use preserveModelFieldNames to keep the exact property names from your OpenAPI spec without any normalization. This is useful when:

  • Your API uses unconventional naming (e.g., properties starting with _)
  • You need exact parity with existing SDKs or API documentation
  • Your property names have special meaning that would be lost through normalization

Configuration

<sdk-root>/.speakeasy/gen.yaml
typescript: preserveModelFieldNames: true

Example

Given an OpenAPI spec with these properties:

components: schemas: Event: type: object properties: _raw: type: string __metadata: type: object event_type: type: string EventID: type: string

Without preservation (default):

// preserveModelFieldNames: false (default) // Properties are normalized based on modelPropertyCasing export type Event = { raw: string; // Leading underscores removed metadata: object; // Leading underscores removed eventType: string; // Converted to camelCase eventId: string; // Converted to camelCase };

With preservation:

// preserveModelFieldNames: true // Properties match OpenAPI spec exactly export type Event = { _raw: string; // Preserved with underscore __metadata: object; // Preserved with underscores event_type: string; // Preserved as snake_case EventID: string; // Preserved as PascalCase };

When to Use

ScenarioRecommendation
Standard APIs with conventional namingUse modelPropertyCasing (default)
APIs with leading underscores (e.g., _raw, _links)Use preserveModelFieldNames: true
Migrating from existing SDK with specific field namesUse preserveModelFieldNames: true
Mixed naming conventions that must be preservedUse preserveModelFieldNames: true

Last updated on