Add Smithy intermediate model builder and mojo activation - #7279
Open
Fred1155 wants to merge 1 commit into
Open
Conversation
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.
Motivation and Context
This builds an
IntermediateModelfrom a Smithy model, and teaches the Maven mojo to use it when amodel.jsonis present. It's a port of C2J'sIntermediateModelBuilder.The fastest way to review it is to open
IntermediateModelBuildernext toSmithyIntermediateModelBuilderand work through the phase table below. Most of it is line-for-line. Four places needed real thought, and five C2J steps are missing on purpose.Modifications
smithy/SmithyIntermediateModelBuilder.javaIntermediateModelIntermediateModelBuildersmithy/SmithyModels.javaC2jModelsmaven/plugin/GenerationMojo.javamodel.jsonpresentcodegen-maven-plugin/pom.xmlsmithy-modelRemoveUnusedShapes.javafinal→public finalThere's no
codegen/pom.xmlchange, becausesmithy-model,smithy-aws-traitsandsmithy-rules-engineare already compile dependencies there. The plugin module did needsmithy-modeldeclared, since it now importsModeldirectly instead of picking it up transitively fromcodegen.The only thing that reaches this builder is the mojo, and only for a model root that contains a
model.json. No shipped service has one, so generated output doesn't change.Build phases
AddOperations→TreeMapAddSmithyOperations→TreeMapendpointCacheRequiredremoveIfIntermediateModelremoveUnusedShapes+ deprecated shapesD1 — four shape processors where C2J has six. C2J runs
AddEmptyInputShapeandAddEmptyOutputShapeas extra passes to invent request and response shapes for operations that declare none. The Smithy input and output processors do it inline, checking forsmithy.api#Unitand callingsynthesizeEmptyRequestorsynthesizeEmptyResponse. Diffing the chains looks like a dropped step; the work just happens in one pass instead of two.D2 — two linking methods read the built model instead of the raw one. C2J's versions reach back into its
ServiceModel, which doesn't exist here.linkCustomAuthorizationToRequestShapesreadsoperation.getAuthType()off theOperationModel— the same value, sinceAddSmithyOperations.translateAuthsets it from the source C2J reads.linkOperationsToInputOutputShapeskeys onsmithy.api#Unitrather than C2J'sgetOutput() != null, which is how Smithy expresses "no output". Theop != nullguard beside it is unreachable.D3 —
clientContextParamsis translated fromsmithy.rules#clientContextParams. This is the only behaviour the PR adds beyond wiring. It's not an internal field: it generates a public builder method per param, plus the key class and the endpoint-resolution wiring, so leaving it null silently removes public API rather than producing a subtly wrong model.Two choices worth a look. It returns null rather than an empty map when the trait is absent, matching C2J, where an empty map would serialise as
{}and read as a diff. And it sorts by name, because this map decides generated builder-method order and the trait's key order is arbitrary where C2J's happens to be alphabetical.Set by C2J, not here
Five steps are missing on purpose. Taken together they're the main limit on what this builder can currently handle.
customization.preprocess(service)customization.postprocess(fullModel)paginators.getPagination()Collections.emptyMap()waiters.getWaiters()Collections.emptyMap()customizeEndpointParameters,customizeOperationContextParamsThe endpoint rule set and endpoint tests still come from the sidecar JSON files, passed through
SmithyModelsuntouched, even though the model carries@smithy.rules#endpointRuleSetand@smithy.rules#endpointTestsinline.following PR will prefer the trait and fall back to the sidecar.
Testing
Implemented parity fixture test, but not in this PR to keep it clean to review.
Screenshots (if appropriate)
Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions. Commit the new file created by the script in.changes/next-releasewith your changes.License