Add Smithy shape subclasses for request, response, exception, and mod… - #7239
Open
Fred1155 wants to merge 1 commit into
Open
Add Smithy shape subclasses for request, response, exception, and mod…#7239Fred1155 wants to merge 1 commit into
Fred1155 wants to merge 1 commit into
Conversation
davidh44
reviewed
Aug 7, 2026
| for (OperationShape op : topDown.getContainedOperations(getService())) { | ||
| queue.add(op.getInputShape()); | ||
| queue.add(op.getOutputShape()); | ||
| queue.addAll(op.getErrors()); |
Contributor
There was a problem hiding this comment.
getErrors() only returns operation-level errors, should we call queue.addAll(getService().getErrorsSet()) after the loop?
nit: getErrors() is deprecated in favor of getErrorsSet()
Comment on lines
+92
to
+102
| for (MemberShape m : shape.members()) { | ||
| queue.add(m.getTarget()); | ||
| } | ||
| if (shape.isListShape()) { | ||
| queue.add(shape.asListShape().get().getMember().getTarget()); | ||
| continue; | ||
| } | ||
| if (shape.isMapShape()) { | ||
| queue.add(shape.asMapShape().get().getKey().getTarget()); | ||
| queue.add(shape.asMapShape().get().getValue().getTarget()); | ||
| continue; |
Contributor
There was a problem hiding this comment.
Seems like shape.members() covers all members already, and the subsequent queue.add() calls are redundant. Maybe we can just simplify to
if (shape.isListShape() || shape.isMapShape()) {
continue;
}
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
The previous PR #7218 added the AddSmithyShapes base class, which translates a single shape and its members. This PR adds the four concrete processors on top of it — the ones that decide which shapes to translate and stamp the type-specific fields (marshaller, unmarshaller, error code, HTTP status). Each is a port of the matching C2J processor: same output (Map<String, ShapeModel>), different input. Nothing is wired into generation yet.
Modifications
Files
smithy/AddSmithyInputShapes.javaShapeMarshallerAddInputShapes,AddEmptyInputShapesmithy/AddSmithyOutputShapes.javaShapeUnmarshallerAddOutputShapes,AddEmptyOutputShapesmithy/AddSmithyExceptionShapes.javaAddExceptionShapessmithy/AddSmithyModelShapes.javaAddModelShapesAddSmithyProcessorsTest(8),AddSmithyInputShapesTest(6),AddSmithyOutputShapesTest(3)Shape selection
serviceModel.getOperations()TopDownIndex.getContainedOperations(service)op.getInput() != null; null →AddEmptyInputShapesmithy.api#Unit→ synthesizedop.getOutput() != null; null →AddEmptyOutputShapeUnit→ synthesizedisException()OperationIndex.getErrors(service, op)— merged service + operation errors, skipping names already emittedNote the exception source is the merged error list, matching what the operation translator uses for
OperationModel.exceptions. Reading onlyop.getErrors()would skip service-level errors and leave an operation referencing an exception class with no shape.AddSmithyModelShapesadditionally skips prelude shapes and@errorshapes (owned by the exception processor). C2J skips exceptions the same way (getModelShapeTypereturns null forisException()).Union handling matches: C2J models a union as a structure, so it lands as
Model; the Smithy processor also maps union →Model(onlyisEnumShape→Enum).Request shape
C2J builds the marshaller in
Utils.createInputShapeMarshaller/createSyntheticInputShapeMarshaller.actionprotocolmetadata.getProtocol()verb/requestUriop.getHttp()@httpfor rest-json/rest-xml; elsePOST+/— D1targetmetadata.getTargetPrefix()+ operation namelocationName/xmlNameSpaceUriinputreferenceisSyntheticAddEmptyInputShapeUnitinputShapeModel.endpointDiscoveryop.getEndpointdiscovery()(AddInputShapes:82)ClientEndpointDiscoveryIndex.getEndpointDiscoveryInfo(service, op)endpointDiscoveryis set only on real input shapes; C2J'sAddEmptyInputShapedoes not set it, so synthesized empty requests stay null. BothSyncClientClass:310andAsyncClientClass:417read it off the request shape, guarded only by the operation-level field, so a null there fails codegen rather than producing a diff.For smithy-rpc-v2-cbor services the request URI produced here is /, while the C2J path produces /service/{targetPrefix}/operation/{OperationName}. C2J doesn't read that path from the model either, it also starts at /, and a customization processor (SmithyRpcV2CborProtocolProcessor) rewrites it afterwards. That processor hasn't been ported to the Smithy side yet, and it closes when the customization processors land, at which point the same rewrite applies to both paths.
Response shape
flattenedisFlattened()@xmlFlattenedresultWrapperoutput.getResultWrapper()Result, awsQuery only — D3Exception shapes
typeExceptionerrorCodeshape.getError().getCode()else shape name@awsQueryErrorwhere the protocol allows, else shape name — D4httpStatusCodeerror.httpStatusCode@httpErrorC2J sets
isRetryable/isThrottlinghere; on the Smithy side the base class already sets both from@retryable(AddSmithyShapes:266), so the processor doesn't repeat it. Same forisFaultand the documentation fallback.Testing
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