Repository navigation
Conversation
|
|
||
| public static SmithyIntermediateModelPostprocessor create(CustomizationConfig config) { | ||
| List<CodegenCustomizationProcessor> processors = new ArrayList<>(); | ||
| processors.add(new MetadataModifiersProcessor(config.getCustomServiceMetadata())); |
There was a problem hiding this comment.
I think there might be a small gap here. MetadataModifiersProcessor has two halves. postprocess applies contentType (now wired up). preprocess applies customServiceMetadata.protocol by overwriting ServiceMetadata.protocols — and this chain only ever calls postprocess, so on the Smithy path protocol is silently ignored. The only user in our services of protocol is Kinesis - but could potentially impact custom internal services....
I'd lean towards a fail fast check: throw in SmithyIntermediateModelPostprocessor.create when customServiceMetadata.protocol is non-null on the Smithy path (with a message pointing at addTraits + protocol traits which are the correct (and now supported) smithy way to handle this).
There was a problem hiding this comment.
For this one, I have another PR #7442 to apply this preprocessing just for kinesis. And the old CBOR protocol has no Smithy trait..
69bb469
into
feature/master/smithy-migration
|
This pull request has been closed and the conversation has been locked. Comments on closed PRs are hard for our team to see. If you need more assistance, please open a new issue that references this one. |
Motivation and Context
On the Smithy path, a service's customizations are applied as smithy-build transforms listed in its
smithy-build.json. For example, a transform renames S3'sCopyObjectRequest.Bucketmember toDestinationBucket. Some customizations also have a part that only affects the generated Java and says nothing about the service. For example, S3 also keeps a deprecatedbucket()accessor next to the newdestinationBucket(), so existing callers still compile. Smithy has no standard trait for that.This PR lets those Java-only settings travel through the model as traits, so the translator can read them from the member or shape they apply to. These are the settings, from
customization.configshapeModifiersandcustomSdkShapes:existingNameDeprecatedalternateBeanPropertyNameignoreDataTypeConversionFailuresemitEnumNamecustomSdkShapesModifications
addTraitstransform (AddTraitsTransformer, registered with the other codegen transforms)Codegen traits (new, namespace
software.amazon.awssdk.codegen)deprecatedName(string)alternateBeanPropertyName(string)set<value>ignoreDataTypeConversionFailuresenumConstantName(string)syntheticsyntheticon members that target the shapeMETA-INF/smithy/aws-sdk-java-codegen-traits.smithy. Each trait's selector limits where it can be applied, and Smithy reports any other use as a validation error.codegen/.../smithy/traits/, registered inMETA-INF/services/software.amazon.smithy.model.traits.TraitService. The classes are needed because the codegen transforms build traits with Smithy'sTraitFactory, which rejects a trait ID with no registered class.Translator
SmithyCodegenTraitsapplies each trait to the intermediate model, setting the same fields as C2J'sAddShapes: one method per member trait, and one that returns an enum constant's name.AddSmithyShapescalls it once per trait when it builds a member, and in the loop that builds an enum's constants. Without the trait, a member or enum constant is built as before.Postprocessor (
SmithyIntermediateModelPostprocessor)MetadataModifiersProcessor, which copiescustomServiceMetadata.contentTypefromcustomization.configinto the intermediate model metadata, as on the C2J path. Only Kinesis uses this in our repo.contentTypeapplies to the whole service, so it stays incustomization.configand does not become a trait.Not in this PR
smithy-build.jsonfrom a service'scustomization.configcomes in a follow-up PR, and it emits these traits. Until then nothing in the build adds them, so this PR changes no generated client.Testing
AddTraitsTransformerTest: adds a member trait and replaces an existing one; adds a shape trait; fails on a missing shape and on an unknown trait.SmithyCodegenTraitsTest: each trait ID creates its Java class; the trait definitions are found throughdiscoverModels; a trait outside its selector is a validation error.SmithyCodegenTraitsTranslationTest: each trait reaches the right intermediate-model field;deprecatedNameon a list member fails, as on C2J;contentTypereaches the metadata.SmithyBuildTransformsTest.codegenTraits_reachTheIntermediateModel: traits added through a real smithy-build run reach the intermediate model.SmithyIntermediateModelPostprocessorTest.javaOnlyShapeModifiersInConfigWithoutTraits_leaveTheModelUnchanged: the Smithy path no longer reads these settings fromcustomization.config.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