smithy-lang / smithy

Smithy is a protocol-agnostic interface definition language and set of tools for generating clients, servers, and documentation for any programming language.
https://smithy.io
Apache License 2.0
1.7k stars 201 forks source link

Missing smithy-trait-codegen union support #2268

Open msosnicki opened 2 months ago

msosnicki commented 2 months ago

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 https://github.com/smithy-lang/smithy/blob/1805e515bc3877a02aa8351da1a7ea62e92a2c8f/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/TraitCodegenSymbolProvider.java#L184.

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

Thanks

hpmellema commented 2 months ago

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

joelvanderhoof commented 1 month ago

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

Will this include traits to support untagged and discriminated unions?

hpmellema commented 1 month ago

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.

msosnicki commented 1 month ago

@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 {}
hpmellema commented 1 month ago

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