Skip to content

Added support for getter sections in unions codegen#1229

Open
timocov wants to merge 1 commit into
smithy-lang:mainfrom
timocov:union-getter-section
Open

Added support for getter sections in unions codegen#1229
timocov wants to merge 1 commit into
smithy-lang:mainfrom
timocov:union-getter-section

Conversation

@timocov
Copy link
Copy Markdown
Contributor

@timocov timocov commented Jun 5, 2026

What behavior changes?

This PR adds GetterSection to getter of union variant classes.

Why is this change needed?

One of the places where GetterSection helps is when you want to add custom annotations to getters. For instance, when integrating generated code with jakarta validation in Spring Boot, complex fields require to have @Valid annotation attached in order to be validated (e.g. to run full depth validation). Currently, GetterSection is not "emitted" which means that union member getters aren't being processed and it is possible to add @Valid annotation in this case.

How was this validated?

I changed to code locally, run gw pTML, run the codegen, spin up a spring boot application and validated that the request is being validated correctly.

What should reviewers focus on?

Should I use

writer.pushState();
writer.injectSection(new GetterSection(member));

instead to avoid people accidentally removing the content of the method?

Also, should I do the same for enums?

Additional Links

N/A.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@adwsingh
Copy link
Copy Markdown
Contributor

adwsingh commented Jun 6, 2026

I wonder if the better design here is to generically be able to add support for custom Annotations in the codegen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants