smithy-lang/smithy

Missing smithy-trait-codegen union support

Opened this issue · 5 comments

We're using the new smithy-trait-codegen module to generate the java trait files for the protocols. Seem that the unions are not supported yet

throw new UnsupportedOperationException("Union shapes are not supported at this time.");
.

Is it something on the radar for the upcoming releases? If not, would contribution speed up the process?

Thanks

We do have plans to add support for union traits in a future release.

We do have plans to add support for union traits in a future release.

Will this include traits to support untagged and discriminated unions?

The support for union traits mentioned here is for generating the java implementation of custom Smithy Union traits such as:

@trait 
union MyUnion {
    option1: String 
    option2: Integer
}

I was not referring to adding additional behavior traits to modify the behavior of Smithy unions. Support for union trait generation will not include anything relating to untagged unions.

@hpmellema Will it also support the following case?

@trait
structure MyTrait {
    union: MyUnion
} 
union MyUnion {
    option1: String 
    option2: Integer
}

During decoding, it would work only for tagged unions, right? For example:

@MyTrait(
    union: {
        option1: "Foo"
    }
}
structure StructWithTrait {}

Yes, we plan to support nested unions within trait definitions, and yes, on node deserialization only tagged unions would be supported.