Update codegen to support closure-based generation#1260
Draft
JordonPhillips wants to merge 3 commits into
Draft
Conversation
This updates the code generators to support generating based on shape closures. Shape closures are a new way to define a set of shapes to generate in the model without rooting that set at a service shape. This has implications that cause some chages throughout the generator. Notably, a service might not exist. There are a number of places that required a service shape to exist that had to be updated to tolerate it being missing. Notably renames may now be driven through the closure definition itself rather than a service shape, so renames needed to be passed through in a lot of generator classes. Previously types codegen was implemented by creating a synthetic service shape and/or operation and attaching the shapes to it. The generator would then skip those synthetic shapes so that no unwanted scaffolding was generated. That whole system was removed. Another important implication of shape closures is that a closure can have multiple services. For now, smithy-java is keeping the restriction to have exactly 0 or 1 services. Supporting multiple can be done down the line if there's a need.
mtdowling
requested changes
Jun 23, 2026
mtdowling
left a comment
Member
There was a problem hiding this comment.
I think this is just missing an example using the new closure setting
mtdowling
reviewed
Jun 25, 2026
| "namespace": "software.amazon.smithy.java.example.closure", | ||
| "headerFile": "license.txt", | ||
| "modes": ["server", "types"], | ||
| "closure": "smithy.example.birds#fullService" |
Member
There was a problem hiding this comment.
Does closure apply to all modes?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What behavior changes?
This updates the code generators to support generating based on shape closures. Shape closures are a new way to define a set of shapes to generate in the model without rooting that set at a service shape.
This has implications that cause some chages throughout the generator. Notably, a service might not exist. There are a number of places that required a service shape to exist that had to be updated to tolerate it being missing. Notably renames may now be driven through the closure definition itself rather than a service shape, so renames needed to be passed through in a lot of generator classes.
Previously types codegen was implemented by creating a synthetic service shape and/or operation and attaching the shapes to it. The generator would then skip those synthetic shapes so that no unwanted scaffolding was generated. That whole system was removed.
Another important implication of shape closures is that a closure can have multiple services. For now, smithy-java is keeping the restriction to have exactly 0 or 1 services. Supporting multiple can be done down the line if there's a need.
Why is this change needed?
Shape codegen is a general feature that Smithy customers have wanted for a long time. Model-defined closures make that possible in a way that shares the definition across generators and removes the need for hacks like the existing synthetic service / operation plumbing.
How was this validated?
Tests were added, including new integ tests. Existing types codegen codgen settings were kept.
What should reviewers focus on?
Existing types codegen behavior should be preserved. There are surely some subtleties of the previous behavior that I've missed, particularly in the mixed mode case.
Additional Links
This needs smithy-lang/smithy#3156 to build successfully.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.