Skip to content

feature request: Add support for int enums #279

@ghostbuster91

Description

@ghostbuster91

Motivation

When translating from OpenAPI to Smithy, schemas that define enums with an integer type (e.g. type: integer + enum: [...]) are currently mapped to plain enum in Smithy which is incorrect.

Expected behavior

Given an OpenAPI schema like:

Status:
  type: integer
  enum: [0, 1, 2]
  x-enum-varnames:
    - PENDING
    - ACTIVE
    - ARCHIVED

The generated Smithy model should be:

intEnum Status {
  PENDING  = 0
  ACTIVE   = 1
  ARCHIVED = 2
}

Current behavior

The same schema is currently translated into:

enum Status {
  PENDING
  ACTIVE
  ARCHIVED
}

Why x-enum-varnames?

OpenAPI itself does not support named integer enums directly.

The common convention (used by OpenAPI Generator, Swagger Codegen, etc.) is to combine:

type: integer
enum: [...]
x-enum-varnames: [...] (vendor extension to preserve symbolic names)

This provides both wire values (integers) and stable names for code generation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions