[ruby] fix: enumUnknownDefaultCase declares the unknown-default member but never deserializes to it

Merged
WI
2mo ago
+59-0

With enumUnknownDefaultCase=true, the ruby client adds UNKNOWN_DEFAULT_OPEN_API to every enum class's constants and all_vars, but the enum's own build_from_hash still raises for any value outside the list:

RuntimeError: Invalid ENUM value SOMETHING_NEW for class #DomainStatus

So a response carrying a newer value of a $ref'd enum still fails as a whole. Reproduced on current master.

Fix

partial_model_enum_class.mustache, with the flag on:

def build_from_hash(value)
  return value if DomainStatus.all_vars.include?(value)
  UNKNOWN_DEFAULT_OPEN_API
end

The fallback is the last declared enum var, which with the flag is always the injected member (an integer enum keeps its existing name, Nunknown_default_open_api). Output without the flag is byte-identical.

Verification (ruby 3.3, DomainStatus: [ACTIVE, INACTIVE], Domain.status: $ref, flag on)

masterthis PR
DomainStatus.build_from_hash('SOMETHING_NEW')raises RuntimeErrorreturns "unknown_default_open_api"
Domain.build_from_hash('status' => 'SOMETHING_NEW')raises RuntimeErrorstatus is "unknown_default_open_api"

Tests

Two new RubyClientCodegenTest cases on the existing 3_0/enum.yaml (string and integer enums): with the flag, build_from_hash falls back instead of raising (fails without the fix); without it, it still raises exactly as today.

Known gaps

Inline enum properties still raise with the flag on: the generated attribute writer (partial_model_generic.mustache, def status=(status)) validates strictly, and build_from_hash goes through it. Only $ref'd enum classes are fixed here; the writer is a follow-up.

PR checklist

  • Read the contribution guidelines.
  • Built the project and updated samples (./bin/generate-samples.sh ./bin/configs/ruby*.yaml). No sample changed: none enables enumUnknownDefaultCase.
  • Technical committee: @cliffano @zlx @autopp

Summary by cubic

Fixes the Ruby client's enumUnknownDefaultCase handling so unknown enum values deserialize to the unknown-default member instead of raising, preserving the flag's promise that new server values don't break the whole response.

  • With enumUnknownDefaultCase=true, build_from_hash now returns the unknown-default enum member instead of raising RuntimeError.
  • Without the flag, generated code is byte-identical to before and still raises on unknown values.
  • Adds tests covering both flag-on and flag-off paths, including the integer enum's numeric-prefixed unknown-default member.

Generated with Claude Code