Skip to content

Type Mapping

This reference documents how the code generator maps OpenAPI schema types to C# types.

OpenAPI TypeFormatC# Type
string(none)string
stringdate-timeDateTimeOffset
stringdateDateOnly
stringtimeTimeOnly
stringdurationTimeSpan
stringuuidGuid
stringuriUri
stringbytebyte[]
stringbinaryStream
OpenAPI TypeFormatC# Type
integer(none)int
integerint32int
integerint64long
OpenAPI TypeFormatC# Type
number(none)double
numberfloatfloat
numberdoubledouble
numberdecimaldecimal
OpenAPI TypeC# Type
booleanbool

Objects with named properties are generated as C# record types:

# Input
MyModel:
type: object
properties:
name:
type: string
// Output
public record MyModel
{
[JsonPropertyName("name")]
public string? Name { get; init; }
}

Array types are mapped to generic collections:

ConfigurationC# Type
UseImmutableArrays = true (default)IReadOnlyList<T>
UseImmutableArrays = falseList<T>
# Input
tags:
type: array
items:
type: string
// Output (default)
public IReadOnlyList<string>? Tags { get; init; }
// Output (mutable)
public List<string>? Tags { get; init; }

String enums are generated as C# enum types:

# Input
Status:
type: string
enum: [active, inactive, pending]
// Output (StringEnums = true)
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum Status
{
[JsonStringEnumMemberName("active")]
Active,
[JsonStringEnumMemberName("inactive")]
Inactive,
[JsonStringEnumMemberName("pending")]
Pending,
}

allOf schemas are flattened into a single record with all properties merged. If a $ref is included, properties from the referenced schema are included:

# Input
Animal:
type: object
properties:
name:
type: string
Dog:
allOf:
- $ref: '#/components/schemas/Animal'
- type: object
properties:
breed:
type: string
// Output
public record Dog
{
[JsonPropertyName("name")]
public string? Name { get; init; }
[JsonPropertyName("breed")]
public string? Breed { get; init; }
}

oneOf and anyOf schemas generate a record that can hold any of the variant types. Since C# doesn’t have native union types, these are represented as records with the combined properties or as object fallbacks.

Properties are made nullable (T?) when:

  1. The property is not listed in required
  2. The schema explicitly includes nullable: true
  3. The schema type includes null in the type array

Properties are non-nullable (or use required) when:

  1. Listed in the required array
  2. Have a default value (when DefaultNonNullable = true)

Schema references ($ref: '#/components/schemas/MyType') are resolved to the C# type name of the referenced schema. The reference ID is converted to PascalCase:

OpenAPI ReferenceC# Type
$ref: '#/components/schemas/User'User
$ref: '#/components/schemas/pet-status'PetStatus
$ref: '#/components/schemas/API_Response'ApiResponse

Schema names and property names are converted to valid C# identifiers:

  • Type names: PascalCase (user-profileUserProfile)
  • Property names: PascalCase (first_nameFirstName)
  • Enum members: PascalCase (in_progressInProgress)
  • C# keywords are escaped (class@Class)
  • Digit-leading names are prefixed with _ (123abc_123abc)