Skip to content

Naming Strategies

Use @OpenApiNaming to automatically transform property and enum value names in the generated schema, similar to Jackson's @JsonNaming.

Class-level Naming

Apply @OpenApiNaming on a class to transform all property names:

kotlin
@OpenApiNaming(OpenApiNamingStrategy.SNAKE_CASE)
class UserProfile {
    val firstName: String = ""    // → "first_name"
    val lastName: String = ""     // → "last_name"
    val emailAddress: String = "" // → "email_address"
}

Available Strategies

StrategyInputOutput
DEFAULTfirstNamefirstName (no change)
SNAKE_CASEfirstNamefirst_name
KEBAB_CASEfirstNamefirst-name

Per-property Override

@OpenApiName on a property always takes priority over the class-level strategy:

kotlin
@OpenApiNaming(OpenApiNamingStrategy.SNAKE_CASE)
class UserProfile {
    val firstName: String = ""  // → "first_name" (from strategy)

    @OpenApiName("ID")
    val id: String = ""         // → "ID" (explicit override)
}

Enum Naming

@OpenApiNaming also works on enum classes to transform value names:

kotlin
@OpenApiNaming(OpenApiNamingStrategy.KEBAB_CASE)
enum class StatusCode {
    NOT_FOUND,       // → "not-found"
    BAD_REQUEST,     // → "bad-request"
    INTERNAL_ERROR   // → "internal-error"
}

Use @OpenApiName on individual values to override specific entries:

kotlin
@OpenApiNaming(OpenApiNamingStrategy.KEBAB_CASE)
enum class StatusCode {
    NOT_FOUND,                       // → "not-found"

    @OpenApiName("custom-value")
    BAD_REQUEST,                     // → "custom-value"

    INTERNAL_ERROR                   // → "internal-error"
}

See Enums for more enum customization options.