Skip to content

SDK generation fails when the value type of the enum is integer #5343

@welovej

Description

@welovej

Hi team,

We encountered a generation failure in the SDK pipeline when typespec defines the following extensible enum:

/**
 * The minute element of the time. Allowed values are 0 and 30. If not specified, its value defaults to 0.
 */
union Minute {
  integer,
  #suppress "@azure-tools/typespec-azure-core/documentation-required" "For backward compatibility"
  `0`: 0,
  #suppress "@azure-tools/typespec-azure-core/documentation-required" "For backward compatibility"
  `30`: 30,
}

This schema causes a failure during SDK generation due to a mismatch in the type resolution logic. The code that fails looks like this:
Location

InputEnumTypeValue enumValue = valueType.Kind switch
{
    InputPrimitiveTypeKind.String => new InputEnumTypeStringValue(name, rawValue.Value.GetString() ?? throw new JsonException(), valueType, enumType, summary, doc) { Decorators = decorators ?? [] },
    InputPrimitiveTypeKind.Int32 => new InputEnumTypeIntegerValue(name, rawValue.Value.GetInt32(), valueType, enumType, summary, doc) { Decorators = decorators ?? [] },
    InputPrimitiveTypeKind.Float32 => new InputEnumTypeFloatValue(name, rawValue.Value.GetSingle(), valueType, enumType, summary, doc) { Decorators = decorators ?? [] },
    _ => throw new JsonException()
};

Problem

In this case, valueType.Kind is InputPrimitiveTypeKind.Integer, which does not match any of the expected InputPrimitiveTypeKind.Int32, String, or Float32, causing the fallback _ => throw new JsonException() to be triggered.

This happens because the typespec int32 union does not explicitly indicate a format, and the generator attempts to map it to InputPrimitiveTypeKind.Integer, which is not handled in the switch statement.

Related TCGC issue

Link

Thanks!

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